Skip to content

Commit acc892c

Browse files
committed
fix(linux): pass sysroot flags to assembly actions
Keep linker-specific -Wl,--sysroot flags limited to link actions while applying the compiler sysroot to assembly actions. resolves #141
1 parent 3ae838b commit acc892c

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎docs/features.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ enabled by default.
7070
- **`output_execpath_flags`** (both) — `-o` for the link output.
7171
- **`libraries_to_link`** (both) — Handles whole-archive, static, object-file,
7272
dynamic, and versioned-dynamic library linking.
73-
- **`sysroot_link_flags`** (Linux) — Adds `--sysroot` / `-Wl,--sysroot` at link.
73+
- **`sysroot_link_flags`** (Linux) — Adds `--sysroot` / `-Wl,--sysroot` at link,
74+
and `--sysroot` for assemble/preprocess-assemble actions (preprocessed `.S`
75+
sources need it to resolve sysroot headers).
7476

7577
### Opt-in link features (Linux)
7678
These mirror Bazel's legacy features and are guarded, so they are no-ops until

‎docs/maintenance.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ feature, though; some behavior is provided by other toolchain wiring:
5353
- **`gcov`** is provided via `tool_paths` (`gcov_wrapper`).
5454
- **Sysroot (Linux)** — the sysroot path is passed as `builtin_sysroot` to
5555
`create_cc_toolchain_config_info`; compile-time header resolution relies on
56-
`cxx_builtin_include_directories`, so no `--sysroot` is needed at compile.
57-
Link-time `--sysroot` / `-Wl,--sysroot` is emitted by the custom
58-
`sysroot_link_flags` feature. There is intentionally no legacy `sysroot`
59-
compile feature.
56+
`cxx_builtin_include_directories`, so no `--sysroot` is needed for c/cxx
57+
compiles. Link-time `--sysroot` / `-Wl,--sysroot` and assembly-time
58+
`--sysroot` (assemble / preprocess-assemble; needed for `.S` sources since
59+
the extra_*_compile_flags include paths do not apply there) are emitted by
60+
the custom `sysroot_link_flags` feature. There is intentionally no legacy
61+
`sysroot` compile feature.
6062
- **Sysroot / system includes (QNX)** — QNX does not use `builtin_sysroot`;
6163
system include roots come from `cxx_builtin_include_directories` (SDP paths),
6264
and the SDP environment is injected by the `sdp_env` feature.

‎features/native/sysroot_link_flags/features.bzl‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")
2+
load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot")
3+
14
# *******************************************************************************
25
# Copyright (c) 2026 Contributors to the Eclipse Foundation
36
#
@@ -11,9 +14,6 @@
1114
# SPDX-License-Identifier: Apache-2.0
1215
# *******************************************************************************
1316

14-
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")
15-
load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot")
16-
1717
def make_sysroot_link_flags(target_os, sysroot):
1818
"""Creates the sysroot_link_flags feature for this toolchain's sysroot directory.
1919
@@ -31,8 +31,17 @@ def make_sysroot_link_flags(target_os, sysroot):
3131
sysroot = sysroot,
3232
)
3333

34+
cc_sysroot(
35+
name = "sysroot_assembly_flags_args",
36+
actions = ["@rules_cc//cc/toolchains/actions:assembly_actions"],
37+
sysroot = sysroot,
38+
)
39+
3440
cc_feature(
3541
name = "sysroot_link_flags",
36-
args = [":sysroot_link_flags_args"],
42+
args = [
43+
":sysroot_link_flags_args",
44+
":sysroot_assembly_flags_args",
45+
],
3746
feature_name = "sysroot_link_flags",
3847
)

0 commit comments

Comments
 (0)