-
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.
Add support for override_target when using bzlmod (#2683)
The ability to override crate targets when using crate_universe was added here: #2674 However, this change did not expose that functionality when using bzlmod. This change adds that functionality in. Because of the limited set of options we have for dictionaries in tag classes, I had to split out "override_targets" into four different options, each taking a Label. I have added in an example based on the example given in #2674 , but using bzlmod instead. I have also tested that example and found it to be working.
- Loading branch information
1 parent
ada2e52
commit bbbeb68
Showing
12 changed files
with
162 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Required on windows | ||
common --enable_platform_specific_config | ||
startup --windows_enable_symlinks | ||
build:windows --enable_runfiles | ||
|
||
build --experimental_enable_bzlmod | ||
|
||
# This isn't currently the defaut in Bazel, but we enable it to test we'll be ready if/when it flips. | ||
build --incompatible_disallow_empty_glob | ||
|
||
# Required for cargo_build_script support before Bazel 7 | ||
build --incompatible_merge_fixed_and_default_shell_env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bazel-* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") | ||
|
||
rust_library( | ||
name = "override_targets_example", | ||
srcs = glob(["src/*.rs"]), | ||
edition = "2018", | ||
deps = [ | ||
"@override_test//:foo", | ||
], | ||
) | ||
|
||
rust_library( | ||
name = "foo", | ||
srcs = ["foo.rs"], | ||
edition = "2018", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
rust_test( | ||
name = "unit_test", | ||
crate = ":override_targets_example", | ||
edition = "2018", | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[workspace] | ||
[package] | ||
name = "override_targets" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
path = "/dev/null" | ||
|
||
[dependencies.foo] | ||
version = "0.0.0" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""bazelbuild/rules_rust - bzlmod example""" | ||
|
||
module( | ||
name = "override_target_example_with_bzlmod", | ||
version = "0.0.0", | ||
) | ||
|
||
bazel_dep(name = "platforms", version = "0.0.8") | ||
bazel_dep( | ||
name = "bazel_skylib", | ||
version = "1.5.0", | ||
) | ||
bazel_dep( | ||
name = "rules_rust", | ||
version = "0.0.0", | ||
) | ||
local_path_override( | ||
module_name = "rules_rust", | ||
path = "../../..", | ||
) | ||
|
||
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") | ||
rust.toolchain(edition = "2021") | ||
use_repo( | ||
rust, | ||
"rust_toolchains", | ||
) | ||
|
||
register_toolchains("@rust_toolchains//:all") | ||
|
||
crate = use_extension( | ||
"@rules_rust//crate_universe:extension.bzl", | ||
"crate", | ||
) | ||
crate.from_cargo( | ||
name = "override_test", | ||
cargo_lockfile = "//:Cargo.lock", | ||
manifests = ["//:Cargo.toml"], | ||
) | ||
crate.annotation( | ||
crate = "foo", | ||
override_target_lib = "@//:foo", | ||
) | ||
use_repo(crate, "override_test") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally blank; using bzlmod |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally blank; enable strict mode for bzlmod |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const THE_ANSWER: u32 = 42; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
mod test { | ||
#[test] | ||
pub fn test() { | ||
assert_eq!(foo::THE_ANSWER, 42); | ||
} | ||
} |