Skip to content

Conversation

@armandomontanez
Copy link
Contributor

This was preventing ar flags from propagating to the cargo build script runner.

@armandomontanez armandomontanez force-pushed the fix-ar-flags branch 2 times, most recently from 553c3f0 to e0e5ddc Compare October 28, 2025 00:32
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me! Would you also be able to add some sort of regression test to //test/cargo_build_script/...? I would love to know the plumbing of AR args continues to work.

edit: Also, thank you!

@armandomontanez
Copy link
Contributor Author

Looks like the macOS failure is very relevant; the configured toolchain's AR binary is still not making it through. It looks like toolchains_llvm intends to use libtool-darwin, but either it's misconfigured, or something here still isn't picking up that tool.

@armandomontanez
Copy link
Contributor Author

Looks like the macOS failure is very relevant; the configured toolchain's AR binary is still not making it through. It looks like toolchains_llvm intends to use libtool-darwin, but either it's misconfigured, or something here still isn't picking up that tool.

Hmm... or not. Looks like it's failing on other builds too. Test log contents:

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //test/cc_shared_library:test
-----------------------------------------------------------------------------
external/bazel_tools/tools/test/collect_cc_coverage.sh: line 99: : command not found
error: coverage collection script failed

There were two issues with AR in the cargo_build_script rule:

  1. ARFLAGS was not set.
  2. For many toolchains, the ar tool was not properly configured.

This change fixes both of those problems.
@armandomontanez
Copy link
Contributor Author

Hmm, Cross compilation with bzlmod on macOS does appear to be a real failure. Got mixed up with another failure.

TL;DR: cc-rs does not properly support libtool, which means enabling support for respecting the AR toolchain breaks all macOS toolchains that use libtool or llvm-libtool-darwin.

@armandomontanez armandomontanez marked this pull request as draft October 28, 2025 21:50
@armandomontanez
Copy link
Contributor Author

armandomontanez commented Nov 2, 2025

I'd much rather emit an error if libtool is in use rather than using a non-hermetic ar, but that's a breaking change. For now, I'll retain the previous behavior but make it more likely to work as intended (catching llvm-libtool-darwin in addition to libtool, and clearing ARFLAGS that are now properly forwarded for other archiver tools).

I'll try to add libtool support to cc-rs in parallel, but probably shouldn't block on that.

@armandomontanez armandomontanez marked this pull request as ready for review November 2, 2025 23:50
@armandomontanez
Copy link
Contributor Author

Ping :)

Copy link
Collaborator

@UebelAndre UebelAndre 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!

@UebelAndre UebelAndre added this pull request to the merge queue Nov 17, 2025
Merged via the queue into bazelbuild:main with commit 982c202 Nov 17, 2025
3 checks passed
armandomontanez added a commit to armandomontanez/rules_rust that referenced this pull request Dec 8, 2025
This is a partial revert of bazelbuild#3704. It does NOT revert logic that
properly finds the hermetic archiver (binary and associated tests).

cc-rs needs full ownership of flag handling for the archiver. This is in
part due to `ar` having very specific positional flag behaviors, and
partially due to some special logic in how cc-rs constructs static libraries.

The change to enable ARFLAGS was causing many toolchains that pass flags
to the static archiver to error out due to conflicting expectations for
flag handling. Example bad ar invocation, where `cq` is treated as the
destination archive instead of the `ar` tool mode:

ar rcsD cq dest.a src1.o src2.o

This drops forwarding of `ARFLAGS` to fix the common case.
armandomontanez added a commit to armandomontanez/rules_rust that referenced this pull request Dec 9, 2025
This is a partial revert of bazelbuild#3704. It does NOT revert logic that
properly finds the hermetic archiver (binary and associated tests).

cc-rs needs full ownership of flag handling for the archiver. This is in
part due to `ar` having very specific positional flag behaviors, and
partially due to some special logic in how cc-rs constructs static libraries.

The change to enable ARFLAGS was causing many toolchains that pass flags
to the static archiver to error out due to conflicting expectations for
flag handling. Example bad `ar` invocation, where `cq` is treated as the
destination archive instead of the `ar` tool mode:

  ar rcsD cq dest.a src1.o src2.o

This drops forwarding of `ARFLAGS` to fix the common case.
armandomontanez added a commit to armandomontanez/rules_rust that referenced this pull request Dec 9, 2025
This is a partial revert of bazelbuild#3704. It does NOT revert logic that
properly finds the hermetic archiver (binary and associated tests).

cc-rs needs full ownership of flag handling for the archiver. This is in
part due to `ar` having very specific positional flag behaviors, and
partially due to some special logic in how cc-rs constructs static libraries.

The change to enable ARFLAGS was causing many toolchains that pass flags
to the static archiver to error out due to conflicting expectations for
flag handling. Example bad `ar` invocation, where `cq` is treated as the
destination archive instead of the `ar` tool mode:

  ar rcsD cq dest.a src1.o src2.o

This drops forwarding of `ARFLAGS` to fix the common case.
@finn-ball
Copy link
Contributor

Though I support the efforts to streamline bazel's toolchain and rust's, this has the potential to affect anything which depends on the cc-rs crate which can prepend cq to any ar command, conflicting with ar flags set by bazel's toolchain.

https://github.com/rust-lang/cc-rs/blob/9ec00e4bf2a8b087760245b0ec721fb3bd59731f/src/lib.rs#L2747
https://github.com/rust-lang/cc-rs/blob/9ec00e4bf2a8b087760245b0ec721fb3bd59731f/src/lib.rs#L3275

It is trivial to patch but just adding this here as a warning as this is a fairly fundamental crate to many builds.

@fhanau
Copy link

fhanau commented Dec 9, 2025

Though I support the efforts to streamline bazel's toolchain and rust's, this has the potential to affect anything which depends on the cc-rs crate which can prepend cq to any ar command, conflicting with ar flags set by bazel's toolchain.

https://github.com/rust-lang/cc-rs/blob/9ec00e4bf2a8b087760245b0ec721fb3bd59731f/src/lib.rs#L2747 https://github.com/rust-lang/cc-rs/blob/9ec00e4bf2a8b087760245b0ec721fb3bd59731f/src/lib.rs#L3275

It is trivial to patch but just adding this here as a warning as this is a fairly fundamental crate to many builds.

Seeing the same issue – this change results in running $AR rcsd cq when building some crates, causing the action to fail based on the archive being absent so far.

github-merge-queue bot pushed a commit that referenced this pull request Dec 9, 2025
This is a partial revert of #3704. It does NOT revert logic that
properly finds the hermetic archiver (binary and associated tests).

cc-rs needs full ownership of flag handling for the archiver. This is in
part due to `ar` having very specific positional flag behaviors, and
partially due to some special logic in how cc-rs constructs static
libraries.

The change to enable `ARFLAGS` was causing many toolchains that pass
flags to the static archiver to error out due to conflicting
expectations for flag handling. Example bad `ar` invocation, where `cq`
is treated as the destination archive instead of the `ar` tool mode:
```
  ar rcsD cq dest.a src1.o src2.o
```
This drops forwarding of `ARFLAGS` to fix the common case.
@armandomontanez
Copy link
Contributor Author

Yep, this wasn't caught in presubmit due to how toolchains_llvm's ar flags end up being spelled out. Submitted a partial revert (reverted forwarding of AR flags, but not the finding of the archiver tool) as #3763, which is available in 0.68.1. Sorry for the inconvenience here.

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.

4 participants