-
Notifications
You must be signed in to change notification settings - Fork 605
Add test for regression after #4040. #4064
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
Draft
slackito
wants to merge
1
commit into
bazelbuild:main
Choose a base branch
from
slackito:pr4040-regression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| load("@rules_rust//rust:defs.bzl", "rust_binary") | ||
| load("@rules_rust//cargo:defs.bzl", "cargo_build_script") | ||
|
|
||
| package( | ||
| default_visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cargo_build_script( | ||
| name = "build_script", | ||
| srcs = ["build.rs"], | ||
| data = ["data.txt"], | ||
| deps = [ | ||
| "@rules_rust//tools/runfiles", | ||
| ], | ||
| ) | ||
|
|
||
| rust_binary( | ||
| name = "reproduce_bin", | ||
| srcs = ["main.rs"], | ||
| deps = [":build_script"], | ||
| ) | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use std::env; | ||
| use std::path::Path; | ||
|
|
||
| fn main() { | ||
| let r = runfiles::Runfiles::create().unwrap(); | ||
| // The rlocation path is relative to the workspace name | ||
| let rlocation_path = "rules_rust/test/unit/cargo_build_script_data_runfiles/data.txt"; | ||
| let path = runfiles::rlocation!(r, rlocation_path); | ||
|
|
||
| match path { | ||
| Some(p) => { | ||
| if p.exists() { | ||
| println!("cargo:warning=Found data.txt at {}", p.display()); | ||
| } else { | ||
| panic!("data.txt path returned but does not exist: {}", p.display()); | ||
| } | ||
| } | ||
| None => { | ||
| panic!("Failed to resolve runfile path: {}", rlocation_path); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hello world |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| fn main() { | ||
| println!("Hello from main"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ah, I didn't consider cases where
cargo_build_scriptuses the runfiles library. Can you expand on the need for this? For the most part, I would have expected them to only operate on execpath orCARGO_MANIFETST_DIRpaths. We could export the necessary values forscriptrunfiles butdatawouldn't be available and I don't think it's a good idea to try to recreate any kind of repo mapping file to be able to use the merged runfiles dir. Do you have thoughts there?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.
In the particular target that started failing after your commit, someone wanted to embed some config files in a
rust_binary, and they used acargo_build_scripttarget to read .toml files and generate rust code containing the config values.That target doesn't need to be a cargo_build_script. In fact, it used to be a gen_embedded_configs.py
py_binaryand agenrulethat ran the binary before a user switched it to a cargo_build_script because it's "the Rust way". So we can switch it back.What I don't know is what to do with
cargo_build_scriptdata dependencies in general. We could say data files are not accessible as runfiles from the build script. But acargo_build_scriptcan have arbitraryrust_librarytargets asdeps, and these can havedatadeps and presumably need to access them. But right now they'd get the cargo_runfiles tree that we generate and fail in the same way, right?For all I know, maybe we'll end up telling users "don't do that". But I don't feel qualified to make that call yet :|
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.
Does #4066 work for you?