diff --git a/WORKSPACE b/WORKSPACE index cf0a495c..e919abb4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -13,10 +13,9 @@ load("//zig:repositories.bzl", "rules_zig_dependencies", "zig_register_toolchain # Fetch dependencies which users need as well rules_zig_dependencies() -# TODO[AH] Zig version zig_register_toolchains( - name = "zig1_14", - zig_version = "1.14.2", + name = "zig", + zig_version = "0.10.1", ) # For running our own unit tests diff --git a/e2e/workspace/BUILD b/e2e/workspace/BUILD index 3d0e0b67..f9dd1bcb 100644 --- a/e2e/workspace/BUILD +++ b/e2e/workspace/BUILD @@ -3,15 +3,30 @@ Add a basic smoke-test target below. """ load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") # load("rules_zig//zig:defs.bzl", "...") # Replace with a usage of your rule/macro filegroup(name = "empty") +genrule( + name = "zig_version", + outs = ["zig_version.actual"], + cmd = "$(ZIG_BIN) version > $(OUTS)", + toolchains = ["@zig_toolchains//:resolved_toolchain"], +) + build_test( name = "smoke_test", targets = [ # targets you add above ":empty", + ":zig_version", ], ) + +diff_test( + name = "zig_version_test", + file1 = ":zig_version.expected", + file2 = ":zig_version.actual", +) diff --git a/e2e/workspace/WORKSPACE b/e2e/workspace/WORKSPACE index bd4ebbf1..172dd1a7 100644 --- a/e2e/workspace/WORKSPACE +++ b/e2e/workspace/WORKSPACE @@ -14,6 +14,11 @@ local_repository( # you should fetch it *before* calling this. # Alternatively, you can skip calling this function, so long as you've # already fetched all the dependencies. -load("@rules_zig//zig:repositories.bzl", "rules_zig_dependencies") +load("@rules_zig//zig:repositories.bzl", "rules_zig_dependencies", "zig_register_toolchains") rules_zig_dependencies() + +zig_register_toolchains( + name = "zig", + zig_version = "0.10.1", +) diff --git a/e2e/workspace/zig_version.expected b/e2e/workspace/zig_version.expected new file mode 100644 index 00000000..57121573 --- /dev/null +++ b/e2e/workspace/zig_version.expected @@ -0,0 +1 @@ +0.10.1 diff --git a/zig/private/toolchains_repo.bzl b/zig/private/toolchains_repo.bzl index 7a6d58c1..9e075927 100644 --- a/zig/private/toolchains_repo.bzl +++ b/zig/private/toolchains_repo.bzl @@ -20,31 +20,12 @@ with only the toolchain attribute pointing into the platform-specific repositori # Add more platforms as needed to mirror all the binaries # published by the upstream project. PLATFORMS = { - # TODO[AH] Zig platforms - "x86_64-apple-darwin": struct( - compatible_with = [ - "@platforms//os:macos", - "@platforms//cpu:x86_64", - ], - ), - "aarch64-apple-darwin": struct( - compatible_with = [ - "@platforms//os:macos", - "@platforms//cpu:aarch64", - ], - ), - "x86_64-unknown-linux-gnu": struct( + "x86_64-linux": struct( compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], ), - "x86_64-pc-windows-msvc": struct( - compatible_with = [ - "@platforms//os:windows", - "@platforms//cpu:x86_64", - ], - ), } def _toolchains_repo_impl(repository_ctx): diff --git a/zig/private/versions.bzl b/zig/private/versions.bzl index 7f6c5bdc..8c658fda 100644 --- a/zig/private/versions.bzl +++ b/zig/private/versions.bzl @@ -1,14 +1,11 @@ """Mirror of release info -TODO: generate this file from GitHub API""" +TODO[AH]: generate this file from https://ziglang.org/download/index.json""" # The integrity hashes can be computed with # shasum -b -a 384 [downloaded file] | awk '{ print $1 }' | xxd -r -p | base64 TOOL_VERSIONS = { - "1.14.2": { - "x86_64-apple-darwin": "sha384-ws4+rANvv0YxM1SgIBUXSG9jT8dKw83nls6R5qYkEKzPUB+viBIEozSsyq2e6i+f", - "aarch64-apple-darwin": "sha384-HcvJbxoJtGSavkGu0e7CyD00cBlmDb0TBWJ4JSaNa70zuU3N7XlMOYm3bbQcAv2U", - "x86_64-pc-windows-msvc": "sha384-35YN6TKpT0L9qyRBmq48NucvyXEtHnkeC+txf2YZmmJTmOzrAKREA74BA0EZvpar", - "x86_64-unknown-linux-gnu": "sha384-QgGOwTaetxY0h5HWCKc/3ZtBs4N/fgaaORthn7UcEv++Idm9W+ntCCZRwvBdwHPD", + "0.10.1": { + "x86_64-linux": "sha256-Zpnw5ykwgbQkKPMsnZyYOFQJS9Ff7lSJ8SxM9FGMw4A=", }, } diff --git a/zig/repositories.bzl b/zig/repositories.bzl index 13201a3e..4b3d1489 100644 --- a/zig/repositories.bzl +++ b/zig/repositories.bzl @@ -40,22 +40,21 @@ _ATTRS = { } def _zig_repo_impl(repository_ctx): - # TODO[AH] Zig download URL - url = "https://github.com/someorg/someproject/releases/download/v{0}/mylang-{1}.zip".format( - repository_ctx.attr.zig_version, - repository_ctx.attr.platform, - ) + # TODO[AH] read URLs from https://ziglang.org/download/index.json + url = "https://ziglang.org/download/0.10.1/zig-linux-x86_64-0.10.1.tar.xz" + strip_prefix = "zig-linux-x86_64-0.10.1" repository_ctx.download_and_extract( url = url, integrity = TOOL_VERSIONS[repository_ctx.attr.zig_version][repository_ctx.attr.platform], + stripPrefix = strip_prefix, ) # TODO[AH] compiler and lib files build_content = """#Generated by zig/repositories.bzl load("@rules_zig//zig:toolchain.bzl", "zig_toolchain") zig_toolchain(name = "zig_toolchain", target_tool = select({ - "@bazel_tools//src/conditions:host_windows": "mylang_tool.exe", - "//conditions:default": "mylang_tool", + "@bazel_tools//src/conditions:host_windows": "zig.exe", + "//conditions:default": "zig", }), ) """ diff --git a/zig/tests/versions_test.bzl b/zig/tests/versions_test.bzl index 70cbcaa0..63b09fcc 100644 --- a/zig/tests/versions_test.bzl +++ b/zig/tests/versions_test.bzl @@ -7,12 +7,10 @@ load("//zig/private:versions.bzl", "TOOL_VERSIONS") def _smoke_test_impl(ctx): env = unittest.begin(ctx) - asserts.equals(env, "1.14.2", TOOL_VERSIONS.keys()[0]) + asserts.equals(env, "0.10.1", TOOL_VERSIONS.keys()[0]) return unittest.end(env) -# The unittest library requires that we export the test cases as named test rules, -# but their names are arbitrary and don't appear anywhere. -_t0_test = unittest.make(_smoke_test_impl) +_smoke_test = unittest.make(_smoke_test_impl) def versions_test_suite(name): - unittest.suite(name, _t0_test) + unittest.suite(name, _smoke_test)