Skip to content

Commit

Permalink
Use rules_shell instead of built-in rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri committed Dec 12, 2024
1 parent 9cdb86c commit eec0460
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
###############################################################################
Expand Down
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
4 changes: 4 additions & 0 deletions docs/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ bazel_dep(
name = "rules_cc",
version = "0.0.17",
)
bazel_dep(
name = "rules_shell",
version = "0.3.0",
)
2 changes: 2 additions & 0 deletions examples/bazel_env/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions examples/bazel_env/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions examples/bzlmod/all_crate_deps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"])

Expand Down
4 changes: 4 additions & 0 deletions examples/bzlmod/all_crate_deps/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/bzlmod/cross_compile/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"])

Expand Down
3 changes: 3 additions & 0 deletions examples/bzlmod/cross_compile/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions examples/crate_universe_local_path/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
2 changes: 2 additions & 0 deletions examples/crate_universe_local_path/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions examples/ios_build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/musl_cross_compiling/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/sys/basic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
2 changes: 2 additions & 0 deletions rust/private/repository_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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}"],
Expand Down
10 changes: 10 additions & 0 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

sh_binary(
name = "query_test_binary",
srcs = ["query_test_binary.sh"],
Expand Down
1 change: 1 addition & 0 deletions test/cc_shared_library/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/clippy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load(
"rust_static_library",
"rust_test",
)
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

package(default_visibility = ["//test:__subpackages__"])

Expand Down
1 change: 1 addition & 0 deletions test/empty_suite/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/portable_link_flags_darwin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions test/rust_analyzer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
3 changes: 2 additions & 1 deletion test/rustfmt/rustfmt_integration_test_suite.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load(
"rust_static_library",
"rustfmt_test",
)
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

_VARIANTS = {
"rust_binary": rust_binary,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit eec0460

Please sign in to comment.