Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

gwenzek
Copy link
Contributor

@gwenzek gwenzek commented Jun 13, 2025

!!! This build.zig is experimental !!!
#67

It shows how to bridge Bazel and build.zig.
It requires the user to have bazel and tar installed on their machine.

Bazel is used to:

  • compile C and C++ deps into .a files.
  • call zig-translate C
  • generating Zig files
  • tarring Zig sources

build.zig finishes the work by:

  • untarring Zig sources
  • copying .a files into zig-cache
  • creating "zig modules" visible to other build.zig.

zig build test --summary all will run a lot of tests
zig build test-zml will stick to ZML test suite
zig build -Druntimes:cpu=true -Druntimes:cuda=false test will enable/disable runtimes

Caveats:

Potential follow ups:

  • The main missing is that Bazel takes care of sandboxing
    ZML executables and the PJRT runtimes and all the dependencies.
    This part has not been added to build.zig beyond mininal rPath for the the libpjrt_xxx.so,
    but for cuda you have more depedencies that would need to be sandboxed.

  • The module graph of the various protobuffers is alson a bit big,
    and if it changes it will be tedious to update. Ideally bazel should generate this graph of deps for us.

@gwenzek gwenzek requested review from Corendos and steeve and removed request for Corendos June 13, 2025 13:02
fn testFn() void {
std.debug.assert(remainingStackSize() > 2048);
// Check if the stack was already overflowed
const current = xframe();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Corendos not sure what this test is doing but it's not compiling anymore.

std.testing.refAllDecls(gguf);
std.testing.refAllDecls(nemo);
// std.testing.refAllDecls(nemo);
std.testing.refAllDecls(safetensors);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't ported the yaml deps to build.zig, but also not sure it's worth it. The nemo/yaml code doesn't compile anyway.

zml/BUILD.bazel Outdated
visibility = ["//visibility:public"],
deps = [
":posix",
":sentencepiece_model_proto",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't used

zml/BUILD.bazel Outdated
"//stdx",
"//zml/tokenizer",
"//zml/tools",
"@rules_zig//zig/lib:libc",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't used

@gwenzek gwenzek requested a review from Corendos June 13, 2025 13:05
@gwenzek gwenzek changed the title build.zig Experimental build.zig Jun 16, 2025
@gwenzek gwenzek force-pushed the gw/build.zig branch 2 times, most recently from 9c591b3 to d09a6a5 Compare June 17, 2025 15:36
fixup! add "zml_sandbox"
@gwenzek gwenzek force-pushed the gw/build.zig branch 2 times, most recently from 57364d0 to 7be70e8 Compare June 20, 2025 09:31
gwenzek added a commit that referenced this pull request Jul 15, 2025
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)
gwenzek added 7 commits July 15, 2025 17:31
allow to pass pregenerated tarball to avoid calling `bazel //zml:sources`
This help when upgrading Zig versions and ZML code is not fully ported yet,
but we want to use build.zig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant