Hi here! I am currently learning zig, and I have a lot of joy on using it since it has rust like syntax which I kinda like but without all the hurdle of rust. After gone though the ziglings exercises and opened a project just to mess around the basic built-in data structures, the allocators and some patterns for dynamically creating some structs on heap, I decided to have a look to web assembly since I have a plan on rewriting some of my older projects in zig as a web app.
However, I have faced a build error, but neither I can understand the meaning of the error because it is deep into the standard library, nor I can find any similar problems anywhere. Let me show you the code for the details:
My application is simple, just a simple debug print in src/main.zig:
const std = @import("std");
pub fn main() !void {
std.debug.print("Hello World", .{});
}
Meanwhile, here is my build.zig file:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.abi = .none,
});
// Expose '-Doptimize=[enum]' as a command-line option.
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "main",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.entry = .disabled;
exe.rdynamic = true;
b.installArtifact(exe);
}
When I build the file directly using the following command:
zig build-exe src/main.zig -target wasm32-wasi
It works perfectly fine, and I can confirm the program works by running wasmtime.
However, sometimes, I wanna use some dependencies for the build, so I want to use the build file to build the project, but when I build the project using the command zig build
, I got the following error:
...\zig-windows-x86_64-0.13.0\lib\std\posix.zig:121:24: error: struct 'posix.system__struct_1539' has no member named 'fd_t'
pub const fd_t = system.fd_t;
Anything I have done wrong or misunderstood with the build.zig file?
Let me know if anyone want more information for the issue.