Skip to content

Commit 36d583d

Browse files
authored
workspace: use upstreamed rules_zig instead of our fork (#340)
This PR uses the new release of rules_zig where we upstreamed all the work from the zml rules_zig fork. Not much changes from the POV of the public API except for `copts` becoming `zigopts`. Also, the global `c` module is only available to Zig modules that depend on a non empty `cc_library`. This is behavior that can probably be modified in `rules_zig` later on. Finally, ZLS support had to be completely rethought to comply with the change in shape of ZigModuleInfo providers and subsequent rules. This PR is blocked until `rules_zig` exposes `ZigModuleInfo` for `zig_binaries`.
1 parent 53ad583 commit 36d583d

29 files changed

+973
-221
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ common --incompatible_enable_proto_toolchain_resolution
7676
common --incompatible_disallow_empty_glob=false
7777

7878
# Use the C linker to link Zig code
79-
common --@rules_zig//zig/settings:linkmode=cc
79+
common --@rules_zig//zig/settings:use_cc_common_link=True
8080

8181
common --@toolchains_llvm_bootstrapped//config:experimental_stub_libgcc_s=True
8282

BUILD.bazel

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
load("@rules_zig//zig:defs.bzl", "zls_completion")
2-
load("@zml//third_party/zls:zls.bzl", "zls_runner")
3-
4-
zls_runner(
5-
name = "zls",
6-
target = ":completion",
7-
)
1+
load("//third_party/zls:zls_completion.bzl", "zls_completion")
82

93
zls_completion(
104
name = "completion",

MODULE.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ bazel_dep(name = "abseil-cpp", version = "20250814.0")
66
bazel_dep(name = "aspect_bazel_lib", version = "2.20.0")
77
bazel_dep(name = "aspect_rules_py", version = "1.6.3")
88
bazel_dep(name = "bazel_skylib", version = "1.8.1")
9-
bazel_dep(name = "libxev", version = "20250718.0-9f785d2")
9+
bazel_dep(name = "libxev", version = "20251010.0-9f785d2")
1010
bazel_dep(name = "patchelf", version = "0.18.0")
1111
bazel_dep(name = "pcre2", version = "10.45")
1212
bazel_dep(name = "platforms", version = "1.0.0")
@@ -18,7 +18,7 @@ bazel_dep(name = "rules_oci", version = "2.2.6")
1818
bazel_dep(name = "rules_proto", version = "7.1.0")
1919
bazel_dep(name = "rules_python", version = "1.5.3")
2020
bazel_dep(name = "rules_rust", version = "0.63.0")
21-
bazel_dep(name = "rules_zig", version = "20250827.0-35b6d57")
21+
bazel_dep(name = "rules_zig", version = "0.12.1")
2222
bazel_dep(name = "toolchains_llvm_bootstrapped", version = "0.2.4")
2323
bazel_dep(name = "with_cfg.bzl", version = "0.11.0")
2424

@@ -92,10 +92,10 @@ use_repo(tpu, "libpjrt_tpu")
9292
neuron = use_extension("//runtimes/neuron:neuron.bzl", "neuron_packages")
9393
use_repo(neuron, "aws-neuronx-collectives", "aws-neuronx-runtime-lib", "libgomp1", "libpjrt_neuron", "zlib1g")
9494

95-
zls = use_extension("//third_party/zls:zls.bzl", "repo")
96-
use_repo(zls, "zls_aarch64-macos", "zls_x86_64-linux", "zls_x86_64-macos")
95+
zls = use_extension("//third_party/zls:zls_toolchain.bzl", "zls_toolchains")
96+
use_repo(zls, "zls_toolchains")
9797

98-
register_toolchains("//third_party/zls:all")
98+
register_toolchains("@zls_toolchains//:all")
9999

100100
non_module_deps = use_extension("//:third_party/non_module_deps.bzl", "non_module_deps")
101101
use_repo(non_module_deps, "com_github_hejsil_clap", "com_google_sentencepiece", "mnist", "org_swig_swig", "xla")

MODULE.bazel.lock

Lines changed: 235 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

async/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ zig_library(
1010
"executor.zig",
1111
"stack.zig",
1212
],
13-
copts = ["-lc"],
13+
zigopts = ["-lc"],
1414
extra_srcs = glob(["asm/*.s"]),
1515
main = "async.zig",
1616
visibility = ["//visibility:public"],

examples/mnist/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ zig_binary(
1111
"@mnist//:mnist.safetensors",
1212
"@mnist//:t10k-images.idx3-ubyte",
1313
],
14+
zigopts = ["-fllvm"],
1415
main = "mnist.zig",
1516
deps = [
1617
"//async",

runtimes/cuda/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ zig_shared_library(
55
name = "zmlxcuda",
66
# Use Clang's compiler-rt, but disable stack checking
77
# to avoid requiring on the _zig_probe_stack symbol.
8-
copts = ["-fno-stack-check", "-fllvm"],
8+
zigopts = ["-fno-stack-check", "-fllvm"],
99
main = "zmlxcuda.zig",
1010
shared_lib_name = "libzmlxcuda.so.0",
1111
visibility = ["@libpjrt_cuda//:__subpackages__"],
@@ -14,6 +14,7 @@ zig_shared_library(
1414

1515
cc_library(
1616
name = "empty",
17+
defines = ["ZML_RUNTIME_CUDA_DISABLED"],
1718
)
1819

1920
cc_library(

runtimes/neuron/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load("@zml//bazel:runfiles.bzl", "runfiles_to_default")
1111
# of neuronx-cc (see add_needed of the patchelf target below).
1212
zig_shared_library(
1313
name = "libpjrt_neuron",
14-
copts = ["-fno-stack-check"],
14+
zigopts = ["-fno-stack-check"],
1515
main = "libpjrt_neuron.zig",
1616
visibility = ["@libpjrt_neuron//:__subpackages__"],
1717
deps = [
@@ -48,6 +48,7 @@ cc_library(
4848

4949
cc_library(
5050
name = "empty",
51+
defines = ["ZML_RUNTIME_NEURON_DISABLED"],
5152
)
5253

5354
cc_library(
@@ -79,7 +80,7 @@ upb_c_proto_library(
7980

8081
zig_shared_library(
8182
name = "libneuronxla",
82-
copts = [
83+
zigopts = [
8384
"-fno-stack-check",
8485
"-fPIC",
8586
],

runtimes/rocm/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ zig_shared_library(
55
name = "zmlxrocm",
66
# Use Clang's compiler-rt, but disable stack checking
77
# to avoid requiring on the _zig_probe_stack symbol.
8-
copts = ["-fno-stack-check"],
8+
zigopts = ["-fno-stack-check"],
99
main = "zmlxrocm.zig",
1010
shared_lib_name = "libzmlxrocm.so.0",
1111
visibility = ["@libpjrt_rocm//:__subpackages__"],
@@ -24,6 +24,7 @@ alias(
2424

2525
cc_library(
2626
name = "empty",
27+
defines = ["ZML_RUNTIME_ROCM_DISABLED"],
2728
)
2829

2930
cc_library(

runtimes/tpu/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@rules_zig//zig:defs.bzl", "zig_library")
33

44
cc_library(
55
name = "empty",
6+
defines = ["ZML_RUNTIME_TPU_DISABLED"],
67
)
78

89
cc_library(

0 commit comments

Comments
 (0)