Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 62 additions & 29 deletions docs/extension_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,53 +48,86 @@ Declares a toolchain repository to generate.

Declares a package repository explicitly. This is used when the package is not
taken from the default version matrix or when local QNX SDP generation is
required.
required. The tag is nothing more than a thin proxy to the native `http_archive`
repository rule: its attributes are passed straight through to `http_archive`
with no additional processing.

## `gcc.toolchain(...)` Attributes

Required attributes:

- `name`: name of the generated repository
- `target_cpu`: target CPU, currently `x86_64` or `aarch64`
- `target_os`: target OS, currently `linux` or `qnx`
- `name` (mandatory): toolchain repo name, default set to `score_gcc_toolchain`.
- `target_cpu` (mandatory): target platform CPU, currently `x86_64` or `aarch64`.
- `target_os` (mandatory): target platform OS, currently `linux` or `qnx`.

Common package selection attributes:

- `use_default_package`: resolve package metadata from `packages/version_matrix.bzl`
- `use_default_package`: whether to use the default package from the version
matrix, default set to `False`.
- `version`: GCC version string for Linux toolchains (e.g. `12.2.0` or `15.3.0` —
see `packages/version_matrix.bzl` for all versions currently packaged)
- `sdp_version`: QNX SDP version string
- `sdk_version`: alternative SDK identifier used in matrix resolution
- `sdp_to_link`: override the package repository name that the toolchain uses
see `packages/version_matrix.bzl` for all versions currently packaged).
- `sdp_version`: version of the SDP package.
- `sdk_version`: SDK version info variable, an alternative identifier used in
matrix resolution.
- `sdp_to_link`: name of the toolchain package to be linked with this
toolchain, default set to toolchain name + `_pkg`.
- `use_system_toolchain`: TBD.

Flag and runtime attributes:

- `extra_compile_flags`
- `extra_c_compile_flags`
- `extra_cxx_compile_flags`
- `extra_link_flags`
- `extra_known_features`
- `extra_enabled_features`
- `ld_library_paths`
- `runtime_ecosystem`
- `use_base_constraints_only`
- `extra_compile_flags`: list of additional flags to be passed to compiler.
- `extra_c_compile_flags`: list of additional flags to be passed to C compiler.
- `extra_cxx_compile_flags`: list of additional flags to be passed to C++
compiler.
- `extra_link_flags`: list of additional flags to be passed to linker.
- `extra_known_features`: extra `cc_feature` features to add to this toolchain
in an initially disabled state. See [Feature Injection](#feature-injection).
- `extra_enabled_features`: extra `cc_feature` features to add to this
toolchain in an initially enabled state. See [Feature Injection](#feature-injection).
- `ld_library_paths`: list of paths relative to the sysroot which should build
up the runtime linker path of the tools of this toolchain.
- `runtime_ecosystem`: attribute for identifying the system-level runtime
environment a binary or target is built to run in.
- `use_base_constraints_only`: experimental. Attribute for flag toolchain
creation to use only base platform constraints. Limits toolchain
registration to 1 per base platform definition.

QNX-specific attributes:

- `license_path`
- `license_info_variable`
- `license_info_url`
- `license_path`: path to the shared license file, default set to
`/opt/score_qnx/license/licenses`.
- `license_info_variable`: QNX license info variable.
- `license_info_url`: URL of the QNX license server.

## `gcc.sdp(...)` Attributes

The `gcc.sdp` tag defines the package side of the toolchain setup. Important
attributes are:

- `name`: repository name for the package
- `build_file`: BUILD file that exposes the package contents as Bazel targets
- `url`: url of the archive,
- `sha256`: sha256 of the archive
- `strip_prefix`: extraction prefix for packaged archives
The `gcc.sdp` tag defines the package side of the toolchain setup. It is a
proxy to `http_archive`: every attribute below maps 1:1 to the identically
named `http_archive` attribute, so refer to the Bazel `http_archive` docs for
full semantics. Its attributes are:

- `name`: package name of toolchain, default set to toolchain name + `_pkg`.
- `build_file`: the path to the BUILD file of selected archive.
- `url`: url to the toolchain archive.
- `sha256`: checksum of the archive.
- `strip_prefix`: strip prefix from toolchain archive.
- `files`: a map of relative paths (key) to a file label (value) that is
overlaid on the repo as a symlink.
- `patches`: list of patches to apply to the archive.
- `patch_args`: the arguments given to the patch tool. Defaults to `-p0` (see
the `patch_strip` attribute), however `-p1` will usually be needed for
patches generated by git. When arguments other than `-p` are specified,
Bazel falls back to the `patch` command line tool instead of the
Bazel-native patch implementation. Only affects patch files in the
`patches` attribute.
- `patch_cmds`: bash commands executed in the extracted archive root after
extraction.
- `patch_strip`: when set to `N`, this is equivalent to inserting `-pN` to the
beginning of `patch_args`.
- `patch_tool`: the patch(1) utility to use. If specified, Bazel uses the
specified patch tool instead of the Bazel-native patch implementation.

Archive attributes can be supplied either directly through `gcc.sdp(...)` or through `packages/version_matrix.bzl`; the extension forwards matrix values for `patches`, `patch_args`, `patch_cmds`, `patch_strip`, `patch_tool`, and `files` to `http_archive` when present. Entries that omit these optional fields use the native `http_archive` defaults.

## Feature Injection

Expand Down
3 changes: 2 additions & 1 deletion docs/generation_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ toolchain repository through these steps:
`packages/version_matrix.bzl`

Defines the supported package matrix. Each entry maps a logical toolchain key
to download metadata and, when needed, extra compiler or linker flags.
to download metadata and, when needed, extra compiler or linker flags and
archive patches.

`rules/common.bzl`

Expand Down
2 changes: 1 addition & 1 deletion docs/repository_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Contains the repository rules that materialize a toolchain repository.

Stores package metadata and BUILD descriptors for supported toolchain
archives. The most important file is `packages/version_matrix.bzl`, which maps
logical toolchain identifiers to URLs, checksums, build files, and any
logical toolchain identifiers to URLs, checksums, build files, patches, and any
required extra flags.

`features/`
Expand Down
47 changes: 47 additions & 0 deletions extensions/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,46 @@ _attrs_sdp = {
default = None,
doc = "The path to the BUILD file of selected archive.",
),
"files": attr.string_keyed_label_dict(
mandatory = False,
default = {},
doc = "A map of relative paths (key) to a file label (value) that overlaid on the repo as a symlink.",
),
"name": attr.string(
default = "",
doc = "package name of toolchain, default set to toolchain toolchain name + `_pkg`.",
),
"patch_args": attr.string_list(
mandatory = False,
default = [],
doc =
"The arguments given to the patch tool. Defaults to -p0 (see the `patch_strip` " +
"attribute), however -p1 will usually be needed for patches generated by " +
"git. If multiple -p arguments are specified, the last one will take effect." +
"If arguments other than -p are specified, Bazel will fall back to use patch " +
"command line tool instead of the Bazel-native patch implementation. When falling " +
"back to patch command line tool and patch_tool attribute is not specified, " +
"`patch` will be used. This only affects patch files in the `patches` attribute.",
),
"patch_cmds": attr.string_list(
mandatory = False,
default = [],
doc = "Bash commands executed in the extracted archive root after extraction.",
),
"patch_strip": attr.int(
default = 0,
doc = "When set to `N`, this is equivalent to inserting `-pN` to the beginning of `patch_args`.",
),
"patch_tool": attr.string(
default = "",
doc = "The patch(1) utility to use. If this is specified, Bazel will use the specified " +
"patch tool instead of the Bazel-native patch implementation.",
),
"patches": attr.label_list(
mandatory = False,
default = [],
doc = "List of patches to apply to the archive.",
),
"sha256": attr.string(
mandatory = False,
default = "",
Expand Down Expand Up @@ -190,10 +221,15 @@ def _get_packages(tags):
packages.append({
"build_file": tag.build_file,
"name": tag.name,
"patch_args": tag.patch_args,
"patch_cmds": tag.patch_cmds,
"patch_strip": tag.patch_strip,
"patch_tool": tag.patch_tool,
"sha256": tag.sha256,
"strip_prefix": tag.strip_prefix,
"url": tag.url,
"patches": tag.patches,
"files": tag.files,
})
return packages

Expand Down Expand Up @@ -306,10 +342,16 @@ def _create_and_link_sdp(toolchain_info):
return {
"build_file": matrix["build_file"],
"name": pkg_name,
# patch_args/patch_strip/patch_tool are not part of the version matrix; fall back to sdp tag defaults.
"patch_args": matrix.get("patch_args", []),
"patch_cmds": matrix.get("patch_cmds", []),
"patch_strip": matrix.get("patch_strip", 0),
"patch_tool": matrix.get("patch_tool", ""),
"sha256": matrix["sha256"],
"strip_prefix": matrix["strip_prefix"],
"url": matrix["url"],
"patches": matrix.get("patches"),
"files": matrix.get("files"),
}

def _resolve_identifier(toolchain_info):
Expand Down Expand Up @@ -395,9 +437,14 @@ def _impl(mctx):
name = archive_info["name"],
urls = [archive_info["url"]],
build_file = archive_info["build_file"],
patch_args = archive_info["patch_args"],
patch_cmds = archive_info["patch_cmds"],
patch_strip = archive_info["patch_strip"],
patch_tool = archive_info["patch_tool"],
sha256 = archive_info["sha256"],
strip_prefix = archive_info["strip_prefix"],
patches = archive_info["patches"],
files = archive_info["files"],
)

for toolchain_info in toolchains:
Expand Down
4 changes: 3 additions & 1 deletion rules/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group")
# Certain SDP versions are mapped to canonical versions used in platform constraints.
# For example, SDP 8.0.4 is mapped to 8.0.0 because platform constraint support
# uses the older identifier.
SDP_VERSION_MAPPING = {"8.0.4": "8.0.0"}
SDP_VERSION_MAPPING = {
"8.0.4": "8.0.0",
}

def get_flag_strings(flags):
"""Converts a list of warning flags into a Bazel flag group representation.
Expand Down
15 changes: 13 additions & 2 deletions tests/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@ gcc.toolchain(
)

# *******************************************************************************
# Setting GCC (CPU:x86_64|OS:QNX|version(sdp):8.0.0|ES:posix)
# Setting GCC (CPU:x86_64|OS:QNX|version(sdp):8.0.4|ES:posix)
# *******************************************************************************
# gcc.toolchain(
# name = "score_qcc_toolchain",
# sdp_version = "8.0.4",
# target_cpu = "x86_64",
# target_os = "qnx",
# use_default_package = True,
# )

# *******************************************************************************
# Setting GCC (CPU:x86_64|OS:QNX|version(sdp):8.0.4|ES:posix)
# *******************************************************************************
gcc.toolchain(
name = "score_qcc_toolchain",
Expand All @@ -159,7 +170,7 @@ gcc.toolchain(
)

# *******************************************************************************
# Setting GCC (CPU:aarch64|OS:QNX|version(sdp):8.0.0|ES:posix)
# Setting GCC (CPU:aarch64|OS:QNX|version(sdp):8.0.4|ES:posix)
# *******************************************************************************
gcc.toolchain(
name = "score_qcc_arm_toolchain",
Expand Down
Loading
Loading