You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On version 0.13, for example, after applying the patch and running below (removed deprecated option -Dno-autodocs and added option -freference-trace recommended by the error message).
~/.local/lib/zig/lib/std/posix.zig:5340:9: error: WASI does not support os.realpath
@compileError("WASI does not support os.realpath");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
realpathAlloc: ~/.local/lib/zig/lib/std/fs.zig:726:40
create: src/codegen/llvm.zig:913:38
create: src/Compilation.zig:1649:64
buildOutputType: src/main.zig:3213:29
main: src/main.zig:203:20
callMain: ~/.local/lib/zig/lib/std/start.zig:524:32
wasi_start: ~/.local/lib/zig/lib/std/start.zig:207:65
The text was updated successfully, but these errors were encountered:
src/introspect.zig:41:9: error: this function is unsupported on WASI
@compileError("this function is unsupported on WASI");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/introspect.zig:85:9: error: on WASI the global cache dir must be resolved with preopens
@compileError("on WASI the global cache dir must be resolved with preopens");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/std/posix.zig:145:28: error: root struct of file 'c' has no member named 'sockaddr'
pub const sockaddr = system.sockaddr;
~~~~~~^~~~~~~~~
lib/std/c.zig:1:1: note: struct declared here
const std = @import("std");
Command (change your paths to whatever matches your system): ~/release.z/zig-linux-x86_64-0.14.0-dev.311+c50f30038/zig build -Dtarget=wasm32-wasi -Doptimize=ReleaseSmall --zig-lib-dir ~/git/ziglang/zig/lib
OK, so I'll set the options as suggested, especially --zig-lib-dir to point to lib in the source directory. I did make sure to use the same version of the compiler as the source to compile itself.
Maybe this should have been posted as a question in the forums, or a feature request for an additional target in ziglang/zig-bootstrap.
eliot-akira
changed the title
Support compiling Zig compiler to wasm32-wasi target
Compiling Zig compiler to wasm32-wasi target
Jul 17, 2024
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Clone Zig and compile the compiler to
wasm32-wasi
target.git clone --recursive --depth 1 --single-branch --branch master https://github.com/ziglang/zig cd zig zig build -Dtarget=wasm32-wasi -Doptimize=ReleaseSmall -Dno-langref -Dno-lib
It results in errors.
Expected Behavior
The Zig compiler can be compiled to
wasm32-wasi
target for running in the browser.Attempts toward a solution
The closest solution I found is in the Zig Playground repo, specifically
ZIG_WASM.md
.It's a patch that allows the compilation to succeed. I'll include it below for reference.
Notably, I found the patch only works for Zig version
0.11
.Versions above
0.11
result in compile errors related toos.realpath()
. I think the following issue is related:On version
0.13
, for example, after applying the patch and running below (removed deprecated option-Dno-autodocs
and added option-freference-trace
recommended by the error message).The error:
The text was updated successfully, but these errors were encountered: