From 89cb003a4313b9889fdde7ef4247cd862bd4be55 Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 31 Aug 2026 10:06:10 -0400 Subject: [PATCH] refactor(bazel): extract repository rule helpers --- MODULE.bazel.lock | 2 +- bazel/BUILD | 5 ++++- bazel/rust_toolchain.bzl | 17 +++-------------- bazel/utils.bzl | 12 ++++++++++++ 4 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 bazel/utils.bzl diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index d9e5f7c..27cf8e4 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -93,7 +93,7 @@ "moduleExtensions": { "//bazel:rust_toolchain.bzl%rust": { "general": { - "bzlTransitiveDigest": "fQj9CTS2ItcWLOd4VcpBs75mepI/nRwLQOA3c7X5QG4=", + "bzlTransitiveDigest": "dVDpuhw0j4+nz6zvC0CHD8HwV8sSxepnzuFdoOftyBk=", "usagesDigest": "SQP3kWaLgKBHOdfxAvAWSUMuSfW8zC/274pBGhq2FlQ=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, diff --git a/bazel/BUILD b/bazel/BUILD index 8bdb927..6fa894b 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1 +1,4 @@ -exports_files(["rust_toolchain.bzl"]) +exports_files([ + "rust_toolchain.bzl", + "utils.bzl", +]) diff --git a/bazel/rust_toolchain.bzl b/bazel/rust_toolchain.bzl index 7077fbe..07ed507 100644 --- a/bazel/rust_toolchain.bzl +++ b/bazel/rust_toolchain.bzl @@ -1,3 +1,6 @@ +load("//bazel:utils.bzl", _execute = "execute", _require = "require") + + def _rust_repository_impl(repository_ctx): rustc = _require(repository_ctx, "rustc") rustdoc = _require(repository_ctx, "rustdoc") @@ -36,20 +39,6 @@ def _rust_repository_impl(repository_ctx): repository_ctx.file("BUILD.bazel", _build_file(host_triple, release)) -def _require(repository_ctx, executable): - path = repository_ctx.which(executable) - if path == None: - fail("{} must be available in PATH.".format(executable)) - return path - - -def _execute(repository_ctx, arguments): - result = repository_ctx.execute(arguments) - if result.return_code != 0: - fail("command failed: {}\n{}".format(" ".join(arguments), result.stderr)) - return result.stdout.strip() - - def _build_file(host_triple, release): return """ filegroup( diff --git a/bazel/utils.bzl b/bazel/utils.bzl new file mode 100644 index 0000000..ebbb8ff --- /dev/null +++ b/bazel/utils.bzl @@ -0,0 +1,12 @@ +def require(repository_ctx, executable): + path = repository_ctx.which(executable) + if path == None: + fail("{} must be available in PATH.".format(executable)) + return path + + +def execute(repository_ctx, arguments): + result = repository_ctx.execute(arguments) + if result.return_code != 0: + fail("command failed: {}\n{}".format(" ".join(arguments), result.stderr)) + return result.stdout.strip()