|
| 1 | +<!-- |
| 2 | +# ******************************************************************************* |
| 3 | +# Copyright (c) 2026 Contributors to the Eclipse Foundation |
| 4 | +# |
| 5 | +# See the NOTICE file(s) distributed with this work for additional |
| 6 | +# information regarding copyright ownership. |
| 7 | +# |
| 8 | +# This program and the accompanying materials are made available under the |
| 9 | +# terms of the Apache License Version 2.0 which is available at |
| 10 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# SPDX-License-Identifier: Apache-2.0 |
| 13 | +# ******************************************************************************* |
| 14 | +--> |
| 15 | + |
| 16 | +# Extension API |
| 17 | + |
| 18 | +## Consumer Entry Point |
| 19 | + |
| 20 | +Consumers interact with this repository through the `gcc` module extension in |
| 21 | +`@score_bazel_cpp_toolchains//extensions:gcc.bzl`. |
| 22 | + |
| 23 | +Typical usage looks like this: |
| 24 | + |
| 25 | +```starlark |
| 26 | +bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.4.0") |
| 27 | + |
| 28 | +gcc = use_extension("@score_bazel_cpp_toolchains//extensions:gcc.bzl", "gcc") |
| 29 | + |
| 30 | +gcc.toolchain( |
| 31 | + name = "score_gcc_toolchain", |
| 32 | + target_cpu = "x86_64", |
| 33 | + target_os = "linux", |
| 34 | + version = "12.2.0", |
| 35 | + use_default_package = True, |
| 36 | +) |
| 37 | + |
| 38 | +use_repo(gcc, "score_gcc_toolchain") |
| 39 | +``` |
| 40 | + |
| 41 | +## Public Tags |
| 42 | + |
| 43 | +`gcc.toolchain(...)` |
| 44 | + |
| 45 | +Declares a toolchain repository to generate. |
| 46 | + |
| 47 | +`gcc.sdp(...)` |
| 48 | + |
| 49 | +Declares a package repository explicitly. This is used when the package is not |
| 50 | +taken from the default version matrix or when local QNX SDP generation is |
| 51 | +required. |
| 52 | + |
| 53 | +## `gcc.toolchain(...)` Attributes |
| 54 | + |
| 55 | +Required attributes: |
| 56 | + |
| 57 | +- `name`: name of the generated repository |
| 58 | +- `target_cpu`: target CPU, currently `x86_64` or `aarch64` |
| 59 | +- `target_os`: target OS, currently `linux` or `qnx` |
| 60 | + |
| 61 | +Common package selection attributes: |
| 62 | + |
| 63 | +- `use_default_package`: resolve package metadata from `packages/version_matrix.bzl` |
| 64 | +- `version`: GCC version string for Linux toolchains |
| 65 | +- `sdp_version`: QNX SDP version string |
| 66 | +- `sdk_version`: alternative SDK identifier used in matrix resolution |
| 67 | +- `sdp_to_link`: override the package repository name that the toolchain uses |
| 68 | + |
| 69 | +Flag and runtime attributes: |
| 70 | + |
| 71 | +- `extra_compile_flags` |
| 72 | +- `extra_c_compile_flags` |
| 73 | +- `extra_cxx_compile_flags` |
| 74 | +- `extra_link_flags` |
| 75 | +- `ld_library_paths` |
| 76 | +- `runtime_ecosystem` |
| 77 | +- `use_base_constraints_only` |
| 78 | + |
| 79 | +QNX-specific attributes: |
| 80 | + |
| 81 | +- `license_path` |
| 82 | +- `license_info_variable` |
| 83 | +- `license_info_url` |
| 84 | + |
| 85 | +## `gcc.sdp(...)` Attributes |
| 86 | + |
| 87 | +The `gcc.sdp` tag defines the package side of the toolchain setup. Important |
| 88 | +attributes are: |
| 89 | + |
| 90 | +- `name`: repository name for the package |
| 91 | +- `build_file`: BUILD file that exposes the package contents as Bazel targets |
| 92 | +- `url` and `sha256`: archive or installer source |
| 93 | +- `strip_prefix`: extraction prefix for packaged archives |
| 94 | +- `mode`: `archive` or `build` |
| 95 | +- `patchset`: QNX SDP patchset definition used in build mode |
| 96 | +- `target_cpu`: target CPU used when building an SDP locally |
| 97 | + |
| 98 | +## Activation In A Workspace |
| 99 | + |
| 100 | +Declaring a toolchain repository is not enough on its own. Consumers still need |
| 101 | +to activate the generated toolchain during Bazel analysis, typically with a |
| 102 | +configuration such as: |
| 103 | + |
| 104 | +```text |
| 105 | +--extra_toolchains=@score_gcc_toolchain//:x86_64-linux-gcc_12.2.0 |
| 106 | +``` |
| 107 | + |
| 108 | +The example workspace under `examples/` provides complete `.bazelrc` |
| 109 | +configurations for this activation step. |
| 110 | + |
| 111 | +## Behavior Notes |
| 112 | + |
| 113 | +- The extension is intended for the root module. |
| 114 | +- When `use_default_package` is enabled, the version matrix can inject extra |
| 115 | + include and link flags required by non-standard sysroot layouts. |
| 116 | +- QNX toolchains use additional licensing and include-path parameters that do |
| 117 | + not apply to Linux toolchains. |
0 commit comments