-
Notifications
You must be signed in to change notification settings - Fork 591
Avoid adding data (vs compile_data) to Rustc actions #3916
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,5 @@ | ||
| load(":transitive_data_test.bzl", "transitive_cbs_data_test_suite") | ||
|
|
||
| transitive_cbs_data_test_suite( | ||
| name = "transitive_cbs_data_test_suite", | ||
| ) |
115 changes: 115 additions & 0 deletions
115
cargo/tests/cargo_build_script/transitive_data/transitive_data_test.bzl
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,115 @@ | ||
| """Tests documenting that cargo_build_script `data` files currently act as both | ||
| compile_data and runtime data -- they appear in Rustc compile action inputs for | ||
| both the direct library and transitive dependents. | ||
|
|
||
| See https://github.com/bazelbuild/rules_rust/issues/3609 for context.""" | ||
|
|
||
| load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
| load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
| load("//cargo:defs.bzl", "cargo_build_script") | ||
| load("//rust:defs.bzl", "rust_library") | ||
|
|
||
| def _cbs_data_in_rustc_inputs_impl(ctx): | ||
| env = analysistest.begin(ctx) | ||
| target = analysistest.target_under_test(env) | ||
|
|
||
| rustc_action = None | ||
| for action in target.actions: | ||
| if action.mnemonic == "Rustc": | ||
| rustc_action = action | ||
| break | ||
|
|
||
| asserts.false(env, rustc_action == None, "Expected a Rustc action") | ||
|
|
||
| # cargo_build_script `data` currently flows into BuildInfo.compile_data | ||
| # via script_data, so it appears in Rustc action inputs for both the | ||
| # direct dependent and transitive dependents. This documents that | ||
| # CBS `data` effectively acts as both compile_data and data today. | ||
| data_inputs = [i for i in rustc_action.inputs.to_list() if "cbs_data_dep.txt" in i.path] | ||
| asserts.true( | ||
| env, | ||
| len(data_inputs) > 0, | ||
| "Expected CBS data file to appear in Rustc action inputs (CBS data currently acts as compile_data)", | ||
| ) | ||
|
|
||
| return analysistest.end(env) | ||
|
|
||
| cbs_data_in_rustc_inputs_test = analysistest.make( | ||
| _cbs_data_in_rustc_inputs_impl, | ||
| ) | ||
|
|
||
| def _define_test_targets(): | ||
| write_file( | ||
| name = "cbs_data_dep_file", | ||
| out = "cbs_data_dep.txt", | ||
| content = ["data for build script", ""], | ||
| newline = "unix", | ||
| ) | ||
|
|
||
| write_file( | ||
| name = "build_rs_src", | ||
| out = "build.rs", | ||
| content = ["fn main() {}", ""], | ||
| newline = "unix", | ||
| ) | ||
|
|
||
| cargo_build_script( | ||
| name = "build_script", | ||
| srcs = [":build.rs"], | ||
| data = [":cbs_data_dep.txt"], | ||
| edition = "2021", | ||
| ) | ||
|
|
||
| write_file( | ||
| name = "lib_src", | ||
| out = "lib.rs", | ||
| content = ["pub fn hello() {}", ""], | ||
| newline = "unix", | ||
| ) | ||
|
|
||
| rust_library( | ||
| name = "lib", | ||
| srcs = [":lib.rs"], | ||
| deps = [":build_script"], | ||
| edition = "2021", | ||
| ) | ||
|
|
||
| write_file( | ||
| name = "bin_src", | ||
| out = "bin.rs", | ||
| content = ["extern crate lib;", ""], | ||
| newline = "unix", | ||
| ) | ||
|
|
||
| rust_library( | ||
| name = "bin", | ||
| srcs = [":bin.rs"], | ||
| deps = [":lib"], | ||
| edition = "2021", | ||
| ) | ||
|
|
||
| def transitive_cbs_data_test_suite(name): | ||
| """Entry-point macro called from the BUILD file. | ||
|
|
||
| Args: | ||
| name (str): Name of the macro. | ||
| """ | ||
| _define_test_targets() | ||
|
|
||
| cbs_data_in_rustc_inputs_test( | ||
| name = "cbs_data_in_lib_compile_inputs_test", | ||
| target_under_test = ":lib", | ||
| ) | ||
|
|
||
| cbs_data_in_rustc_inputs_test( | ||
| name = "cbs_data_in_bin_compile_inputs_test", | ||
| target_under_test = ":bin", | ||
| ) | ||
|
|
||
| native.test_suite( | ||
| name = name, | ||
| tests = [ | ||
| ":cbs_data_in_lib_compile_inputs_test", | ||
| ":cbs_data_in_bin_compile_inputs_test", | ||
| ], | ||
| ) |
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.