Skip to content

Conversation

@leroycep
Copy link

I also did a major refactor of the build.zig, let me know if you don't want those changes in this pull request 😅

Also, I've only tested this on linux, so I have no idea if the other backends need updating, I just made sure zig build and zig build test worked.

Links to relevant changes upstream (not including std.Build):

Relevant changes

- [remove @Fence()][#21585]
- `tv_` prefix removed from `linux.timespec` in [std.c reorganization][2]
- `linux.timerfd_create` now accepts clockid_t enum in [std.c reorganization][3]
- `linux.clockid_t` is now a non-exhaustive enum in [std.c reorganization][4]

[#21585]: ziglang/zig#21585
[2]: ziglang/zig@e8c4e79#diff-37593602824d84b26d4345c606faf7be68c398f3bd74016afdaa6ba5dc6acaafL6224-L6233
[3]: ziglang/zig@e8c4e79#diff-37593602824d84b26d4345c606faf7be68c398f3bd74016afdaa6ba5dc6acaafL1965-R1974
[4]: ziglang/zig@e8c4e79#diff-37593602824d84b26d4345c606faf7be68c398f3bd74016afdaa6ba5dc6acaafL4032-R4056
@Zorgatone
Copy link

@leroycep do you think this is the source of the error I have while trying to build libxev as a dependency here? #140

@Zorgatone
Copy link

Zorgatone commented Feb 4, 2025

I still get an error here, I can try to see if I'm able to fix it:

zig:99:18: error: expected 2 argument(s), found 1
        if (posix.clock_gettime(posix.CLOCK.MONOTONIC)) |new_time| {
            ~~~~~^~~~~~~~~~~~~~
/home/zorgatone/.zvm/master/lib/std/posix.zig:5628:5: note: function declared here
pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void {
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    init: /home/zorgatone/.cache/zig/p/1220cec72f20b6a6c382c56bc76c27a1720845fd1217f1169e2894913913f743c188/src/backend/io_uring.zig:47:26
    main: src/main.zig:4:33
    5 reference(s) hidden; use '-freference-trace=7' to see all references

@Zorgatone
Copy link

Zorgatone commented Feb 4, 2025

I still get an error here, I can try to see if I'm able to fix it:

zig:99:18: error: expected 2 argument(s), found 1
        if (posix.clock_gettime(posix.CLOCK.MONOTONIC)) |new_time| {
            ~~~~~^~~~~~~~~~~~~~
/home/zorgatone/.zvm/master/lib/std/posix.zig:5628:5: note: function declared here
pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void {
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    init: /home/zorgatone/.cache/zig/p/1220cec72f20b6a6c382c56bc76c27a1720845fd1217f1169e2894913913f743c188/src/backend/io_uring.zig:47:26
    main: src/main.zig:4:33
    5 reference(s) hidden; use '-freference-trace=7' to see all references

Actually, updating from Zig 0.14.0-dev.2989+bf6ee7cb3 to Zig 0.14.0-dev.3036+7ac110ac2 fixed the error for me

@leroycep
Copy link
Author

leroycep commented Feb 4, 2025

Yeah I updated it to latest master, unfortunately that made it incompatible with earlier versions. If you want to use an earlier version of Zig you can pin to the earlier commit.

While I'm here, relevant upstream changes:

@dadadani
Copy link

dadadani commented Feb 10, 2025

Just to be aware, this doesn't work on MacOS since the kqueue backend hasn't been changed. There is also a smaller issue that most of the darwin namespace is not published.

If it helps, I have already patched libxev in my fork to make it work with Zig 0.14.x even on MacOS. I haven't really made a pull request yet since Zig 0.14 hasn't been tagged yet

@leroycep
Copy link
Author

I might pull in your changes if that's all right. And I hope your pull request to fix the darwin namespace get's merged, otherwise libxev might have to copy paste the darwin definitions.

My philosophy for this pull request is more "put it out there so other's can find it". I figure mitchell can ignore it until then 😄

@gwenzek gwenzek mentioned this pull request Feb 13, 2025
@GrapeBaBa
Copy link

Error after upgrade 0.14.0 for a project depends on libxev.

/Users/kaichen/.cache/zig/p/libxev-0.0.0-AAAAABfSEgDSIP4pd3W1dLAxL6r1r8wARMvaZQ0FWOwt/build.zig:352:52: error: reached unreachable code
    return std.fs.path.dirname(@src().file) orelse unreachable;
                                                   ^~~~~~~~~~~
/Users/kaichen/.cache/zig/p/libxev-0.0.0-AAAAABfSEgDSIP4pd3W1dLAxL6r1r8wARMvaZQ0FWOwt/build.zig:213:58: note: called from here
    var c_dir = try std.fs.cwd().openDir(comptime thisDir() ++ "/" ++ c_dir_path, .{ .iterate = true });
                                                  ~~~~~~~^~
referenced by:
    build: /Users/kaichen/.cache/zig/p/libxev-0.0.0-AAAAABfSEgDSIP4pd3W1dLAxL6r1r8wARMvaZQ0FWOwt/build.zig:188:25
    runBuild__anon_70771: /Users/kaichen/zig/0.14.0/files/lib/std/Build.zig:2428:44

@dadadani
Copy link

dadadani commented Mar 6, 2025

Error after upgrade 0.14.0 for a project depends on libxev.

/Users/kaichen/.cache/zig/p/libxev-0.0.0-AAAAABfSEgDSIP4pd3W1dLAxL6r1r8wARMvaZQ0FWOwt/build.zig:352:52: error: reached unreachable code
    return std.fs.path.dirname(@src().file) orelse unreachable;
                                                   ^~~~~~~~~~~
/Users/kaichen/.cache/zig/p/libxev-0.0.0-AAAAABfSEgDSIP4pd3W1dLAxL6r1r8wARMvaZQ0FWOwt/build.zig:213:58: note: called from here
    var c_dir = try std.fs.cwd().openDir(comptime thisDir() ++ "/" ++ c_dir_path, .{ .iterate = true });
                                                  ~~~~~~~^~
referenced by:
    build: /Users/kaichen/.cache/zig/p/libxev-0.0.0-AAAAABfSEgDSIP4pd3W1dLAxL6r1r8wARMvaZQ0FWOwt/build.zig:188:25
    runBuild__anon_70771: /Users/kaichen/zig/0.14.0/files/lib/std/Build.zig:2428:44

If you are using this repo, it won't work because it's still targeting 0.13. Try my fork for now (linked it in an older message), it should work fine

@mitchellh
Copy link
Owner

Note I tried to get this PR working for macOS but Zig 0.14 is simply crashing on even trying to compile libxev. I haven't tested Linux I assume it's working since others report it is in this PR. That's an issue.

@leroycep
Copy link
Author

Huh, weird. I can confirm that this branch works on Linux. Building for aarch64-macos results in errors, presumably because I haven't updated any code besides the code for Linux:

~/code/libxev> zig build test -Dtarget=aarch64-macos
test
└─ run static-binding-test
   └─ zig build-exe static-binding-test Debug aarch64-macos
      └─ zig build-lib xev Debug aarch64-macos 4 errors
src/backend/kqueue.zig:1496:34: error: root source file struct 'c' has no member named 'NOTE_EXIT'
        flags: u32 = posix.system.NOTE_EXIT | posix.system.NOTE_EXITSTATUS,
                     ~~~~~~~~~~~~^~~~~~~~~~
/home/geemili/code/zig/build-master/stage3/lib/zig/std/c.zig:1:1: note: struct declared here
const std = @import("std");
^~~~~
src/backend/kqueue.zig:1659:26: error: no field named 'tv_sec' in struct 'c.timespec__struct_476'
        assert(self.next.tv_sec >= 0);
                         ^~~~~~
/home/geemili/code/zig/build-master/stage3/lib/zig/std/c.zig:112:78: note: struct declared here
    .dragonfly, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
                                                                      ~~~~~~~^~~~~~
src/watcher/async.zig:164:33: error: root source file struct 'c' has no member named 'getKernError'
            switch (posix.system.getKernError(posix.system.mach_port_allocate(
                    ~~~~~~~~~~~~^~~~~~~~~~~~~
/home/geemili/code/zig/build-master/stage3/lib/zig/std/c.zig:1:1: note: struct declared here
const std = @import("std");
^~~~~
src/watcher/async.zig:309:34: error: root source file struct 'c' has no member named 'mach_msg_header_t'
            var msg: posix.system.mach_msg_header_t = .{
                     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/home/geemili/code/zig/build-master/stage3/lib/zig/std/c.zig:1:1: note: struct declared here
const std = @import("std");
^~~~~
error: the following command failed with 4 compilation errors:
/home/geemili/code/zig/build-master/stage3/bin/zig build-lib -ODebug -target aarch64-macos -mcpu baseline -Mroot=/home/geemili/code/libxev/src/c_api.zig -lc --cache-dir /home/geemili/code/libxev/.zig-cache --global-cache-dir /home/geemili/.cache/zig --name xev -static --zig-lib-dir /home/geemili/code/zig/build-master/stage3/lib/zig/ --listen=- 
test
└─ run xev-test
   └─ zig test xev-test Debug aarch64-macos failure
error: the following command terminated unexpectedly:
/home/geemili/code/zig/build-master/stage3/bin/zig test -ODebug -target aarch64-macos -mcpu baseline -Mroot=/home/geemili/code/libxev/src/main.zig -lc --cache-dir /home/geemili/code/libxev/.zig-cache --global-cache-dir /home/geemili/.cache/zig --name xev-test --zig-lib-dir /home/geemili/code/zig/build-master/stage3/lib/zig/ --listen=- 
Build Summary: 1/7 steps succeeded; 2 failed
test transitive failure
├─ run xev-test transitive failure
│  └─ zig test xev-test Debug aarch64-macos failure
└─ run static-binding-test transitive failure
   └─ zig build-exe static-binding-test Debug aarch64-macos transitive failure
      ├─ zig build-lib xev Debug aarch64-macos 4 errors
      └─ zig build-lib xev Debug aarch64-macos (reused)
error: the following build command failed with exit code 1:
/home/geemili/code/libxev/.zig-cache/o/499a76d93a1502bcbe6ac962291d520d/build /home/geemili/code/zig/build-master/stage3/bin/zig /home/geemili/code/zig/build-master/stage3/lib/zig /home/geemili/code/libxev /home/geemili/code/libxev/.zig-cache /home/geemili/.cache/zig --seed 0x813840fd -Z44256add535867a7 test -Dtarget=aarch64-macos

@leroycep leroycep changed the title update to zig 0.14.0-dev.2952+8fa47bb90 update to zig 0.14.0 (only build.zig and Linux backends updated) Mar 10, 2025
@mitchellh
Copy link
Owner

Okay I got beyond the crash. Working on it.

@gwenzek
Copy link

gwenzek commented Mar 11, 2025

@mitchellh look into https://github.com/dadadani/libxev it builds and run on MacOs but I haven't stress tested it.

@mitchellh
Copy link
Owner

Thanks! I got macOS working last night so we're good. Working on Windows now which is close.

@mitchellh
Copy link
Owner

Got windows working. On my branch I have a broken build.zig so I have to carry those changes over from this PR or some alternate path and then I think we'll be good to go.

@dadadani
Copy link

@mitchellh since my fork has mostly everything already working with zig 0.14, do you prefer if I open a PR, or are you already ready with your branch?

@mitchellh
Copy link
Owner

Superseded by #153. I redid everything on my own (just to learn Zig 0.14 changes). I also went a different direction with the build.zig changes. Thank you!

@mitchellh mitchellh closed this Mar 11, 2025
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.

6 participants