-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid double building
cargo_build_script.data
targets (#2826)
Before this change targets passed to `cargo_build_script.data` would get built multiple times (once per configuration) ``` % bazel cquery 'filter(//test/cargo_build_script/location_expansion:target_data.txt, deps(//test/cargo_build_script/location_expansion:build_rs))' //test/cargo_build_script/location_expansion:target_data.txt (be33641) //test/cargo_build_script/location_expansion:target_data.txt (a1c326f) ``` We can see that this is the exec (`a1c326f`) and target (`be33641`) configurations. ``` % bazel config a1c326f be33641 INFO: Displaying diff between configs a1c326f and be33641 Displaying diff between configs a1c326f and be33641 FragmentOptions com.google.devtools.build.lib.analysis.PlatformOptions { platforms: [@@internal_platforms_do_not_use//host:host], [@@bazel_tools//tools:host_platform] } FragmentOptions com.google.devtools.build.lib.analysis.config.CoreOptions { compilation_mode: opt, fastbuild is exec configuration: true, false platform_suffix: exec, null } FragmentOptions com.google.devtools.build.lib.rules.android.AndroidConfiguration$Options { fat_apk_cpu: [], [armeabi-v7a] } FragmentOptions com.google.devtools.build.lib.rules.cpp.CppOptions { copt: [-g0], [] cxxopt: [-g0], [] strip: always, sometimes } FragmentOptions com.google.devtools.build.lib.rules.java.JavaOptions { java_runtime_version: remotejdk_11, local_jdk jvmopt: [-XX:ErrorFile=/dev/stderr], [] } ``` This is caused by `data` being passed to the underlying rust binary in `cargo_build_script_wrapper.bzl`. The fix for this ends up requiring some gymnastics as many existing uses of `cargo_build_script` rely on `data` files being available within the runfiles of `cargo_build_script.script`. This change accounts for that by creating a wrapper rule for the build script that symlinks the `cfg=exec` Rust binary (which is the actual [Cargo build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html)) and updating the `cargo_build_script` rule to consume it as `cfg=target`. Within the `cargo_build_script` rule this means the script target and it's `data` attribute files will be in `cfg=target` but the binary itself will have been built for `cfg=exec` and will be runnable on the exec platform. We see after this change that data targets only appear once now ``` % bazel cquery 'filter(//test/cargo_build_script/location_expansion:target_data.txt, deps(//test/cargo_build_script/location_expansion:build_rs))' //test/cargo_build_script/location_expansion:target_data.txt (be33641) ```
- Loading branch information
1 parent
05d54a4
commit cbdf540
Showing
3 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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