From 045a22052fc147d38c617aec70c77d5fdd87a5fe Mon Sep 17 00:00:00 2001 From: vardaro Date: Wed, 5 Jun 2024 10:38:48 -0700 Subject: [PATCH 1/2] Add zig_repository_cache repository rule for directing Zig compilation environment variables. --- toolchain/defs.bzl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index f6f613e..1e1ea25 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -77,6 +77,10 @@ def toolchains( mirror_format = original_format.replace("https://ziglang.org/", "https://mirror.bazel.build/ziglang.org/") url_formats = [mirror_format, original_format] + zig_repository_cache( + name = "zig_sdk_cache", + ) + zig_repository( name = "zig_sdk", version = version, @@ -147,14 +151,8 @@ def _zig_repository_impl(repository_ctx): cache_prefix = repository_ctx.os.environ.get("HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX", "") if cache_prefix == "": - if os == "windows": - cache_prefix = "C:\\\\Temp\\\\zig-cache" - elif os == "macos": - cache_prefix = "/var/tmp/zig-cache" - elif os == "linux": - cache_prefix = "/tmp/zig-cache" - else: - fail("unknown os: {}".format(os)) + label = Label("@zig_sdk_cache//:zig.env") + cache_prefix = str(repository_ctx.path(label).dirname) repository_ctx.template( "tools/zig-wrapper.zig", @@ -235,6 +233,15 @@ zig_repository = repository_rule( implementation = _zig_repository_impl, ) +def _zig_repository_cache_impl(ctx): + ctx.file("zig.env", "") + ctx.file("BUILD.bazel", 'exports_files(["zig.env"])') + +zig_repository_cache = repository_rule( + implementation = _zig_repository_cache_impl, + attrs={}, +) + def filegroup(name, **kwargs): native.filegroup(name = name, **kwargs) return ":" + name From 10ef8dce3d43345a2a6c37a91f3bdd2b44724f0d Mon Sep 17 00:00:00 2001 From: vardaro Date: Wed, 5 Jun 2024 10:49:46 -0700 Subject: [PATCH 2/2] Run buildifier --- toolchain/defs.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index 1e1ea25..0a671f9 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -239,7 +239,7 @@ def _zig_repository_cache_impl(ctx): zig_repository_cache = repository_rule( implementation = _zig_repository_cache_impl, - attrs={}, + attrs = {}, ) def filegroup(name, **kwargs):