Skip to content

feat: honor rustflags from cargo's --config CLI option for zig -mcpu - #471

Merged
messense merged 1 commit into
mainfrom
cli-config-rustflags
Aug 27, 2026
Merged

feat: honor rustflags from cargo's --config CLI option for zig -mcpu#471
messense merged 1 commit into
mainfrom
cli-config-rustflags

Conversation

@messense

Copy link
Copy Markdown
Member

Rustflags passed via cargo's --config option (KEY=VALUE in TOML syntax or a path to an extra config file) were forwarded to the child cargo process but not reflected in the -mcpu passed to zig cc, silently reverting to baseline CPU for C/C++ dependencies and linking.

Parse the --config arguments and overlay them onto the cargo_config2-resolved rustflags following cargo's precedence rules: RUSTFLAGS/CARGO_ENCODED_RUSTFLAGS env vars shortcut everything, CLI config beats config env vars and files within a tier, target tier beats build tier, and arrays join left-to-right with CLI items last.

This makes it possible to scope a target-cpu to a cargo alias without wrapper scripts or RUSTFLAGS:

[alias]
build-prod = "zigbuild --release --target x86_64-unknown-linux-gnu --config target.x86_64-unknown-linux-gnu.rustflags=['-C','target-cpu=x86-64-v4']"

Most of this can be simplified once cargo-config2 supports --config overrides natively (taiki-e/cargo-config2#3).

Closes #463

Rustflags passed via cargo's `--config` option (KEY=VALUE in TOML syntax
or a path to an extra config file) were forwarded to the child cargo
process but not reflected in the -mcpu passed to zig cc, silently
reverting to baseline CPU for C/C++ dependencies and linking.

Parse the --config arguments and overlay them onto the
cargo_config2-resolved rustflags following cargo's precedence rules:
RUSTFLAGS/CARGO_ENCODED_RUSTFLAGS env vars shortcut everything, CLI
config beats config env vars and files within a tier, target tier beats
build tier, and arrays join left-to-right with CLI items last.

This makes it possible to scope a target-cpu to a cargo alias without
wrapper scripts or RUSTFLAGS:

    [alias]
    build-prod = "zigbuild --release --target x86_64-unknown-linux-gnu --config target.x86_64-unknown-linux-gnu.rustflags=['-C','target-cpu=x86-64-v4']"

Most of this can be simplified once cargo-config2 supports --config
overrides natively (taiki-e/cargo-config2#3).

Closes #463
@messense
messense merged commit aae42c6 into main Aug 27, 2026
49 checks passed
@messense
messense deleted the cli-config-rustflags branch August 27, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

explicit --target-cpu flag

1 participant