Repository navigation
fix: resolve compiler shims through PATH - #1519
rksharma-owg wants to merge 1 commit into
Conversation
|
Hi @rksharma-owg! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary: Cargo always sets `OPT_LEVEL` (`0` to `3`, `s` or `z`) in the environment of a build script. cc-rs requires it: `cc::Build::compile` fails with `Environment variable OPT_LEVEL not defined` when it is missing (cc 1.2.52 and 1.4.x). `buildscript_run` set `OPT_LEVEL` only when the toolchain's rustc flags contained `-Copt-level=` followed by a digit. So every build script that uses cc-rs (`ring`, `zstd-sys`, `libz-sys`, `psm`, …) fails: - under a toolchain without such a flag, which includes the default `system_rust_toolchain` (`rustc_flags = []`); - under `-Copt-level=s` or `-Copt-level=z`, which are excluded by the digit check. The shim works around this crate by crate: the fixups of `psm`, `stacker` and `aws-lc-fips-sys` set `OPT_LEVEL = "3"`. This PR takes the last `-Copt-level=` of the rustc flags, `s` and `z` included, and uses rustc's default `0` when there is none. An `OPT_LEVEL` in the target's `env` still takes precedence, as in those fixups. ## Affected version origin/main 00c2ee4. ## Reproduction A build script that compiles one C file with cc-rs 1.2.52, run through `buildscript_run` with the prelude's demo toolchains: ```rust fn main() { cc::Build::new().file("foo.c").compile("foo"); } ``` ## Expected The build script runs, as under Cargo. ## Actual ``` OPT_LEVEL = None error occurred in cc-rs: Environment variable OPT_LEVEL not defined. ``` Pull Request resolved: #1669 Test Plan: - New `tests/prelude/rust/buildscript_opt_level`: a build script reports its `OPT_LEVEL` as a cfg, and the assertion expects a valid level in `[rustc_flags]`. - Checked with a locally built buck2 and the demo toolchains on macOS: - That build script reports `opt_level=""` on origin/main, `opt_level="0"` with this change, and `opt_level="s"` with `rustc_flags = ["-Copt-level=s"]`. - The cc-rs build script above fails on origin/main and builds `libfoo.a` with this change. To get past cc-rs, the local prelude also had the `os.execvp` change of #1519 (#1491): under the default `system_cxx_toolchain`, the next step fails without it. Reviewed By: dtolnay Differential Revision: D134832191 fbshipit-source-id: e0c3f9089c49ec8615b58b85ca22992a5cea88e7
Summary
Resolve bare compiler commands through PATH in the Rust build-script compiler shim.
Problem
The default system C++ toolchain can provide a bare compiler name such as clang. from_any_dir.py currently calls os.execl, which does not search PATH, so the build-script path fails with FileNotFoundError even though the same compiler works for ordinary C++ targets.
Root Cause
os.execl requires the executable to be directly resolvable and does not perform PATH lookup.
Fix
Use os.execvp so the compiler command is resolved using the action environment PATH while preserving the original argument vector.
Tests
The Windows timeout was not a test assertion failure and is reported here for transparency. Scope is intentionally limited to compiler command resolution in the Rust build-script shim.
Fixes #1491