Skip to content

Commit

Permalink
Avoid using local_path_override in extension rules
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Dec 9, 2024
1 parent c9f561f commit 7942272
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .bcr/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
filegroup(
name = "extension_presubmits",
srcs = glob([
"extensions/**/presubmit.yml",
]),
visibility = ["//test/bzl_version:__pkg__"],
)
10 changes: 9 additions & 1 deletion .bcr/extensions/bindgen/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ bcr_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
shell_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "rm MODULE.bazel.lock || true"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "mkdir -p .bcr/core && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr/core && echo 'common --override_module=rules_rust=.bcr/core' > user.bazelrc"
batch_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "del MODULE.bazel.lock"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "(if not exist .bcr\\core mkdir .bcr\\core) && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr\\core && echo common --override_module=rules_rust=.bcr/core > user.bazelrc"

test_targets:
- "//..."
9 changes: 8 additions & 1 deletion .bcr/extensions/prost/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ bcr_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
shell_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "rm MODULE.bazel.lock || true"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "mkdir -p .bcr/core && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr/core && echo 'common --override_module=rules_rust=.bcr/core' > user.bazelrc"
batch_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "del MODULE.bazel.lock"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "(if not exist .bcr\\core mkdir .bcr\\core) && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr\\core && echo common --override_module=rules_rust=.bcr/core > user.bazelrc"
test_targets:
- "//..."
9 changes: 8 additions & 1 deletion .bcr/extensions/protobuf/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ bcr_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
shell_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "rm MODULE.bazel.lock || true"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "mkdir -p .bcr/core && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr/core && echo 'common --override_module=rules_rust=.bcr/core' > user.bazelrc"
batch_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "del MODULE.bazel.lock"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "(if not exist .bcr\\core mkdir .bcr\\core) && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr\\core && echo common --override_module=rules_rust=.bcr/core > user.bazelrc"
test_targets:
- "//..."
9 changes: 8 additions & 1 deletion .bcr/extensions/wasm_bindgen/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ bcr_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
shell_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "rm MODULE.bazel.lock || true"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "mkdir -p .bcr/core && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr/core && echo 'common --override_module=rules_rust=.bcr/core' > user.bazelrc"
batch_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "del MODULE.bazel.lock"
# Vendor the core rules to avoid failures from use of `local_path_override`
- "(if not exist .bcr\\core mkdir .bcr\\core) && curl -L https://github.com/bazelbuild/rules_rust/releases/download/0.55.4/rules_rust-0.55.4.tar.gz | tar -xz -C .bcr\\core && echo common --override_module=rules_rust=.bcr/core > user.bazelrc"
test_targets:
- "//..."
4 changes: 2 additions & 2 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ bcr_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
shell_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "rm MODULE.bazel.lock || true"
run_targets:
- "//third-party-in-workspace:vendor"
Expand All @@ -28,8 +28,8 @@ bcr_test_module_windows:
name: "Run test module"
platform: windows
bazel: ${{ bazel }}
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
shell_commands:
# Remove the lockfile because we generate on Bazel 7, but test on Bazel 6 which may not be able to parse a future-generated lockfile.
- "rm MODULE.bazel.lock || true"
run_targets:
- "//third-party-in-workspace:vendor"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ jobs:
tar -czf ${{ github.workspace }}/.github/rules_rust_bindgen.tar.gz \
-C ${{ github.workspace }}/extensions/bindgen \
--exclude="examples" \
--exclude="dev.bazelrc" \
.
# Save the sha256 checksum of the distro archive to the environment
Expand All @@ -169,6 +170,7 @@ jobs:
tar -czf ${{ github.workspace }}/.github/rules_rust_prost.tar.gz \
-C ${{ github.workspace }}/extensions/prost \
--exclude="examples" \
--exclude="dev.bazelrc" \
.
# Save the sha256 checksum of the distro archive to the environment
Expand All @@ -180,6 +182,7 @@ jobs:
tar -czf ${{ github.workspace }}/.github/rules_rust_protobuf.tar.gz \
-C ${{ github.workspace }}/extensions/protobuf \
--exclude="examples" \
--exclude="dev.bazelrc" \
.
# Save the sha256 checksum of the distro archive to the environment
Expand All @@ -191,6 +194,7 @@ jobs:
tar -czf ${{ github.workspace }}/.github/rules_rust_wasm_bindgen.tar.gz \
-C ${{ github.workspace }}/extensions/wasm_bindgen \
--exclude="examples" \
--exclude="dev.bazelrc" \
.
# Save the sha256 checksum of the distro archive to the environment
Expand Down
4 changes: 4 additions & 0 deletions extensions/bindgen/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ common:no-bzlmod --noenable_bzlmod --enable_workspace
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

# Allow bazel configuration flags to locate the core rules to avoid adding local
# override paths to the `MODULE.bazel` file and breaking downstream consumers.
try-import %workspace%/dev.bazelrc

###############################################################################
## Custom user flags
##
Expand Down
1 change: 1 addition & 0 deletions extensions/bindgen/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rust-project.json

# BazelCI
bazelci.py
.bcr/core
4 changes: 0 additions & 4 deletions extensions/bindgen/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ bazel_dep(
name = "rules_rust",
version = "0.55.4",
)
local_path_override(
module_name = "rules_rust",
path = "../..",
)

bazel_dep(
name = "bazel_skylib",
Expand Down
5 changes: 5 additions & 0 deletions extensions/bindgen/dev.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A Bazel configuration flag used to locate the core rules when developing
# within the `rules_rust` repository. This file should not be used by
# external consumers

common --override_module=rules_rust=../../
4 changes: 4 additions & 0 deletions extensions/prost/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ common:no-bzlmod --noenable_bzlmod --enable_workspace
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

# Allow bazel configuration flags to locate the core rules to avoid adding local
# override paths to the `MODULE.bazel` file and breaking downstream consumers.
try-import %workspace%/dev.bazelrc

###############################################################################
## Custom user flags
##
Expand Down
1 change: 1 addition & 0 deletions extensions/prost/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rust-project.json

# BazelCI
bazelci.py
.bcr/core
4 changes: 0 additions & 4 deletions extensions/prost/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ bazel_dep(
name = "rules_rust",
version = "0.55.4",
)
local_path_override(
module_name = "rules_rust",
path = "../..",
)

bazel_dep(
name = "platforms",
Expand Down
5 changes: 5 additions & 0 deletions extensions/prost/dev.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A Bazel configuration flag used to locate the core rules when developing
# within the `rules_rust` repository. This file should not be used by
# external consumers

common --override_module=rules_rust=../../
4 changes: 4 additions & 0 deletions extensions/protobuf/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ common:no-bzlmod --noenable_bzlmod --enable_workspace
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

# Allow bazel configuration flags to locate the core rules to avoid adding local
# override paths to the `MODULE.bazel` file and breaking downstream consumers.
try-import %workspace%/dev.bazelrc

###############################################################################
## Custom user flags
##
Expand Down
1 change: 1 addition & 0 deletions extensions/protobuf/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rust-project.json

# BazelCI
bazelci.py
.bcr/core
4 changes: 0 additions & 4 deletions extensions/protobuf/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ bazel_dep(
name = "rules_rust",
version = "0.55.4",
)
local_path_override(
module_name = "rules_rust",
path = "../..",
)

bazel_dep(
name = "bazel_skylib",
Expand Down
5 changes: 5 additions & 0 deletions extensions/protobuf/dev.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A Bazel configuration flag used to locate the core rules when developing
# within the `rules_rust` repository. This file should not be used by
# external consumers

common --override_module=rules_rust=../../
4 changes: 4 additions & 0 deletions extensions/wasm_bindgen/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ common:no-bzlmod --noenable_bzlmod --enable_workspace
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

# Allow bazel configuration flags to locate the core rules to avoid adding local
# override paths to the `MODULE.bazel` file and breaking downstream consumers.
try-import %workspace%/dev.bazelrc

###############################################################################
## Custom user flags
##
Expand Down
1 change: 1 addition & 0 deletions extensions/wasm_bindgen/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rust-project.json

# BazelCI
bazelci.py
.bcr/core
4 changes: 0 additions & 4 deletions extensions/wasm_bindgen/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ bazel_dep(
name = "rules_rust",
version = "0.55.4",
)
local_path_override(
module_name = "rules_rust",
path = "../..",
)

bazel_dep(
name = "bazel_skylib",
Expand Down
5 changes: 5 additions & 0 deletions extensions/wasm_bindgen/dev.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# A Bazel configuration flag used to locate the core rules when developing
# within the `rules_rust` repository. This file should not be used by
# external consumers

common --override_module=rules_rust=../../
16 changes: 16 additions & 0 deletions test/bzl_version/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load(":bzl_version_test.bzl", "bzl_version_test")
load("//rust:defs.bzl", "rust_test")
load("//:version.bzl", "VERSION")

exports_files([
"bzl_version_test.rs",
Expand All @@ -9,3 +11,17 @@ bzl_version_test(
name = "bzl_version_test",
module_bazel = "//:MODULE.bazel",
)

rust_test(
name = "presubmit_validation_test",
srcs = ["presubmit_validation_test.rs"],
data = ["//.bcr:extension_presubmits"],
edition = "2021",
rustc_env = {
"PRESUBMIT_RLOCATIONPATHS": "$(rlocationpaths //.bcr:extension_presubmits)",
"RULES_RUST_VERSION": VERSION,
},
deps = [
"//tools/runfiles",
],
)
32 changes: 32 additions & 0 deletions test/bzl_version/presubmit_validation_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Tests to verify bazel-central-registry CI is configured for the current
//! version of rules_rust.
use runfiles::Runfiles;

/// If this test fails, it means the vendoring of the core rules is not in
/// sync with the current version of rules_rust and the urls need to be updated.
#[test]
fn vendered_core_rules_version_in_sync() {
let r = Runfiles::create().unwrap();
let rlocationpaths = env!("PRESUBMIT_RLOCATIONPATHS")
.split(" ")
.collect::<Vec<_>>();

let core_cmd_unix = format!("\"mkdir -p .bcr/core && curl -L https://github.com/bazelbuild/rules_rust/releases/download/{0}/rules_rust-{0}.tar.gz | tar -xz -C .bcr/core && echo 'common --override_module=rules_rust=.bcr/core' > user.bazelrc\"", env!("RULES_RUST_VERSION"));
let core_cmd_windows = format!("\"(if not exist .bcr\\\\core mkdir .bcr\\\\core) && curl -L https://github.com/bazelbuild/rules_rust/releases/download/{0}/rules_rust-{0}.tar.gz | tar -xz -C .bcr\\\\core && echo common --override_module=rules_rust=.bcr/core > user.bazelrc\"", env!("RULES_RUST_VERSION"));

let cmds = [core_cmd_unix, core_cmd_windows];

for rlocationpath in rlocationpaths {
let path = runfiles::rlocation!(r, rlocationpath).unwrap();
let content = std::fs::read_to_string(path).unwrap();
for cmd in &cmds {
assert!(
content.contains(cmd),
"{} did not contain the expected vendor command:\n{}",
rlocationpath,
cmd
);
}
}
}

0 comments on commit 7942272

Please sign in to comment.