ZML initializes runfiles before `main` so its loaders can locate
packaged libraries and data.
When using `-fno-llvm -fincremental` and linking with the incremental
ELF linker, declaring the registration pointer in Zig produces incorrect
`.init_array` data.
See https://codeberg.org/ziglang/zig/issues/37453
Use a C constructor on Linux and macOS so the C compiler emits the
platform-specific startup registration, while Zig exports the existing
runfiles initialization function directly.
We can revert when https://codeberg.org/ziglang/zig/issues/37453 is
fixed.
With this fix, we bypass the wrong behavior in incremental ELF linker
and get closer to ZML compliance with zig incremental using their
incremental linker.
The registration is shared by the `use_cc_common_link=true` and `false`
paths. Keep the explicit linker retention so the constructor is included
even when its object is in a static archive.
The `@patchelf` version 0.18.0 is more capable and can now construct
something like
```bash
patchelf \
--add-needed somelib.so \
--force-rpath \
--set-rpath '/home/kevin/sdk/lib' \
--rename-dynamic-symbols patched_tcc.symbols \
--output patched_tcc/furiosa-tcc \
somebinary
```
So now we do not need to spawn a shell and do all the cp, chmod, and the
successive patchelf command
Before
```bash
remove_rpath = ["some/directory"]
```
`--remove-rpath` is a flag that `Removes the entire embedded search
path` and not an individual directory
will contruct something like `patchelf --remove-rpath some/directory
patched.so` but `--remove-rpath` do not take arguments
Switch to `remove_rpath = True` to ensure something like `patchelf
--remove-rpath --output patched.so original.so` the `--remove-rpath` is
now used just after the patchelf to ensure correct usage flag placement.
Even if `exec_compatible_with = ["@platforms//os:macos"],` is removed
from `platforms/metal/BUILD.bazel`, fetching the pinned Metal toolchain
on Linux currently fails:
```
ERROR: /home/oboulant/.cache/bazel/_bazel_oboulant/4ea653214b23f6728bdb9f5b40de2f50/external/zml+/bazel/http_aea_archive.bzl:20:13: An error occurred during the fetch of repository 'zml++http_aea_archive+metal_toolchain':
Traceback (most recent call last):
File "/home/oboulant/.cache/bazel/_bazel_oboulant/4ea653214b23f6728bdb9f5b40de2f50/external/zml+/bazel/http_aea_archive.bzl", line 43, column 19, in _http_aea_archive_impl
_require_macos(rctx)
File "/home/oboulant/.cache/bazel/_bazel_oboulant/4ea653214b23f6728bdb9f5b40de2f50/external/zml+/bazel/http_aea_archive.bzl", line 20, column 13, in _require_macos
fail("http_aea_archive is macOS-only; current repository OS is %r" % rctx.os.name)
Error in fail: http_aea_archive is macOS-only; current repository OS is "linux"
```
Add checksum-pinned `ipsw` and `7-Zip` binaries for Linux x86_64.
`bazel/http_aea_archive.bzl` now selects the right binaries according to
running host. It preserves the existing macOS extraction path.
Linux ARM64 remains uncovered.
Validation:
```bash
bazel build \
# selects compiler binaries from the extracted external repository \
# filegroup defined in platforms/metal/metal_toolchain.BUILD.bazel \
@metal_toolchain//:metal_compile_tools \
# selects the compiler’s runtime files \
# filegroup also defined in platforms/metal/metal_toolchain.BUILD.bazel \
@metal_toolchain//:metal_compile_runtime \
# copies compiler binaries and runtime files into the layout consumed by ZML \
//platforms/metal:metal_toolchain \
# selects macOS ARM64 as the build target \
--platforms=//platforms:macos_arm64 \
--lockfile_mode=off
```
---------
Co-authored-by: Corentin Kerisit <corentin.kerisit@gmail.com>
in LTO, the linker would garbage collect that exported symbol since it
wouldn't be used inside the final binary
forcing it undefined via a link flag prevents it from being removed.
Introduce `zig_option` and `zig_options` rules to generate the bazel
equivalent of option modules plugged on bazel flags.
On `string` flags, if the flag has a `allowed_values`, the `string` is
converted into a `enum` in zig code.
Also, port platforms to this and remove the ugly `defines` hack to
comptime test for platforms enablement.
In the process, port `arocc` to the `zig_options`.
A few missing loads
Remove all flipped flags or deperacted flags from .bazelrc
Important:
- Keep autoload rules_cc and rules_python because XLA still has
transitive deps that are missing loads, PR in progress.
This suppresses SWIG Warning 524 in `bazel/swig.bzl`.
The custom SWIG rule intentionally parses C++ interfaces while
generating a C ABI wrapper for Zig consumption (in
[sentencepiece.zig](zml/tokenizer/sentencepiece/sentencepiece.zig)), so
this warning is expected noise from an intentional -c backend selection
rather than a build problem.
**Reproduce**
```
$ bazel build //examples/llm
[...]
SWIG:1: Warning 524: Experimental target language. Target language C specified by -c is an experimental language. See the 'Target Languages' section in the Introduction chapter of the SWIG documentation.
[...]
```
**Validation**
* Built `//examples/llm:llm` after a clean
* Confirmed Warning 524 no longer appears
* Build still succeeds without changing generated binding behavior
Update Zig compiler to 0.16.0-dev.3133+5ec8e45f3 and adjust code
for breaking standard library changes:
- Replace ArrayListUnmanaged/ArrayList init with .empty
- Switch to unmanaged AutoArrayHashMap/StringArrayHashMap
- Use debug.GeneralPurposeAllocator (renamed upstream)
- Replace std.Io.File.ReadStreamingError with error.EndOfStream
- Refactor meta.visit to use structured visitor pattern
- Fix alignment allocation in mem.bufferizeInner
Also update third-party dependencies: flashattn 0.0.6-rc8, arocc,
uucode, libvaxis, and zigimg patches.
Co-authored-by: Kevin Barre <kevin@zml.ai>
This allows setting DT_RPATH instead of DT_RUNPATH. DT_RPATH takes
precendence to LD_LIBRARY_PATH.
Sometimes LD_LIBRARY_PATH is useful, sometimes it's a pain. Using this
enables us at least to precede it.
runfiles are process-wide in space and time.
so it makes sense to keep them around
because they are bound to the process, we use the smp_allocator and
except the memory to be kept around during the lifetime of the process.
Much of the work was done by @gwenzek
Sadly we drop the torch loader in the process, to be added back later !
---------
Co-authored-by: Guillaume Wenzek <wzk@zml.ai>
The difference with other sandboxing PRs is that we also define a
trampoline PJRT so file which will prove itself useful to circumvent
PJRT version mismatch because of
https://github.com/aws-neuron/aws-neuron-sdk/issues/1095
Additionally, we artificially create a empty repository so that we can
sandbox the distroless deps inside the neuron module extension.
---------
Co-authored-by: EC2 Default User <ec2-user@ip-172-31-64-93.ec2.internal>
This is the non-controversial part of #262
It contains:
* the new `zig_srcs` helper,
* bug fix related to sources in rules_zig,
* cleanups of zml/BUILD.bazel
* test fixes in async/coro.zig (those tests weren't run in CI but now
are)
* disabled nemo and yaml models loader (don't compile anymore since
0.14.0 bump)
This PR bumps rules_zig to add command line to the zig compilation in
order to enable debug and release configs from the bazel command line
(and bazelrc).
Most notably, this is useful for passing `-mcpu` flags to Zig
(especially for SIMD support like AVX512).
While we're there, add `stdx.time.Duration.hz()` and
`stdx.math.roundeven()`.
This enables making sure versions are the same across the board.
Also, import `triton` repo for later use.
---------
Co-authored-by: Hugo Mano <hugo@zml.ai>