Skip to content

Zig 0.14.0 fails to compile hello world on WSL 1 #23153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Glavo opened this issue Mar 9, 2025 · 5 comments
Open

Zig 0.14.0 fails to compile hello world on WSL 1 #23153

Glavo opened this issue Mar 9, 2025 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@Glavo
Copy link

Glavo commented Mar 9, 2025

Zig Version

0.15.0-dev.10+214750fcf

Steps to Reproduce and Observed Behavior

I'm using the following environment:

                             ....              glavo@glavo-desktop
              .',:clooo:  .:looooo:.           -------------------
           .;looooooooc  .oooooooooo'          OS: Ubuntu 24.04.1 LTS x86_64
        .;looooool:,''.  :ooooooooooc          Host: Windows Subsystem for Linux - Ubuntu-24.04 (2.4.12)
       ;looool;.         'oooooooooo,          Kernel: Linux 4.4.0-26100-Microsoft
      ;clool'             .cooooooc.  ,,       Uptime: 8 hours, 47 mins
         ...                ......  .:oo,      Packages: 1124 (dpkg)
  .;clol:,.                        .loooo'     Shell: fish 3.7.0
 :ooooooooo,                        'ooool     Theme: Yaru [GTK3]
'ooooooooooo.                        loooo.    Icons: Yaru [GTK3]
'ooooooooool                         coooo.    Cursor: Adwaita
 ,loooooooc.                        .loooo.    Terminal: Windows Terminal
   .,;;;'.                          ;ooooc     CPU: 12th Gen Intel(R) Core(TM) i7-12700K (20) @ 4.80 GHz
       ...                         ,ooool.     GPU: Mesa llvmpipe (LLVM 19.1.1, 256 bits)
    .cooooc.              ..',,'.  .cooo.      Memory: 42.16 GiB / 63.78 GiB (66%)
      ;ooooo:.           ;oooooooc.  :l.       Swap: 206.18 MiB / 192.00 GiB (0%)
       .coooooc,..      coooooooooo.           Disk (/): 1.13 TiB / 1.82 TiB (62%) - wslfs
         .:ooooooolc:. .ooooooooooo'           Local IP (eth2): 192.168.31.37/24
           .':loooooo;  ,oooooooooc            Battery: 100% [Charging, AC Connected]
               ..';::c'  .;loooo:'             Locale: C.UTF-8

zig 0.13.0 works fine for me, but zig 0.14.0/0.15.0-dev.10+214750fcf can't compile or run anything even Hello World:

> cat main.zig
const std = @import("std");
pub fn main() !void {
    std.debug.print("Hello, World!\n", .{});
}

> /opt/zig-linux-x86_64-0.13.0/zig run main.zig
Hello, World!
> /opt/zig-linux-x86_64-0.14.0/zig run main.zig
error: unable to write '/home/glavo/.cache/zig/b/a2647189139b29c40a1c6df6248e388bbuiltin.zig': Unexpected
error: sub-compilation of compiler_rt failed
    note: failed to check cache: '/opt/zig-linux-x86_64-0.14.0/lib/compiler_rt.zig' file_hash Unexpected
error: unable to load '/opt/zig-linux-x86_64-0.14.0/lib/std/std.zig': Unexpected
error: unable to load '/opt/zig-linux-x86_64-0.14.0/lib/ubsan_rt.zig': Unexpected
> /opt/zig-linux-x86_64-0.15.0-dev.10+214750fcf/zig run main.zig
error: unable to write '/home/glavo/.cache/zig/b/14048194837c7e803a6d83848568e205builtin.zig': Unexpected
error: sub-compilation of compiler_rt failed
    note: failed to check cache: '/opt/zig-linux-x86_64-0.15.0-dev.10+214750fcf/lib/compiler_rt.zig' file_hash Unexpected
error: unable to load '/opt/zig-linux-x86_64-0.15.0-dev.10+214750fcf/lib/std/std.zig': Unexpected
error: unable to load '/opt/zig-linux-x86_64-0.15.0-dev.10+214750fcf/lib/ubsan_rt.zig': Unexpected

Expected Behavior

Compile normally

@Glavo Glavo added the bug Observed behavior contradicts documented or intended behavior label Mar 9, 2025
@alexrp
Copy link
Member

alexrp commented Mar 9, 2025

In Zig 0.13.0, we formally required kernel version 4.19+, but didn't actually make use of any syscalls from that version.

In Zig 0.14.0, we started actually using newer syscalls, e.g. statx. It's quite possible that's what you're hitting here.

It is very unlikely that we'll make any effort to support WSL 1 since it's emulating a very old kernel version, and it isn't even a 'real' Linux kernel underneath. Is there a reason you aren't just using WSL 2?

@Glavo
Copy link
Author

Glavo commented Mar 9, 2025

It is very unlikely that we'll make any effort to support WSL 1 since it's emulating a very old kernel version, and it isn't even a 'real' Linux kernel underneath. Is there a reason you aren't just using WSL 2?

For me, WSL is a Linux environment that can conveniently share a file system with Windows.

Unfortunately, WSL 2 is terrible for this purpose because accessing the Windows file system in WSL2 is incredibly slow. When I tried to migrate from WSL 1 to WSL 2, the time to compile the same project increased from about two minutes to two hours and a quarter, so I had to go back to WSL 1.

@hclarke
Copy link

hclarke commented May 1, 2025

accessing the Windows file system in WSL2 is incredibly slow

this works much better the other way: keep files on the WSL2 side, and have windows programs access the linux filesystem

there's still an overhead, but it's rare for a windows program to access that many files, so it tends to be less of a problem in practice

@Glavo
Copy link
Author

Glavo commented May 1, 2025

this works much better the other way: keep files on the WSL2 side, and have windows programs access the linux filesystem

there's still an overhead, but it's rare for a windows program to access that many files, so it tends to be less of a problem in practice

I know this, but it doesn't make sense to me.

The only reason I use WSL is so I can use the Linux toolchain to work with files in the Windows file system. For other purposes, I use the Linux physical machine in the intranet directly. Accessing files in the WSL2 file system from Windows is no more convenient than accessing files on other devices via Samba.

@jiacai2050
Copy link
Contributor

In Zig 0.14.0, we started actually using newer syscalls, e.g. statx. It's quite possible that's what you're hitting here.

Maybe we can do version check in debug mode?

The error above is quite confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

5 participants