-
Notifications
You must be signed in to change notification settings - Fork 431
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
Update cargo_build_script
to always render custom runfiles dirs.
#2891
Conversation
631255f
to
4c1a552
Compare
@@ -61,7 +61,7 @@ fn main() { | |||
.expect("Failed to create output directory"); | |||
std::fs::copy(src, &out_dest).unwrap_or_else(|e| { |
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.
If this is going to exist long term then perhaps this directory could have symlinks generated into it whenever possible and the files from DefaultInfo.default_runfiles.files
can be tracked in addition to the output directory. This would probably match runfiles directories more directly but I'm concerned about how remote caches will handle a directory of symlinks so will save such an optimization for another time.
0aa3935
to
91a8ae6
Compare
After soaking this change, I'm finding it leads to additional issues within the
The error is somewhat confusing but when I manually inspect the filesystem on the worker I see very strangely: dir bazel-out\**\
It appears the way symlinks are created confuse Windows into believing these are directories. When I inspect the target of the symlink I can see it's to the original build script: (Get-Item _bs-.exe).Target
However, the script is not on the machine. This is extra strange to me because while investigating I'd explicitly added the real build script to the runfiles of the diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
index 28f91000..c6647ebe 100644
--- a/cargo/private/cargo_build_script.bzl
+++ b/cargo/private/cargo_build_script.bzl
@@ -48,7 +48,7 @@ def _cargo_build_script_runfiles_impl(ctx):
# Tools are ommitted here because they should be within the `script`
# attribute's runfiles.
- runfiles = ctx.runfiles(files = ctx.files.data)
+ runfiles = ctx.runfiles(files = [script] + ctx.files.data)
return [
DefaultInfo( This very much feels like a bug to me. If a depset of files is passed to an action, all files should be downloaded and made available for the action. I'm not sure what to do with this change. It still feels more correct but I do not know how to handle this case and the failure mode of the |
1ac6def
to
f174fd5
Compare
84290cd
to
b2307bd
Compare
b2307bd
to
9a35c22
Compare
9146393
to
d0e7593
Compare
d0e7593
to
eb8ae5e
Compare
I've decided to introduce an incompatibility flag to enable this behavior by default and a new flag for pruning the generated |
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.
This feels quite complicated, but I can see how we ended up here... Thanks for tracking it down!
Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
##### [`v0.52.0](https://github.com/bazelbuild/rules_rust/releases/tag/0.52.0) ### 0.52.0 #### Bzlmod ```python bazel_dep(name = "rules_rust", version = "0.52.0") ``` #### WORKSPACE ```python load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_rust", integrity = "sha256-eTHntUQQe2ICm/L8cuefnXdSOtZQ1ELZPD/M6a1ewes=", urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.52.0/rules_rust-v0.52.0.tar.gz"], ) ``` Additional documentation can be found at: https://bazelbuild.github.io/rules_rust/#setup #### What's Changed - Allowlist more clang flags in bindgen by [@hlopko](https://github.com/hlopko) in bazelbuild/rules_rust#2902 - Allow `+` in repo names by [@fmeum](https://github.com/fmeum) in bazelbuild/rules_rust#2908 - Added utility for parsing action Args param files by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2897 - Updated platform triple mapping to support T3 platforms without `std`. by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2899 - Fix `override_targets` keys in docs by [@max-heller](https://github.com/max-heller) in bazelbuild/rules_rust#2905 - Use absolute path with "-fsanitize-ignorelist" by [@vitalybuka](https://github.com/vitalybuka) in bazelbuild/rules_rust#2911 - Fix platform validation for wasm32-wasip1 target by [@c16a](https://github.com/c16a) in bazelbuild/rules_rust#2894 - Update `cargo_build_script` to always render custom runfiles dirs. by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2891 - Check target tags before ignore tags for lint/fmt aspects by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2913 - Get rolling releases CI green by [@illicitonion](https://github.com/illicitonion) in bazelbuild/rules_rust#2916 - Avoid uses of shell to improve Windows tests by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2912 - Prep release 0.52.0 by [@illicitonion](https://github.com/illicitonion) in bazelbuild/rules_rust#2910 #### New Contributors - [@fmeum](https://github.com/fmeum) made their first contribution in bazelbuild/rules_rust#2908 - [@max-heller](https://github.com/max-heller) made their first contribution in bazelbuild/rules_rust#2905 - [@vitalybuka](https://github.com/vitalybuka) made their first contribution in bazelbuild/rules_rust#2911 - [@c16a](https://github.com/c16a) made their first contribution in bazelbuild/rules_rust#2894 **Full Changelog**: bazelbuild/rules_rust@0.51.0...0.52.0
##### [`v0.52.0](https://github.com/bazelbuild/rules_rust/releases/tag/0.52.0) ### 0.52.0 #### Bzlmod ```python bazel_dep(name = "rules_rust", version = "0.52.0") ``` #### WORKSPACE ```python load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_rust", integrity = "sha256-eTHntUQQe2ICm/L8cuefnXdSOtZQ1ELZPD/M6a1ewes=", urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.52.0/rules_rust-v0.52.0.tar.gz"], ) ``` Additional documentation can be found at: https://bazelbuild.github.io/rules_rust/#setup #### What's Changed - Allowlist more clang flags in bindgen by [@hlopko](https://github.com/hlopko) in bazelbuild/rules_rust#2902 - Allow `+` in repo names by [@fmeum](https://github.com/fmeum) in bazelbuild/rules_rust#2908 - Added utility for parsing action Args param files by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2897 - Updated platform triple mapping to support T3 platforms without `std`. by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2899 - Fix `override_targets` keys in docs by [@max-heller](https://github.com/max-heller) in bazelbuild/rules_rust#2905 - Use absolute path with "-fsanitize-ignorelist" by [@vitalybuka](https://github.com/vitalybuka) in bazelbuild/rules_rust#2911 - Fix platform validation for wasm32-wasip1 target by [@c16a](https://github.com/c16a) in bazelbuild/rules_rust#2894 - Update `cargo_build_script` to always render custom runfiles dirs. by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2891 - Check target tags before ignore tags for lint/fmt aspects by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2913 - Get rolling releases CI green by [@illicitonion](https://github.com/illicitonion) in bazelbuild/rules_rust#2916 - Avoid uses of shell to improve Windows tests by [@UebelAndre](https://github.com/UebelAndre) in bazelbuild/rules_rust#2912 - Prep release 0.52.0 by [@illicitonion](https://github.com/illicitonion) in bazelbuild/rules_rust#2910 #### New Contributors - [@fmeum](https://github.com/fmeum) made their first contribution in bazelbuild/rules_rust#2908 - [@max-heller](https://github.com/max-heller) made their first contribution in bazelbuild/rules_rust#2905 - [@vitalybuka](https://github.com/vitalybuka) made their first contribution in bazelbuild/rules_rust#2911 - [@c16a](https://github.com/c16a) made their first contribution in bazelbuild/rules_rust#2894 **Full Changelog**: bazelbuild/rules_rust@0.51.0...0.52.0
This was a miss from #2891
After #2826 was merged, I started seeing flaky builds on Windows related to build script executables (#2891 (comment)). This appears to be related to bazelbuild/bazel#21747 so to avoid the issue, this change ensures that Windows build script executables are copied instead of symlinked.
After #2887 I started finding similar linker errors in environments that supported runfiles and symlinks but have yet to see this issue in environments without them. I believe my understanding of how the DefaultInfo.default_runfiles objects worked and in the previous change had attempted to rely on it for a runfiles directory. However, there is no guarantee a directory will be rendered and no way to force it to be rendered for actions either (bazelbuild/bazel#15486). The consequence is that creating a custom runfiles directory is no longer a contingency and explicitly creating it is the correct thing to do to ensure
CARGO_MANIFEST_DIR
linker inputs are always available to the consuming actions.With the propagation of
CARGO_MANIFEST_DIR
(now an action output) intoRustc
actions, a new flag is also introduced to prune unnecessary files out of the directory to reduce bloat and potential invalidation in downstream actions,--@rules_rust//cargo/settings:cargo_manifest_dir_filename_suffixes_to_retain
. This flag accepts a list of path suffixes used to determine what (if anything) inCARGO_MANIFEST_DIR
should be retained and passed to downstream actions.Note that the failure mode this addresses is hard to observe as it requires a crate which defines a linker path to something in
CARGO_MANIFEST_DIR
and then for a clean build to be done with a change to a dependent of said crate. If the runfiles directory for the build script is never rendered then there will be no file to link into the crate.