From 88f5cfa2de14d9eecfabc96ecd03b27e07ac2b41 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Tue, 15 Sep 2026 14:20:51 +0100 Subject: [PATCH] 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 --- docs/features.md | 4 +++- docs/maintenance.md | 10 ++++++---- docs/migration_guide.md | 2 +- features/native/sysroot_link_flags/features.bzl | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/features.md b/docs/features.md index bb20348..a7e645f 100644 --- a/docs/features.md +++ b/docs/features.md @@ -70,7 +70,9 @@ enabled by default. - **`output_execpath_flags`** (both) — `-o` for the link output. - **`libraries_to_link`** (both) — Handles whole-archive, static, object-file, dynamic, and versioned-dynamic library linking. -- **`sysroot_link_flags`** (Linux) — Adds `--sysroot` / `-Wl,--sysroot` at link. +- **`sysroot_link_flags`** (Linux) — Adds `--sysroot` / `-Wl,--sysroot` at link, + and `--sysroot` for assemble/preprocess-assemble actions (preprocessed `.S` + sources need it to resolve sysroot headers). ### Opt-in link features (Linux) These mirror Bazel's legacy features and are guarded, so they are no-ops until diff --git a/docs/maintenance.md b/docs/maintenance.md index dcff9d7..89e70c1 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -53,10 +53,12 @@ feature, though; some behavior is provided by other toolchain wiring: - **`gcov`** is provided via `tool_paths` (`gcov_wrapper`). - **Sysroot (Linux)** — the sysroot path is passed as `builtin_sysroot` to `create_cc_toolchain_config_info`; compile-time header resolution relies on - `cxx_builtin_include_directories`, so no `--sysroot` is needed at compile. - Link-time `--sysroot` / `-Wl,--sysroot` is emitted by the custom - `sysroot_link_flags` feature. There is intentionally no legacy `sysroot` - compile feature. + `cxx_builtin_include_directories`, so no `--sysroot` is needed for c/cxx + compiles. Link-time `--sysroot` / `-Wl,--sysroot` and assembly-time + `--sysroot` (assemble / preprocess-assemble; needed for `.S` sources since + the extra_*_compile_flags include paths do not apply there) are emitted by + the custom `sysroot_link_flags` feature. There is intentionally no legacy + `sysroot` compile feature. - **Sysroot / system includes (QNX)** — QNX does not use `builtin_sysroot`; system include roots come from `cxx_builtin_include_directories` (SDP paths), and the SDP environment is injected by the `sdp_env` feature. diff --git a/docs/migration_guide.md b/docs/migration_guide.md index b5c5a22..5d19a55 100644 --- a/docs/migration_guide.md +++ b/docs/migration_guide.md @@ -89,7 +89,7 @@ toolchain, are summarized below. | Default / hardening link flags | **Supported, explicit** | `default_link_flags` feature | | `-L` library search paths, `-Wl,-rpath` | **Supported, explicit** | `library_search_directories`, `runtime_library_search_directories` | | Static archive creation (`ar`) | **Supported, explicit** | `archiver_flags` feature + `cpp_link_static_library` action | -| `--sysroot` handling | **Supported, explicit (Linux)** | `sysroot_link_flags` at link; compile relies on `cxx_builtin_include_directories` | +| `--sysroot` handling | **Supported, explicit (Linux)** | `sysroot_link_flags` at link and assemble/preprocess-assemble; C/C++ compile-time header resolution relies on `cxx_builtin_include_directories` | | Compiler / archiver / strip tool binding | **Supported, wiring** | `action_config` entries, not legacy `tool_paths` | | `gcov` | **Supported, wiring** | `tool_paths` (`gcov_wrapper`) | | Warnings (e.g. `-Wall`) added by default | **Not part of this toolchain — injected** | `minimal_warnings` / `strict_warnings` / `all_wall_warnings` are defined by `score_cpp_policies`, not this toolchain, and only become available once brought in via `extra_known_features` / `extra_enabled_features`. | diff --git a/features/native/sysroot_link_flags/features.bzl b/features/native/sysroot_link_flags/features.bzl index 90fa0cf..a3bebe2 100644 --- a/features/native/sysroot_link_flags/features.bzl +++ b/features/native/sysroot_link_flags/features.bzl @@ -11,6 +11,9 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* +"""Feature definition for sysroot link flags. +""" + load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot") @@ -21,6 +24,7 @@ def make_sysroot_link_flags(target_os, sysroot): "-Wl,--sysroot={sysroot}" needs to be listed here. Args: + target_os: the target operating system for this toolchain (e.g., "linux"). sysroot: label of the directory rule for this toolchain's sysroot. """ if target_os == "linux": @@ -31,8 +35,17 @@ def make_sysroot_link_flags(target_os, sysroot): sysroot = sysroot, ) + cc_sysroot( + name = "sysroot_assembly_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:assembly_actions"], + sysroot = sysroot, + ) + cc_feature( name = "sysroot_link_flags", - args = [":sysroot_link_flags_args"], + args = [ + ":sysroot_link_flags_args", + ":sysroot_assembly_flags_args", + ], feature_name = "sysroot_link_flags", )