-
Notifications
You must be signed in to change notification settings - Fork 478
Populate CFLAGS and CXXFLAGS when invoking cargo build script. #1081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1c7940d
to
aff27ba
Compare
Thanks for putting this together! It's pretty similar to #1004 but the differences are pretty interesting, so it's probably worth lingering on them for a moment:
Either way, there's an open question for @hlopko - Do we have any prior art on wiring up a custom cc_toolchain in a unit analysis test, so that we could test that args get properly propagated from there? (cc @ikalchev - sorry we've left your PR open for so long! I don't really have a preference for which PR we end up merging, but it'd be great to come to a consensus on the open questions above :)) |
We don't have an existing example, and creating even a fake cc toolchain is quite an endeavor (docs are here: https://docs.bazel.build/versions/main/cc-toolchain-config-reference.html, and I'd be surprised if they were up to date). I think I cannot ask anybody to try doing that without feeling like the pure evil. So I can commit to sending an PR with this fake cc toolchain next week. Hope that's quickly enough. |
27dd302
to
953cce3
Compare
I can confirm that this fixes some build issues for me. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this - we can address the c/cpp and sysroot questions in the future as/when needed :)
Sorry for the delay here!
Downstream tools (in particular cc-rs) depend on them being set. The particular use case that I noticed was broken was the macos deployment target (specified via the --macos_minimun_os Bazel option) wasn't being applied on binaries being built via cc-rs in a build.rs script. This was causing all sort of bugs such as symbols not being weakly linked since it was using the SDK version (the default) for the deployment target and bazel-built Rust binaries wouldn't load on older OS versions due to failures to resolve symbols at runtime, even though the deployment target was correctly set in Bazel.
f513424
to
b327469
Compare
PR bazelbuild#1081 started passing CFLAGS to build scripts, which cargo does too. But unfortunately Bazel's cpp toolchain adds an explicit target to the CFLAGS it provides, and that target uses the host platform instead of the target platform. When building a crate like blake3 or zstd on a Mac with iOS as the target, this ends up in the crate being built for macOS instead of iOS.
PR bazelbuild#1081 started passing CFLAGS to build scripts, which cargo does too. But unfortunately Bazel's cpp toolchain adds an explicit target to the CFLAGS it provides, and that target uses the host platform instead of the target platform. When building a crate like blake3 or zstd on a Mac with iOS as the target, this ends up in the crate being built for macOS instead of iOS.
PR bazelbuild#1081 started passing CFLAGS to build scripts, which cargo does too. But unfortunately Bazel's cpp toolchain adds an explicit target to the CFLAGS it provides, and that target uses the host platform instead of the target platform. When building a crate like blake3 or zstd on a Mac with iOS as the target, this ends up in the crate being built for macOS instead of iOS.
PR bazelbuild#1081 started passing CFLAGS to build scripts, which cargo does too. But unfortunately Bazel's cpp toolchain adds an explicit target to the CFLAGS it provides, and that target uses the host platform instead of the target platform. When building a crate like blake3 or zstd on a Mac with iOS as the target, this ends up in the crate being built for macOS instead of iOS.
PR bazelbuild#1081 started passing CFLAGS to build scripts, which cargo does too. But unfortunately Bazel's cpp toolchain adds an explicit target to the CFLAGS it provides, and that target uses the host platform instead of the target platform. When building a crate like blake3 or zstd on a Mac with iOS as the target, this ends up in the crate being built for macOS instead of iOS.
* Fix build scripts targeting the wrong architecture PR #1081 started passing CFLAGS to build scripts, which cargo does too. But unfortunately Bazel's cpp toolchain adds an explicit target to the CFLAGS it provides, and that target uses the host platform instead of the target platform. When building a crate like blake3 or zstd on a Mac with iOS as the target, this ends up in the crate being built for macOS instead of iOS. * Add an end-to-end test to make sure building zstd for iOS works
Downstream tools (in particular cc-rs) depend on them being set.
The particular use case that I noticed was broken was the macos deployment target (specified via the --macos_minimun_os Bazel option) wasn't being applied on binaries being built via cc-rs in a build.rs script. This was causing all sort of bugs such as symbols not being weakly linked since it was using the SDK version (the default) for the deployment target and bazel-built Rust binaries wouldn't load on older OS versions due to failures to resolve symbols at runtime, even though the deployment target was correctly set in Bazel.