Collect build logs

I am wondering how can we collect logs for zig build-exe hello.zig?

By default it seems there are tree like logging in my Ubuntu terminal. but which I can’t collect using zig build-exe hello.zig 2&1 | tee build.log.

The fast updating console log is fancy and convenient for experienced users, but as a newbie I’d like to check the log to learn the build process.

AFAIK this is not (easily) possilbe withbuild-exe and companions. And I also can’t check currently.

If you use build.zig (for instance after a zig init) and then do zig build test for example you can pass the --webui and optionally --time-report to see an overview.

What you are talking about isn’t logging, rather it is detailed progress reporting.

I’m not sure what you hope to learn from it, I doubt there is anything useful for a newbie.

While I hope to view logs like what we got in make V=1 or ninja -v when working on C projects, where I usually use make V=1 2>&1 | tee make.log to collect logs for review later.

@pzittlau thanks! unfortunately I got:

error(web_server): failed to listen to port 0: AddressFamilyUnsupported
error: failed to start web server: AlreadyReported
error: the following build command failed with exit code 1:
.cache/o/ab1e9b95b6421f173429fc9451b91309/build /opt/zig-0.16.0/zig /home/yf/Projects/ziglang/lib /home/yf/Projects/fmtz .cache /tmp/.cache --seed 0xac0718e1 -Zb5d734085ec609de -p . -j8 --time-report

My host have IPv6 disabled, would this be the reason?

Update: I can see reports via zig build --webui=127.0.0.1 --time-report now.

However, it isn’t like traditional make.log or ninja.log where each invocation of compiler or linker commands are logged with command line details.

Maybe this is because Zig has only one compilation unit (i.e. one compile invocation)? But even so there should be compilation and link command line details?

Also I got error when trying another sample:

error(web_server): failed to serve '/main.wasm': EndOfStream
Build Summary: 5/5 steps succeeded

Is zig build --verbose what you are looking for ? That should print every compiler invocation with full cli args.

1 Like

Did you mean below verbose log for a freshly zig init template project:

/opt/zig-0.16.0/zig build-exe -ODebug --dep bbb -Mroot=../bbb/src/main.zig -Mbbb=../bbb/src/root.zig --cache-dir .cache --global-cache-dir /tmp/.cache --name bbb --zig-lib-dir /home/yf/Projects/ziglang/lib/ --listen=-
install -C .cache/o/097d751b256725473921afb115883c52/bbb bin/bbb

Yes that’s the one

I see. it seems only output zig commands, the lld command line is missing for a sample build with .use_llvm = true added.

Yes, it only outputs zig commands, however some of these flags are passed to the linker.

I just double checked the --help output and you could pass the following flags

  --verbose-link               Enable compiler debug output for linking
  --verbose-air                Enable compiler debug output for Zig AIR
  --verbose-llvm-ir[=file]     Enable compiler debug output for LLVM IR
  --verbose-llvm-bc=[file]     Enable compiler debug output for LLVM BC
  --verbose-cimport            Enable compiler debug output for C imports
  --verbose-cc                 Enable compiler debug output for C compilation
  --verbose-llvm-cpu-features  Enable compiler debug output for LLVM CPU features

But, It seems to only print once during compilation, when using zig build with zig build-exe it always prints.
for a fresh zig init running zig build --verbose-link

zig ld -o .zig-cache/tmp/58c1069a0d1e2f80/build --entry _start -z stack-size=16777216 --image-base=16777216 --eh-frame-hdr -z now -static /home/ab/.cache/zig/o/eb560093ed853b7e308c0d7e78ad6ce6/libcompiler_rt.a

1 Like

llvm/clang and the linker(s) are built in to the zig compiler executable, there are no commands to print for them.

But there is still output you can get from flags @abdullah-b-al mentions

@vulpesx and @abdullah-b-al thanks for the information. I see the link command line now, though with weird errors:

$ zig build --build-file ../bbb/build.zig --cache-dir .cache -p . -j4  --verbose-link --verbose
ar rcs /tmp/.cache/o/3df75a6aff742b71c522f11d7a6c7eec/libcompiler_rt.a /tmp/.cache/o/3df75a6aff742b71c522f11d7a6c7eec/libcompiler_rt_zcu.o
zig ld -o .cache/tmp/8b9fb2994534f499/build --entry _start -z stack-size=16777216 --image-base=16777216 --eh-frame-hdr -z now -static /tmp/.cache/o/3df75a6aff742b71c522f11d7a6c7eec/libcompiler_rt.a
/opt/zig-0.16.0/zig build-exe -ODebug --dep bbb -Mroot=../bbb/src/main.zig -Mbbb=../bbb/src/root.zig --verbose-link --cache-dir .cache --global-cache-dir /tmp/.cache --name bbb --zig-lib-dir /opt/zig-0.16.0/lib/ --listen=-
install
└─ install bbb
   └─ compile exe bbb Debug native failure
error: zig ld -o .cache/tmp/7d1bf849038e9f12/bbb --entry _start -z stack-size=16777216 --image-base=16777216 --eh-frame-hdr -z now -static /tmp/.cache/o/3df75a6aff742b71c522f11d7a6c7eec/libcompiler_rt.a
       
failed command: /opt/zig-0.16.0/zig build-exe -ODebug --dep bbb -Mroot=../bbb/src/main.zig -Mbbb=../bbb/src/root.zig --verbose-link --cache-dir .cache --global-cache-dir /tmp/.cache --name bbb --zig-lib-dir /opt/zig-0.16.0/lib/ --listen=-

install -C .cache/o/c4b063ea45122fefb1b0bcd8a1c4d11e/bbb bin/bbb

The final artifact bin/bbb does exist and works.