diff --git a/.bazelrc b/.bazelrc index 640354ce69..4b2cae29ab 100644 --- a/.bazelrc +++ b/.bazelrc @@ -60,6 +60,11 @@ build --nolegacy_external_runfiles # Required for cargo_build_script support before Bazel 7 build --incompatible_merge_fixed_and_default_shell_env +# When our minimum bazel version reaches >= 7.4.0, we should uncomment the +# following line to guarantee that rules_rust does not rely on autoloading; +# see https://github.com/bazelbuild/bazel/issues/23043 for details. +# build --incompatible_autoload_externally= + ############################################################################### ## Bzlmod ############################################################################### diff --git a/MODULE.bazel b/MODULE.bazel index d9d168da72..cb20895546 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -29,6 +29,10 @@ bazel_dep( name = "rules_license", version = "1.0.0", ) +bazel_dep( + name = "rules_shell", + version = "0.3.0", +) bazel_dep( name = "apple_support", version = "1.17.1", diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 7eebe67ca5..08c99a0f70 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load("@stardoc//stardoc:stardoc.bzl", "stardoc") load("//:page.bzl", "gen_header", "page") diff --git a/docs/MODULE.bazel b/docs/MODULE.bazel index 3a8be77113..5262916041 100644 --- a/docs/MODULE.bazel +++ b/docs/MODULE.bazel @@ -52,3 +52,7 @@ bazel_dep( name = "rules_cc", version = "0.0.17", ) +bazel_dep( + name = "rules_shell", + version = "0.3.0", +) diff --git a/examples/bazel_env/BUILD.bazel b/examples/bazel_env/BUILD.bazel index 0d1b028831..5269869b12 100644 --- a/examples/bazel_env/BUILD.bazel +++ b/examples/bazel_env/BUILD.bazel @@ -1,5 +1,7 @@ "Tests for upstream wrappers." +load("@rules_shell//shell:sh_test.bzl", "sh_test") + sh_test( name = "upstream_cargo_test", size = "small", diff --git a/examples/bazel_env/MODULE.bazel b/examples/bazel_env/MODULE.bazel index cbb0b0c814..0edb6b307c 100644 --- a/examples/bazel_env/MODULE.bazel +++ b/examples/bazel_env/MODULE.bazel @@ -18,6 +18,11 @@ local_path_override( path = "../..", ) +bazel_dep( + name = "rules_shell", + version = "0.3.0", +) + rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain(edition = "2021") use_repo( diff --git a/examples/bzlmod/all_crate_deps/BUILD.bazel b/examples/bzlmod/all_crate_deps/BUILD.bazel index d4045fd269..7a3ea9a1cd 100644 --- a/examples/bzlmod/all_crate_deps/BUILD.bazel +++ b/examples/bzlmod/all_crate_deps/BUILD.bazel @@ -1,6 +1,7 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@crates//:defs.bzl", "all_crate_deps") load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc") +load("@rules_shell//shell:sh_test.bzl", "sh_test") package(default_visibility = ["//visibility:public"]) diff --git a/examples/bzlmod/all_crate_deps/MODULE.bazel b/examples/bzlmod/all_crate_deps/MODULE.bazel index abab23ade6..35b8d9e468 100644 --- a/examples/bzlmod/all_crate_deps/MODULE.bazel +++ b/examples/bzlmod/all_crate_deps/MODULE.bazel @@ -10,6 +10,10 @@ bazel_dep( name = "bazel_skylib", version = "1.7.1", ) +bazel_dep( + name = "rules_shell", + version = "0.3.0", +) bazel_dep( name = "rules_rust", version = "0.0.0", diff --git a/examples/bzlmod/cross_compile/BUILD.bazel b/examples/bzlmod/cross_compile/BUILD.bazel index b09fb4c82c..d1698036a8 100644 --- a/examples/bzlmod/cross_compile/BUILD.bazel +++ b/examples/bzlmod/cross_compile/BUILD.bazel @@ -1,4 +1,5 @@ load("@rules_rust//rust:defs.bzl", "rust_binary") +load("@rules_shell//shell:sh_test.bzl", "sh_test") package(default_visibility = ["//visibility:public"]) diff --git a/examples/bzlmod/cross_compile/MODULE.bazel b/examples/bzlmod/cross_compile/MODULE.bazel index 4e1962cc8d..6bb953d4bd 100644 --- a/examples/bzlmod/cross_compile/MODULE.bazel +++ b/examples/bzlmod/cross_compile/MODULE.bazel @@ -17,6 +17,9 @@ local_path_override( # https://github.com/bazelbuild/platforms/releases bazel_dep(name = "platforms", version = "0.0.10") +# https://github.com/bazelbuild/rules_shell/releases +bazel_dep(name = "rules_shell", version = "0.3.0") + # https://github.com/bazel-contrib/toolchains_llvm bazel_dep(name = "toolchains_llvm", version = "1.2.0", dev_dependency = True) diff --git a/examples/crate_universe_local_path/BUILD.bazel b/examples/crate_universe_local_path/BUILD.bazel index 6f156bf432..68d9d8b507 100644 --- a/examples/crate_universe_local_path/BUILD.bazel +++ b/examples/crate_universe_local_path/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") + sh_binary( name = "vendor_lazy_static_out_of_tree", srcs = ["vendor_lazy_static.sh"], diff --git a/examples/crate_universe_local_path/MODULE.bazel b/examples/crate_universe_local_path/MODULE.bazel index 33111a9d55..2aaa401a5e 100644 --- a/examples/crate_universe_local_path/MODULE.bazel +++ b/examples/crate_universe_local_path/MODULE.bazel @@ -4,6 +4,8 @@ local_path_override( path = "../..", ) +bazel_dep(name = "rules_shell", version = "0.3.0") + rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain(edition = "2021") use_repo( diff --git a/examples/ios_build/BUILD.bazel b/examples/ios_build/BUILD.bazel index 8fa89785fb..f4e8ef3b82 100644 --- a/examples/ios_build/BUILD.bazel +++ b/examples/ios_build/BUILD.bazel @@ -1,4 +1,5 @@ load("@rules_rust//rust:defs.bzl", "rust_static_library") +load("@rules_shell//shell:sh_test.bzl", "sh_test") exports_files([ "Cargo.toml", diff --git a/examples/musl_cross_compiling/BUILD.bazel b/examples/musl_cross_compiling/BUILD.bazel index d32bcb2872..9b0411b281 100644 --- a/examples/musl_cross_compiling/BUILD.bazel +++ b/examples/musl_cross_compiling/BUILD.bazel @@ -1,6 +1,7 @@ load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@rules_rust//rust:defs.bzl", "rust_binary") +load("@rules_shell//shell:sh_test.bzl", "sh_test") rust_binary( name = "hello", diff --git a/examples/sys/basic/BUILD.bazel b/examples/sys/basic/BUILD.bazel index 3c0f02fe53..dc28507871 100644 --- a/examples/sys/basic/BUILD.bazel +++ b/examples/sys/basic/BUILD.bazel @@ -13,6 +13,7 @@ # limitations under the License. load("@rules_rust//rust:defs.bzl", "rust_binary") +load("@rules_shell//shell:sh_test.bzl", "sh_test") package(default_visibility = ["//visibility:public"]) diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl index 7eb6d5bd32..bc62a7efcf 100644 --- a/rust/private/repository_utils.bzl +++ b/rust/private/repository_utils.bzl @@ -96,6 +96,8 @@ def BUILD_for_cargo(target_triple): ) _build_file_for_rustfmt_template = """\ +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") + filegroup( name = "rustfmt_bin", srcs = ["bin/rustfmt{binary_ext}"], diff --git a/rust/repositories.bzl b/rust/repositories.bzl index 3122d326e2..048bf3f011 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -85,6 +85,16 @@ def rules_rust_dependencies(): ], sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38", ) + maybe( + http_archive, + name = "rules_shell", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz", + "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz", + ], + sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53", + strip_prefix = "rules_shell-0.3.0", + ) maybe( http_archive, name = "bazel_features", diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 4566e717c3..a4ac9507e4 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") + sh_binary( name = "query_test_binary", srcs = ["query_test_binary.sh"], diff --git a/test/cc_shared_library/BUILD.bazel b/test/cc_shared_library/BUILD.bazel index e5145d6714..f23e4cba8d 100644 --- a/test/cc_shared_library/BUILD.bazel +++ b/test/cc_shared_library/BUILD.bazel @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library", "cc_test") load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_static_library") +load("@rules_shell//shell:sh_test.bzl", "sh_test") rust_static_library( name = "rust_lib", diff --git a/test/clippy/BUILD.bazel b/test/clippy/BUILD.bazel index cf74ee8b41..14d4710392 100644 --- a/test/clippy/BUILD.bazel +++ b/test/clippy/BUILD.bazel @@ -8,6 +8,7 @@ load( "rust_static_library", "rust_test", ) +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") package(default_visibility = ["//test:__subpackages__"]) diff --git a/test/empty_suite/BUILD.bazel b/test/empty_suite/BUILD.bazel index 5cda18d158..79b1607c54 100644 --- a/test/empty_suite/BUILD.bazel +++ b/test/empty_suite/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") load("//rust:defs.bzl", "rust_library", "rust_test", "rust_test_suite") # This package has a rust_test_suite containing no tests. diff --git a/test/portable_link_flags_darwin/BUILD.bazel b/test/portable_link_flags_darwin/BUILD.bazel index c883b4f6bf..32b389149b 100644 --- a/test/portable_link_flags_darwin/BUILD.bazel +++ b/test/portable_link_flags_darwin/BUILD.bazel @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") +load("@rules_shell//shell:sh_test.bzl", "sh_test") rust_library( name = "rust-lib", diff --git a/test/rust_analyzer/BUILD.bazel b/test/rust_analyzer/BUILD.bazel index 3132ee4206..ccc2990533 100644 --- a/test/rust_analyzer/BUILD.bazel +++ b/test/rust_analyzer/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") + sh_binary( name = "rust_analyzer_test", srcs = ["rust_analyzer_test_runner.sh"], diff --git a/test/rustfmt/rustfmt_integration_test_suite.bzl b/test/rustfmt/rustfmt_integration_test_suite.bzl index df3bec800e..03a197d8a3 100644 --- a/test/rustfmt/rustfmt_integration_test_suite.bzl +++ b/test/rustfmt/rustfmt_integration_test_suite.bzl @@ -8,6 +8,7 @@ load( "rust_static_library", "rustfmt_test", ) +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") _VARIANTS = { "rust_binary": rust_binary, @@ -115,7 +116,7 @@ def rustfmt_integration_test_suite(name, **kwargs): **kwargs ) - native.sh_binary( + sh_binary( name = "{}.test_runner".format(name), srcs = ["rustfmt_failure_test.sh"], testonly = True,