Split concatenated compiler flags into separate flag+path arguments#220
Open
JSGette wants to merge 2 commits into
Open
Split concatenated compiler flags into separate flag+path arguments#220JSGette wants to merge 2 commits into
JSGette wants to merge 2 commits into
Conversation
Currently, flags like -isystem, -I, -B, and -L are emitted as single
concatenated strings (e.g. "-isystem/path/to/include", "-B/path/to/bin").
While GCC accepts both forms, this concatenated style is incompatible with
tools that post-process compiler flags by pattern-matching individual
arguments.
Specifically, rules_rust's cargo_build_script has logic (_pwd_flags) to
rewrite execroot-relative paths so that Cargo build scripts (which run
from a different working directory) can locate headers and libraries.
This logic only recognizes the space-separated form ("-isystem", "/path")
and silently skips the concatenated form ("-isystem/path"), causing
build failures when Rust crates with C dependencies (e.g. zstd-sys,
aws-lc-sys via cc-rs) cannot find standard headers like limits.h.
Split all flag+path pairs into two separate list elements. This is a
no-op for GCC (both forms are equivalent) but enables correct path
rewriting by downstream tooling.
f0rmiga
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Flags like
-isystem,-I,-B, and-Lare currently emitted as single concatenated strings indefs.bzl:While GCC accepts both
-isystemPATHand-isystem PATH, the concatenated form is incompatible with downstream tools that post-process compiler flags by matching individual arguments.Specifically,
rules_rust'scargo_build_scripthas path-rewriting logic (_pwd_flags) that prefixes execroot-relative paths with${pwd}/so that Cargo build scripts — which run from a different working directory — can resolve them. This logic only recognizes the space-separated form (-isystem,path) and silently skips the concatenated form (-isystempath).Symptom
When building Rust crates that compile C code via
cc-rs(e.g.zstd-sys,aws-lc-sys), the build script's GCC invocation fails with:because
-isystemexternal/gcc_toolchain_.../includeis passed as-is, and the build script's CWD is not the Bazel execroot, so the relative path doesn't resolve.Reproduction
gcc_toolchainto provide a GCC toolchain.-syscrate usingcc-rsto compile C code (e.g.zstd-sysviaasync-compression, oraws-lc-sysviarustls).rules_rust— thecargo_build_scriptaction for the-syscrate will fail because the compiler cannot find standard headers.The root cause is that
rules_rust's_pwd_flags_isystemand_pwd_flags_bindirfunctions iterate over flag arguments looking for standalone-isystemor-Bentries and then prefix the next argument with${pwd}/. When the flag and path are concatenated into a single argument, these functions never match.Fix
Split all flag+path pairs into two separate list elements:
This is a no-op for GCC (both forms are semantically identical) but enables correct path rewriting by
rules_rustand any other tool that inspects flags as discrete arguments.The same change is applied consistently to
extra_cflags,extra_cxxflags,extra_fflags,extra_ldflags, andextra_asmflags.