Skip to content

fix(ar): suppress warnings from D modifier probe#1700

Merged
NobodyXu merged 3 commits intorust-lang:mainfrom
weihanglo:silent
Apr 7, 2026
Merged

fix(ar): suppress warnings from D modifier probe#1700
NobodyXu merged 3 commits intorust-lang:mainfrom
weihanglo:silent

Conversation

@weihanglo
Copy link
Copy Markdown
Member

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:

#!/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

Address #1697 (comment)

@weihanglo
Copy link
Copy Markdown
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)

Copy link
Copy Markdown
Contributor

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just some feedback onn print warning

Comment thread src/command_helpers.rs Outdated
Copy link
Copy Markdown
Contributor

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/command_helpers.rs Outdated
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
```
Copy link
Copy Markdown
Contributor

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, LGTM!

Release scheduled on this Friday

@NobodyXu NobodyXu merged commit c15c3eb into rust-lang:main Apr 7, 2026
79 checks passed
@weihanglo weihanglo deleted the silent branch April 7, 2026 14:23
@ffuugoo ffuugoo mentioned this pull request Apr 13, 2026
7 tasks
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.

2 participants