Unable to build since 0.14.0-dev.367+a57479afc

I’m unable to build buzz since zig 0.14.0-dev.367+a57479afc.
At first the error was the following on macOS:

error: undefined symbol: _main
    note: implicit entry/start for main executable

Now on zig 0.14.0-dev.622+a84951465, there’s simply no error message but the following build command failed with exit code 1.

I suspect this only occurs because of C dependencies (pcre2, mimalloc) I’m building along with buzz because the wasm build, which has no dependency, completes without issue.

As their is simply no trace or meaningful error message, I’m quite stuck.

Any help would be welcome

The projet: GitHub - buzz-language/buzz: 👨‍🚀 buzz, A small/lightweight statically typed scripting language
Full log of the failing build: https://0x0.st/Xfyd.txt

I tried to build buzz with zig 0.14.0-dev.656+c15755092 but the build failed.

I followed the instructions from the readme but I got an error from a missing file in pcre2:

install
└─ zig build-lib fs Debug native
   └─ zig build-lib pcre2 Debug native 1 errors
error: unable to check cache: stat file '/Users/kristoff/repros/buzz/vendors/pcre2/src/pcre2_chartables.c' failed: FileNotFound

(you might want to update build instructions to reflect that or even better follow my recommendation further down this comment)

So I went into the pcre2 directory, messed around a bit with the shell scripts in there till that file showed up.

Ater that the build encountered this error:

install
└─ zig build-lib os Debug native 1 errors
src/lib/buzz_os.zig:115:5: error: switch must handle all possibilities
    switch (err) {
    ^~~~~~
src/lib/buzz_os.zig:115:5: note: unhandled error value: 'error.ProcessAlreadyExec'
src/lib/buzz_os.zig:115:5: note: unhandled error value: 'error.InvalidProcessGroupId'
src/lib/buzz_os.zig:115:5: note: unhandled error value: 'error.ProcessNotFound'
referenced by:
    execute: src/lib/buzz_os.zig:182:25
    execute: src/lib/buzz_os.zig:153:5

Since the c dependencies are not packaged with a Zig build I assumed that cross-compilation is off the table and opted for patching the compile error.

This led me to a failure to build which turned out to be a SIGSEGV in the Zig compiler :^)

Process 38390 launched: '/Users/kristoff/zig-src/build/stage3/bin/zig' (arm64)
Process 38390 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x000000010aeba77c zig`link.MachO.writeLoadCommands + 1380
zig`link.MachO.writeLoadCommands:
->  0x10aeba77c <+1380>: ldr    w1, [x0, #0x10]
    0x10aeba780 <+1384>: add    x0, sp, #0x100
    0x10aeba784 <+1388>: mov    x2, x24
    0x10aeba788 <+1392>: bl     0x10ad1c598    ; link.MachO.Symbol.getFile
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x000000010aeba77c zig`link.MachO.writeLoadCommands + 1380
    frame #1: 0x000000010ad77720 zig`link.MachO.flushModule + 20324
    frame #2: 0x000000010abcda14 zig`Compilation.flush + 672
    frame #3: 0x000000010abd164c zig`Compilation.update + 9540
    frame #4: 0x000000010abe7b1c zig`main.updateModule + 44
    frame #5: 0x000000010ac18c30 zig`main.buildOutputType + 51300
    frame #6: 0x000000010ab5d230 zig`main + 2568
    frame #7: 0x000000018b3aa0e0 dyld`start + 2360
(lldb)

You can definitely reproduce the error if you re-run the command that failed directly, since you won’t see any output from it the first time as it was run by the build runner.

Now it would be nice to be able to offer a well-packaged reproduction to @kubkon, but man submodules are making this a huge pain in the ass.

So I did the only rational thing: nuked every. single. dotgit. directory, and committed every intermediate asset since there’s no way for me to know what’s needed or not.

@kubkon Crash in link.MachO.writeLoadCommands · Issue #20847 · ziglang/zig · GitHub

If I may add some suggestions:

  1. add a build.zig.zon to your project
  2. remove all the submodules from vendors/ and turn them all into tarballs that you depend on from your build.zig.zon (all the code that copies files around will work)
  3. have the invocation of make inside mir be run automatically by your build script as a starting point…
  4. …and then just replace that makefile with a build.zig
  5. same with pcre2 since it seems that it needs to be build first

You can find plenty of examples of how to directly depend on C/C++ repos (and how to package them for Zig) in All Your Codebase · GitHub

It’s not trivial to port some C/C++ projects to the Zig build system but man it will make your life easier when developing buzz once you do it.

Thanks for looking into it.

  • I’m not sure what that missing pcre file issue was and how you fixed it? Did you simply not init the submodules before building?
  • I don’t understand either why submodules made the reproducibility difficult since they check out a given commit?
  • I have not yet added a build.zig.zon because, last I tried, it doesn’t work behind proxy and I’m stuck behind one at work and I figured I’m not the only one
  • All C dependencies are built by my build.zig except for mir
  • I already tried to build mir with zig but the resulting would crash at runtime in mir with an equally laconic error and I’ve not managed to debug it yet: Building with zig and failing at runtime on `mir_hash_1` · Issue #373 · vnmakarov/mir · GitHub

I think I’ll start having a debug build of zig around since I figured that’s how you got that error stack trace?

Does it work if you add the flag -fno-sanitize=undefined to addCSourceFiles? This might be the enabled-by-default UBSAN detecting undefined behavior.

I did init the submodules.
I had to run the configure shell script (autogen.sh), otherwise I the Zig build would fail with the error above (ie that file was missing, since it’s generated by configuring pcre2. I’m not sure I did exactly the right thing (probably not) but it did fix the build. In any case I think that you have some files in a local checkout that are not present in the repo, can you try to see if you can build from a new clone to confirm if you can reproduce my issues or not?

It’s hard in case that you make changes, like in this case I needed to touch some files in a submodule to make the build work.

Ah that sucks, sorry no idea if that’s any better now

Thank you for letting me know, I’ll try to investigate this

the stack trace was from running in lldb, I used a release build of the compier and apparently misdiagnosed where the crash happened exactly :^) That said you don’t need a debug build of the compiler to recognize that it crashed: re-run manually the command that failed and you should see it crash.

I had to run the configure shell script (autogen.sh), otherwise I the Zig build would fail with the error above (ie that file was missing, since it’s generated by configuring pcre2.

Indeed, I might have run that script once a long time ago and forget about it. I’ll update the build instructions.

Looked into it and as documented in the linked issue, it’s an LLVM backend issue while the crash is a red-herring.