Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions e2e/workspace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
7 changes: 6 additions & 1 deletion e2e/workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
1 change: 1 addition & 0 deletions e2e/workspace/zig_version.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.10.1
21 changes: 1 addition & 20 deletions zig/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions zig/private/versions.bzl
Original file line number Diff line number Diff line change
@@ -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=",
},
}
13 changes: 6 additions & 7 deletions zig/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}),
)
"""
Expand Down
8 changes: 3 additions & 5 deletions zig/tests/versions_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)