-
Notifications
You must be signed in to change notification settings - Fork 52
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
Emscripten LTO: Linking two modules of different target triples #81
Comments
Hmm good to know but strange, I would actually have expected that MUSL is the correct C library to use (since Emscripten is also using MUSL). |
This is probably because zig ensures its self-dependencies by default. During the tests I had no complications in running the applications, only the warnings issued. (same target data-layout) |
patch changediff --git a/build.zig b/build.zig
index dd3aa67..b7a7db5 100644
--- a/build.zig
+++ b/build.zig
@@ -107,6 +107,7 @@ fn buildExample(b: *Build, comptime name: []const u8, options: ExampleOptions) !
.target = options.target,
.optimize = options.optimize,
});
+ example.want_lto = true;
example.root_module.addImport("sokol", options.mod_sokol);
// create a special emcc linker run step
@@ -120,6 +121,7 @@ fn buildExample(b: *Build, comptime name: []const u8, options: ExampleOptions) !
.use_webgl2 = backend != .wgpu,
.use_emmalloc = true,
.use_filesystem = false,
+ .release_use_lto = example.want_lto orelse false,
.shell_file_path = b.path("src/sokol/web/shell.html"),
.extra_args = &.{"-sSTACK_SIZE=512KB"},
});
@@ -171,6 +173,7 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*Build.Step.Compile {
b.installArtifact(lib);
if (options.target.result.isWasm()) {
+ lib.want_lto = true;
// make sure we're building for the wasm32-emscripten target, not wasm32-freestanding
if (lib.rootModuleTarget().os.tag != .emscripten) {
std.log.err("Please build with 'zig build -Dtarget=wasm32-emscripten", .{}); emcc 3.1.61 sokol-zig git:(master) ✗ ~/zig/master/files/zig build run-clear --summary all -Dtarget=wasm32-emscripten-none -Doptimize=ReleaseSafe
run-clear
└─ run /home/kassane/.cache/zig/p/12200ba39d83227f5de08287b043b011a2eb855cdb077f4b165edce30564ba73400e/upstream/emscripten/emrun
└─ install generated/
└─ emcc failure
wasm-ld: error: Invalid summary version 10. Version should be in the range [1-9].
wasm-ld: error: Invalid summary version 10. Version should be in the range [1-9].
wasm-ld: error: Invalid summary version 10. Version should be in the range [1-9].
wasm-ld: error: Invalid summary version 10. Version should be in the range [1-9]. emcc 3.1.71 sokol-zig git:(master) ✗ ~/zig/master/files/zig build run-clear --summary all -Dtarget=wasm32-emscripten-none -Doptimize=ReleaseSafe
run-clear
└─ run /home/kassane/.cache/zig/p/12201d024e47d97dea4d1d6024a9cf1b35ca8be8e4fa1a0ecf6ee9080e479467183a/upstream/emscripten/emrun
└─ install generated/
└─ emcc stderr
'-half-precision' is not a recognized feature for this target (ignoring feature)
'-half-precision' is not a recognized feature for this target (ignoring feature)
Now listening at http://0.0.0.0:6931/ |
Actually Zig isn't enabling LTO on release targets ( wasm32 in particular). Enabling it manually gives this warning during linking.
Similar issue in
sokol-d
: kassane/sokol-d#3 (comment)How to fix?
Replace
wasm32-emscripten
(default is musl) towasm32-emscripten-none
!# first clean .zig-cache and zig-out $ zig build run-clear -Dtarget=wasm32-emscripten-none -Doptimize=ReleaseSmall Now listening at http://0.0.0.0:6931/
The text was updated successfully, but these errors were encountered: