Skip to content

Commit e2b148d

Browse files
committed
Add patches support for SDP toolchain archives
Introduce a patches to the SDP tag class so patches can be applied to downloaded toolchain archives. The attributes are threaded through `_get_packages`, `_create_and_link_sdp`, and the archive download in `_impl`. Documentation is also update to follow up new attribute set.
1 parent c8d4493 commit e2b148d

8 files changed

Lines changed: 211 additions & 50 deletions

File tree

‎docs/extension_api.md‎

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,53 +48,89 @@ Declares a toolchain repository to generate.
4848

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

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

5557
Required attributes:
5658

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`
59+
- `name` (mandatory): toolchain repo name, default set to `score_gcc_toolchain`.
60+
- `target_cpu` (mandatory): target platform CPU, currently `x86_64` or `aarch64`.
61+
- `target_os` (mandatory): target platform OS, currently `linux` or `qnx`.
6062

6163
Common package selection attributes:
6264

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

7076
Flag and runtime attributes:
7177

72-
- `extra_compile_flags`
73-
- `extra_c_compile_flags`
74-
- `extra_cxx_compile_flags`
75-
- `extra_link_flags`
76-
- `extra_known_features`
77-
- `extra_enabled_features`
78-
- `ld_library_paths`
79-
- `runtime_ecosystem`
80-
- `use_base_constraints_only`
78+
- `extra_compile_flags`: list of additional flags to be passed to compiler.
79+
- `extra_c_compile_flags`: list of additional flags to be passed to C compiler.
80+
- `extra_cxx_compile_flags`: list of additional flags to be passed to C++
81+
compiler.
82+
- `extra_link_flags`: list of additional flags to be passed to linker.
83+
- `extra_known_features`: extra `cc_feature` features to add to this toolchain
84+
in an initially disabled state. See [Feature Injection](#feature-injection).
85+
- `extra_enabled_features`: extra `cc_feature` features to add to this
86+
toolchain in an initially enabled state. See [Feature Injection](#feature-injection).
87+
- `ld_library_paths`: list of paths relative to the sysroot which should build
88+
up the runtime linker path of the tools of this toolchain.
89+
- `runtime_ecosystem`: attribute for identifying the system-level runtime
90+
environment a binary or target is built to run in.
91+
- `use_base_constraints_only`: experimental. Attribute for flag toolchain
92+
creation to use only base platform constraints. Limits toolchain
93+
registration to 1 per base platform definition.
8194

8295
QNX-specific attributes:
8396

84-
- `license_path`
85-
- `license_info_variable`
86-
- `license_info_url`
97+
- `license_path`: path to the shared license file, default set to
98+
`/opt/score_qnx/license/licenses`.
99+
- `license_info_variable`: QNX license info variable.
100+
- `license_info_url`: URL of the QNX license server.
87101

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

90-
The `gcc.sdp` tag defines the package side of the toolchain setup. Important
91-
attributes are:
92-
93-
- `name`: repository name for the package
94-
- `build_file`: BUILD file that exposes the package contents as Bazel targets
95-
- `url`: url of the archive,
96-
- `sha256`: sha256 of the archive
97-
- `strip_prefix`: extraction prefix for packaged archives
104+
The `gcc.sdp` tag defines the package side of the toolchain setup. It is a
105+
proxy to `http_archive`: every attribute below maps 1:1 to the identically
106+
named `http_archive` attribute, so refer to the Bazel `http_archive` docs for
107+
full semantics. Its attributes are:
108+
109+
- `name`: package name of toolchain, default set to toolchain name + `_pkg`.
110+
- `build_file`: the path to the BUILD file of selected archive.
111+
- `url`: url to the toolchain archive.
112+
- `sha256`: checksum of the archive.
113+
- `strip_prefix`: strip prefix from toolchain archive.
114+
- `files`: a map of relative paths (key) to a file label (value) that is
115+
overlaid on the repo as a symlink.
116+
- `patches`: list of patches to apply to the archive.
117+
- `patch_args`: the arguments given to the patch tool. Defaults to `-p0` (see
118+
the `patch_strip` attribute), however `-p1` will usually be needed for
119+
patches generated by git. When arguments other than `-p` are specified,
120+
Bazel falls back to the `patch` command line tool instead of the
121+
Bazel-native patch implementation. Only affects patch files in the
122+
`patches` attribute.
123+
- `patch_cmds`: bash commands executed in the extracted archive root after
124+
extraction.
125+
- `patch_strip`: when set to `N`, this is equivalent to inserting `-pN` to the
126+
beginning of `patch_args`.
127+
- `patch_tool`: the patch(1) utility to use. If specified, Bazel uses the
128+
specified patch tool instead of the Bazel-native patch implementation.
129+
130+
These `patch_*`/`files` attributes are only wired for archives declared
131+
directly with `gcc.sdp(...)`. Default packages resolved from
132+
`packages/version_matrix.bzl` fall back to their attribute defaults (empty
133+
list/string, `0`) since the version matrix does not carry these fields.
98134

99135
## Feature Injection
100136

‎docs/generation_flow.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ toolchain repository through these steps:
4040
`packages/version_matrix.bzl`
4141

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

4546
`rules/common.bzl`
4647

‎docs/repository_layout.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Contains the repository rules that materialize a toolchain repository.
4848

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

5454
`features/`

‎extensions/gcc.bzl‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,46 @@ _attrs_sdp = {
3535
default = None,
3636
doc = "The path to the BUILD file of selected archive.",
3737
),
38+
"files": attr.string_keyed_label_dict(
39+
mandatory = False,
40+
default = {},
41+
doc = "A map of relative paths (key) to a file label (value) that overlaid on the repo as a symlink.",
42+
),
3843
"name": attr.string(
3944
default = "",
4045
doc = "package name of toolchain, default set to toolchain toolchain name + `_pkg`.",
4146
),
47+
"patch_args": attr.string_list(
48+
mandatory = False,
49+
default = [],
50+
doc =
51+
"The arguments given to the patch tool. Defaults to -p0 (see the `patch_strip` " +
52+
"attribute), however -p1 will usually be needed for patches generated by " +
53+
"git. If multiple -p arguments are specified, the last one will take effect." +
54+
"If arguments other than -p are specified, Bazel will fall back to use patch " +
55+
"command line tool instead of the Bazel-native patch implementation. When falling " +
56+
"back to patch command line tool and patch_tool attribute is not specified, " +
57+
"`patch` will be used. This only affects patch files in the `patches` attribute.",
58+
),
4259
"patch_cmds": attr.string_list(
4360
mandatory = False,
4461
default = [],
4562
doc = "Bash commands executed in the extracted archive root after extraction.",
4663
),
64+
"patch_strip": attr.int(
65+
default = 0,
66+
doc = "When set to `N`, this is equivalent to inserting `-pN` to the beginning of `patch_args`.",
67+
),
68+
"patch_tool": attr.string(
69+
default = "",
70+
doc = "The patch(1) utility to use. If this is specified, Bazel will use the specified " +
71+
"patch tool instead of the Bazel-native patch implementation.",
72+
),
73+
"patches": attr.label_list(
74+
mandatory = False,
75+
default = [],
76+
doc = "List of patches to apply to the archive.",
77+
),
4778
"sha256": attr.string(
4879
mandatory = False,
4980
default = "",
@@ -190,10 +221,15 @@ def _get_packages(tags):
190221
packages.append({
191222
"build_file": tag.build_file,
192223
"name": tag.name,
224+
"patch_args": tag.patch_args,
193225
"patch_cmds": tag.patch_cmds,
226+
"patch_strip": tag.patch_strip,
227+
"patch_tool": tag.patch_tool,
194228
"sha256": tag.sha256,
195229
"strip_prefix": tag.strip_prefix,
196230
"url": tag.url,
231+
"patches": tag.patches,
232+
"files": tag.files,
197233
})
198234
return packages
199235

@@ -306,10 +342,16 @@ def _create_and_link_sdp(toolchain_info):
306342
return {
307343
"build_file": matrix["build_file"],
308344
"name": pkg_name,
345+
# patch_args/patch_strip/patch_tool are not part of the version matrix; fall back to sdp tag defaults.
346+
"patch_args": matrix.get("patch_args", []),
309347
"patch_cmds": matrix.get("patch_cmds", []),
348+
"patch_strip": matrix.get("patch_strip", 0),
349+
"patch_tool": matrix.get("patch_tool", ""),
310350
"sha256": matrix["sha256"],
311351
"strip_prefix": matrix["strip_prefix"],
312352
"url": matrix["url"],
353+
"patches": matrix.get("patches"),
354+
"files": matrix.get("files"),
313355
}
314356

315357
def _resolve_identifier(toolchain_info):
@@ -395,9 +437,14 @@ def _impl(mctx):
395437
name = archive_info["name"],
396438
urls = [archive_info["url"]],
397439
build_file = archive_info["build_file"],
440+
patch_args = archive_info["patch_args"],
398441
patch_cmds = archive_info["patch_cmds"],
442+
patch_strip = archive_info["patch_strip"],
443+
patch_tool = archive_info["patch_tool"],
399444
sha256 = archive_info["sha256"],
400445
strip_prefix = archive_info["strip_prefix"],
446+
patches = archive_info["patches"],
447+
files = archive_info["files"],
401448
)
402449

403450
for toolchain_info in toolchains:

‎packages/version_matrix.bzl‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ VERSION_MATRIX = {
2020
"sha256": "7279b1adb50361b21f5266b001980b6febb35fa8d83170901196b9edae3f06d9",
2121
"strip_prefix": "aarch64-unknown-linux-gnu",
2222
"url": "https://github.com/eclipse-score/toolchains_gcc_packages/releases/download/v0.0.4/aarch64-unknown-linux-gnu_gcc12.tar.gz",
23+
"patches": [],
2324
},
2425
"aarch64-linux-gcc_15.3.0": {
2526
"build_file": "@score_bazel_cpp_toolchains//packages/linux/aarch64/gcc/15.3.0:gcc.BUILD",
@@ -71,26 +72,31 @@ VERSION_MATRIX = {
7172
"sha256": "e2f6a21681730e61ce39af19758003ba3568b093956a57cde136d5c73cf6540a",
7273
"strip_prefix": "sysroot",
7374
"url": "https://github.com/eclipse-score/os_autosd/releases/download/v0.0.2/autosd-toolchain-aarch64.tar.gz",
75+
"patches": [],
7476
},
7577
"aarch64-qnx-sdp_8.0.0": {
7678
"build_file": "@score_bazel_cpp_toolchains//packages/qnx/aarch64/sdp/8.0.0:sdp.BUILD",
7779
"sha256": "f2e0cb21c6baddbcb65f6a70610ce498e7685de8ea2e0f1648f01b327f6bac63",
7880
"strip_prefix": "installation",
7981
"url": "https://www.qnx.com/download/download/79858/installation.tgz",
8082
"gcc_version": "12.2.0",
83+
"patches": [],
8184
},
8285
"aarch64-qnx-sdp_8.0.4": {
8386
"build_file": "@score_bazel_cpp_toolchains//packages/qnx/aarch64/sdp/8.0.0:sdp.BUILD",
8487
"sha256": "146312c0bf22aab66e8294a06403f2ec6cfeeb074d8fa11549faffd84b7fe778",
8588
"strip_prefix": "",
8689
"url": "https://www.qnx.com/download/download/88447/installation_qnx_804_260520.tar.xz",
8790
"gcc_version": "12.2.0",
91+
"files": {
92+
},
8893
},
8994
"x86_64-linux-gcc_12.2.0": {
9095
"build_file": "@score_bazel_cpp_toolchains//packages/linux/x86_64/gcc/12.2.0:gcc.BUILD",
9196
"sha256": "e9b9a7a63a5f8271b76d6e2057906b95c7a244e4931a8e10edeaa241e9f7c11e",
9297
"strip_prefix": "x86_64-unknown-linux-gnu",
9398
"url": "https://github.com/eclipse-score/toolchains_gcc_packages/releases/download/v0.0.4/x86_64-unknown-linux-gnu_gcc12.tar.gz",
99+
"patches": [],
94100
},
95101
"x86_64-linux-gcc_15.3.0": {
96102
"build_file": "@score_bazel_cpp_toolchains//packages/linux/x86_64/gcc/15.3.0:gcc.BUILD",
@@ -142,6 +148,7 @@ VERSION_MATRIX = {
142148
"sha256": "25991056bd29d4cb37b11e42d0c09f55dc61d0b9d703f75d854cf614f688c96f",
143149
"strip_prefix": "sysroot",
144150
"url": "https://github.com/eclipse-score/os_autosd/releases/download/v0.0.2/autosd-toolchain-x86_64.tar.gz",
151+
"patches": [],
145152
},
146153
"aarch64-linux-sdk_0.1.0-ebclfsa": {
147154
"build_file": "@score_bazel_cpp_toolchains//packages/linux/aarch64/ebclfsa/0.1.0:ebclfsa.BUILD",
@@ -204,6 +211,7 @@ VERSION_MATRIX = {
204211
"strip_prefix": "fastdev-sdk-ubuntu-ebclfsa-ebcl-qemuarm64",
205212
"sha256": "f44286c28d831dc40acdac08ef49f38a2e9cbb057bea38c25834964693785287",
206213
"url": "https://github.com/Elektrobit/eb_corbos_toolkit/releases/download/v2.0.0-beta1/fastdev-sdk-ubuntu-ebclfsa-ebcl-qemuarm64.tar.gz",
214+
"patches": [],
207215
},
208216
"aarch64-linux-sdk_2.0.0-beta2-ebclfsa": {
209217
"build_file": "@score_bazel_cpp_toolchains//packages/linux/aarch64/ebclfsa/2.0.0-beta2:ebclfsa.BUILD",
@@ -303,7 +311,7 @@ VERSION_MATRIX = {
303311
"url": "https://www.qnx.com/download/download/79858/installation.tgz",
304312
"gcc_version": "12.2.0",
305313
},
306-
"x86_64-qnx-sdp_8.0.4": {
314+
"x86_64-qnx-sdp_8.0.5": {
307315
"build_file": "@score_bazel_cpp_toolchains//packages/qnx/x86_64/sdp/8.0.0:sdp.BUILD",
308316
"sha256": "146312c0bf22aab66e8294a06403f2ec6cfeeb074d8fa11549faffd84b7fe778",
309317
"strip_prefix": "",

‎rules/common.bzl‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group")
2020
# Certain SDP versions are mapped to canonical versions used in platform constraints.
2121
# For example, SDP 8.0.4 is mapped to 8.0.0 because platform constraint support
2222
# uses the older identifier.
23-
SDP_VERSION_MAPPING = {"8.0.4": "8.0.0"}
23+
SDP_VERSION_MAPPING = {
24+
"8.0.4": "8.0.0",
25+
"8.0.5": "8.0.0",
26+
}
2427

2528
def get_flag_strings(flags):
2629
"""Converts a list of warning flags into a Bazel flag group representation.

‎tests/MODULE.bazel‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,29 @@ gcc.toolchain(
148148
)
149149

150150
# *******************************************************************************
151-
# Setting GCC (CPU:x86_64|OS:QNX|version(sdp):8.0.0|ES:posix)
151+
# Setting GCC (CPU:x86_64|OS:QNX|version(sdp):8.0.4|ES:posix)
152+
# *******************************************************************************
153+
# gcc.toolchain(
154+
# name = "score_qcc_toolchain",
155+
# sdp_version = "8.0.4",
156+
# target_cpu = "x86_64",
157+
# target_os = "qnx",
158+
# use_default_package = True,
159+
# )
160+
161+
# *******************************************************************************
162+
# Setting GCC (CPU:x86_64|OS:QNX|version(sdp):8.0.5|ES:posix)
152163
# *******************************************************************************
153164
gcc.toolchain(
154165
name = "score_qcc_toolchain",
155-
sdp_version = "8.0.4",
166+
sdp_version = "8.0.5",
156167
target_cpu = "x86_64",
157168
target_os = "qnx",
158169
use_default_package = True,
159170
)
160171

161172
# *******************************************************************************
162-
# Setting GCC (CPU:aarch64|OS:QNX|version(sdp):8.0.0|ES:posix)
173+
# Setting GCC (CPU:aarch64|OS:QNX|version(sdp):8.0.4|ES:posix)
163174
# *******************************************************************************
164175
gcc.toolchain(
165176
name = "score_qcc_arm_toolchain",

0 commit comments

Comments
 (0)