-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
arch-wasm32-bit and 64-bit WebAssembly32-bit and 64-bit WebAssemblybugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavioros-wasiWebAssembly System InterfaceWebAssembly System Interface
Milestone
Description
Zig Version
0.14.0-dev.2293+6d781e095
Steps to Reproduce and Observed Behavior
build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const web_target_query = std.Target.Query{
.cpu_arch = .wasm32,
.os_tag = .wasi,
.cpu_features_add = std.Target.wasm.featureSet(&.{
.atomics,
.multivalue,
.bulk_memory,
}),
};
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "zig-cxx-wasi-lib",
.root_source_file = b.path("src/lib.zig"),
.target = b.resolveTargetQuery(web_target_query),
.optimize = optimize,
.single_threaded = false,
});
lib.linkLibCpp();
b.installArtifact(lib);
const mod = b.addModule("lib-mod", .{
.root_source_file = b.path("src/mod.zig"),
.target = b.resolveTargetQuery(web_target_query),
.optimize = optimize,
.single_threaded = false,
});
mod.linkLibrary(lib);
const exe = b.addExecutable(.{
.name = "zig-cxx-wasi-exe",
.root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(web_target_query),
.optimize = optimize,
.single_threaded = false,
});
exe.root_module.addImport("mod", mod);
b.installArtifact(exe);
}src/lib.zig
pub export fn add(a: i32, b: i32) i32 {
return a + b;
}src/mod.zig
pub extern fn add(i32, i32) i32;src/main.zig
const mod = @import("mod");
pub fn main() u8 {
return @intCast(mod.add(1, 2));
}assemble the above files and then run zig build in the directory you assembled them in.
This will output an error like:
error: wasm-ld: duplicate symbol: wasi_thread_start
note: defined in /home/mike/mvrs/zig-cxx-wasi/.zig-cache/o/a66544b7097a736565165b8f9d7ebcea/libzig-cxx-wasi-lib.a(/home/mike/mvrs/zig-cxx-wasi/.zig-cache/o/a66544b7097a736565165b8f9d7ebcea/libzig-cxx-wasi-lib.a.o)
note: defined in /home/mike/mvrs/zig-cxx-wasi/.zig-cache/o/7233252840d82cbad150a05f118d4272/zig-cxx-wasi-exe.wasm.oExpected Behavior
For the program to link with only one copy of wasm_thread_start... I think...
I'm not completely sure on the expected semantics but I'm building a lib and linking it to a module in one project, then depending upon that module in an exe in another project. But as seen here that fails.
There may be a separate problem where libcxx doesn't build for wasm32-wasm without all the threading options I've added, but it seems on my machine I can actually remove all extra wasm features and single_threading=false and you still get this error if your target is wasi
Metadata
Metadata
Assignees
Labels
arch-wasm32-bit and 64-bit WebAssembly32-bit and 64-bit WebAssemblybugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavioros-wasiWebAssembly System InterfaceWebAssembly System Interface