fix(ar): suppress warnings from D modifier probe#1700
Merged
NobodyXu merged 3 commits intorust-lang:mainfrom Apr 7, 2026
Merged
fix(ar): suppress warnings from D modifier probe#1700NobodyXu merged 3 commits intorust-lang:mainfrom
D modifier probe#1700NobodyXu merged 3 commits intorust-lang:mainfrom
Conversation
Member
Author
|
cc @jieyouxu Let me know if there is a better way to handle this, or you want a test (though that would be trick to write) |
NobodyXu
requested changes
Apr 6, 2026
Contributor
NobodyXu
left a comment
There was a problem hiding this comment.
Thanks, just some feedback onn print warning
NobodyXu
requested changes
Apr 7, 2026
Contributor
NobodyXu
left a comment
There was a problem hiding this comment.
Identified a bug in line splitting, missing \r\n handling
Regarding testing, you can write a rust binary under bin/ and use it during testing
This commit * extends cc-shim with `CC_SHIM_FAIL_IF_ARG` to simulate ar rejecting unknown args. * add tests verifying the probe fallback logic and that the failed probe's noisyt stderr Tests show the current behavior as minimal reproducible examples.
On macOS, the system `ar` doesn't support the `D` modifier.
It causes `illegal option -- D` to be emitted as `cargo:warning=`
during the probe.
Add a `run_silent_on_error()` helper that buffers stderr
and only forwards it when the command succeeds.
Repro script:
```bash
#!/usr/bin/env bash
# Reproduce the "illegal option -- D" cargo:warning= issue on macOS.
# Requires macOS system ar (which does not support the D modifier).
set -euo pipefail
DIR=$(mktemp -d)
trap 'rm -rf "$DIR"' EXIT
mkdir -p "$DIR/src"
cat > "$DIR/Cargo.toml" <<'TOML'
[package]
name = "cc-repro"
version = "0.0.0"
edition = "2021"
[build-dependencies]
#cc = { path = "/path/local/cc-rs" }
cc = "=1.2.59"
TOML
echo 'fn main() {}' > "$DIR/src/main.rs"
echo 'void foo(void) {}' > "$DIR/foo.c"
echo 'fn main() { cc::Build::new().file("foo.c").compile("foo"); }' > "$DIR/build.rs"
echo "==> Building in $DIR ..."
cd "$DIR"
OUTPUT=$(cargo build 2>&1)
if echo "$OUTPUT" | grep -qi "illegal option"; then
echo "BUG: found spurious 'illegal option' warning:"
echo "$OUTPUT" | grep -i "illegal option"
exit 1
else
echo "OK: no spurious warnings."
fi
```
Strip trailing `\r` after splitting on `\n`. This kinda matches how `str::lines()` handles line endings in std. ref: https://github.com/rust-lang/rust/blob/bcded331651b60/library/core/src/str/mod.rs#L1309-L1311
NobodyXu
approved these changes
Apr 7, 2026
Contributor
NobodyXu
left a comment
There was a problem hiding this comment.
Thank you, LGTM!
Release scheduled on this Friday
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.
On macOS, the system
ardoesn't support theDmodifier. It causesillegal option -- Dto be emitted ascargo:warning=during the probe.Add a
run_silent_on_error()helper that buffers stderr and only forwards it when the command succeeds.Repro script:
Address #1697 (comment)