Having trouble compiling zig from source: IsDir error

I compiled zig using the commands from the wiki and got this:

[  5%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_llvm.cpp.o
[ 10%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_llvm-ar.cpp.o
[ 15%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang.cpp.o
[ 21%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang_driver.cpp.o
[ 26%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang_cc1_main.cpp.o
[ 31%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang_cc1as_main.cpp.o
[ 36%] Linking CXX static library zigcpp/libzigcpp.a
[ 36%] Built target zigcpp
[ 42%] Building C object CMakeFiles/zig-wasm2c.dir/stage1/wasm2c.c.o
[ 47%] Linking C executable zig-wasm2c
ld: warning: dylib (/usr/local/Cellar/llvm/17.0.2/lib/libunwind.dylib) was built for newer macOS version (12.6) than being linked (12.0)
ld: warning: dylib (/usr/local/Cellar/llvm/17.0.2/lib/libunwind.dylib) was built for newer macOS version (12.6) than being linked (12.0)
[ 47%] Built target zig-wasm2c
[ 52%] Converting /Users/justinwayland/Private/GitHub Repositories/zig/stage1/zig1.wasm to /Users/justinwayland/Private/GitHub Repositories/zig/build/zig1.c
[ 57%] Building C object CMakeFiles/zig1.dir/zig1.c.o
[ 63%] Building C object CMakeFiles/zig1.dir/stage1/wasi.c.o
[ 68%] Linking C executable zig1
ld: warning: dylib (/usr/local/Cellar/llvm/17.0.2/lib/libunwind.dylib) was built for newer macOS version (12.6) than being linked (12.0)
ld: warning: dylib (/usr/local/Cellar/llvm/17.0.2/lib/libunwind.dylib) was built for newer macOS version (12.6) than being linked (12.0)
ld: warning: dylib (/usr/local/Cellar/llvm/17.0.2/lib/libunwind.dylib) was built for newer macOS version (12.6) than being linked (12.0)
ld: warning: dylib (/usr/local/Cellar/llvm/17.0.2/lib/libunwind.dylib) was built for newer macOS version (12.6) than being linked (12.0)
[ 68%] Built target zig1
[ 73%] Running zig1.wasm to produce /Users/justinwayland/Private/GitHub Repositories/zig/build/zig2.c
error: unable to create compilation: IsDir
make[2]: *** [zig2.c] Error 1
make[1]: *** [CMakeFiles/zig2.dir/all] Error 2
make: *** [all] Error 2

What do I need to do to correct the error?

I’m on MacOS 12.7, x86-64.

That’s a rather unhelpful error message unfortunately. Sorry about that. There are a handful of file system operations in Compilation.zig in the create() function, and one of them is trying to create a file or something like that and failing because the output path already exists and is a directory.

Here are two paths forward:

  1. Start improving the create() function mentioned above to report better errors when file system operations fail. This is not really helpful to your immediate problem since the logic that needs to be fixed is inside zig1.wasm.
  2. Use a system tracing tool (on Linux it would be strace; I always forget what it is on macOS) to find out what file path is returning EISDIR. Alternately you could patch stage1/wasi.c, just change LOG_TRACE at the top of the file from 0 to 1.

From looking it up online, the strace equivalent is dtruss. Unfortunately, doing this directly on make is not permitted by system integrity protection, so that’s right out.

Anyway, the first big thing was that compiling zig using zig-bootstrap completely circumvented the error, but took about 10 hours to run due to having to compile LLVM twice.

The second big thing was that I ran the failing step using LOG_TRACE=1, and got this back:

wasi_snapshot_preview1_args_sizes_get()
wasi_snapshot_preview1_args_get()
wasi_snapshot_preview1_fd_prestat_get(3)
wasi_snapshot_preview1_fd_prestat_dir_name(3, "")
wasi_snapshot_preview1_fd_prestat_get(4)
wasi_snapshot_preview1_fd_prestat_dir_name(4, "")
wasi_snapshot_preview1_fd_prestat_get(5)
wasi_snapshot_preview1_fd_prestat_dir_name(5, "")
wasi_snapshot_preview1_fd_prestat_get(6)
wasi_snapshot_preview1_path_open(3, 0x1, "/Users/justinwayland/Private/GitHub Repositories/zig/build", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 6
wasi_snapshot_preview1_path_open(3, 0x1, "deps/aro", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 7
wasi_snapshot_preview1_path_open(3, 0x1, "/Users/justinwayland/Private/GitHub\ Repositories/zig/build", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 8
wasi_snapshot_preview1_path_open(3, 0x1, "src", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 9
wasi_snapshot_preview1_path_filestat_get(3, 0x1, "./build.zig")
wasi_snapshot_preview1_path_create_directory(4, "h")
wasi_snapshot_preview1_path_open(4, 0x1, "h", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 10
wasi_snapshot_preview1_path_create_directory(4, "o/56b8763260b3ff0a7aacd4000aaeca2a")
wasi_snapshot_preview1_path_open(4, 0x1, "o/56b8763260b3ff0a7aacd4000aaeca2a", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 11
wasi_snapshot_preview1_path_open(5, 0x1, "std", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 12
wasi_snapshot_preview1_path_create_directory(4, "z")
wasi_snapshot_preview1_path_open(4, 0x1, "z", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 13
wasi_snapshot_preview1_path_create_directory(4, "z")
wasi_snapshot_preview1_path_open(4, 0x1, "z", 0x2, 0x7BFFE08, 0x2FFFFFFF, 0x0)
fd = 14
wasi_snapshot_preview1_path_open(8, 0x0, "zig2.c", 0x1, 0xE001FD, 0x0, 0x0)
wasi_snapshot_preview1_fd_close(12)
wasi_snapshot_preview1_fd_close(11)
wasi_snapshot_preview1_fd_close(13)
wasi_snapshot_preview1_fd_close(14)
wasi_snapshot_preview1_fd_close(10)
wasi_snapshot_preview1_fd_write(2, 0x1FFC684, 1)
error: unable to create compilation: wasi_snapshot_preview1_fd_write(2, 0x1FFC654, 1)
IsDirwasi_snapshot_preview1_fd_write(2, 0x1FFC684, 1)

wasi_snapshot_preview1_proc_exit(1)

Does any of this indicate something to you?

Edit: When looking through the make files generated by CMake under zig2.dir, I noticed two problematic lines.
The first, under zig2.c’s definition:

cd "/Users/justinwayland/Private/GitHub Repositories/zig" && "/Users/justinwayland/Private/GitHub Repositories/zig/build/zig1" /Users/justinwayland/Private/GitHub\ Repositories/zig/lib build-exe src/main.zig -ofmt=c -lc -OReleaseSmall --name zig2 -femit-bin="/Users/justinwayland/Private/GitHub\ Repositories/zig/build/zig2.c" --mod build_options::/Users/justinwayland/Private/GitHub\ Repositories/zig/build/config.zig --mod aro::deps/aro/lib.zig --deps build_options,aro -target x86_64-macos

The second, under compiler_rt.c’s defintion:

cd "/Users/justinwayland/Private/GitHub Repositories/zig" && "/Users/justinwayland/Private/GitHub Repositories/zig/build/zig1" /Users/justinwayland/Private/GitHub\ Repositories/zig/lib build-obj lib/compiler_rt.zig -ofmt=c -OReleaseSmall --name compiler_rt -femit-bin="/Users/justinwayland/Private/GitHub\ Repositories/zig/build/compiler_rt.c" --mod build_options::/Users/justinwayland/Private/GitHub\ Repositories/zig/build/config.zig --deps build_options -target x86_64-macos

In particular I am going to highlight what femit-bin is targeting under the first command:

-femit-bin="/Users/justinwayland/Private/GitHub\ Repositories/zig/build/zig2.c"

It seems that the way CMake currently generates makefiles doesn’t handle spaces in the absolute pathname very well.

Edit 2: Yeah, removing the space and refreshing the cmake files fixed the problem.

3 Likes

Nice find. Thanks for reporting the issue!

1 Like