Skip to content
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

wasm incremental compilation does not handle object updates #22501

Open
Tracked by #22220
andrewrk opened this issue Jan 16, 2025 · 0 comments
Open
Tracked by #22220

wasm incremental compilation does not handle object updates #22501

andrewrk opened this issue Jan 16, 2025 · 0 comments
Labels
arch-wasm 32-bit and 64-bit WebAssembly bug Observed behavior contradicts documented or intended behavior enhancement Solving this issue will likely involve adding new logic or components to the codebase. incremental compilation Problem occurs only when reusing compiler state. linking
Milestone

Comments

@andrewrk
Copy link
Member

Zig version: 0.14.0-dev.2790+d4fe4698d

The wasm linker backend does not have a way to repeat the "prelink" phase. You can reproduce this by having a C object in the compilation and editing it during an incremental update:

build.zig:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{
        .name = "abc",
        .root_module = b.createModule(.{
            .target = b.resolveTargetQuery(.{
                .cpu_arch = .wasm32,
                .os_tag = .wasi,
            }),
            .optimize = .Debug,
        }),
        .use_llvm = false,
        .use_lld = false,
    });
    exe.addCSourceFiles(.{ .files = &.{"simple.c"} });
    exe.entry = .disabled;

    b.installArtifact(exe);
}

simple.c

int add(int a, int b) {
    return a + b;
}
andy@bark ~/t/abc [1]> zig build -fincremental --watch 
Build Summary: 3/3 steps succeeded
install success
└─ install abc success
   └─ zig build-exe abc Debug wasm32-wasi success 1s

<edit simple.c and save it>

install
└─ install abc
   └─ zig build-exe abc Debug wasm32-wasi 1 errors
error: symbol collision: add
    note: /home/andy/tmp/abc/.zig-cache/o/fd5f01759518ddb8e2561cbdbac2bbaf/simple.o: exported as (i32, i32) -> i32 here
    note: /home/andy/tmp/abc/.zig-cache/o/fd5f01759518ddb8e2561cbdbac2bbaf/simple.o: exported as (i32, i32) -> i32 here
error: 1 compilation errors
Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install abc transitive failure
   └─ zig build-exe abc Debug wasm32-wasi 1 errors

The update fails because the wasm linker has no way to repeat the prelink phase. It needs to redo all object parsing and then reconnect any references from Zcu to the newly parsed object data.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior enhancement Solving this issue will likely involve adding new logic or components to the codebase. arch-wasm 32-bit and 64-bit WebAssembly linking incremental compilation Problem occurs only when reusing compiler state. labels Jan 16, 2025
@andrewrk andrewrk added this to the 0.15.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly bug Observed behavior contradicts documented or intended behavior enhancement Solving this issue will likely involve adding new logic or components to the codebase. incremental compilation Problem occurs only when reusing compiler state. linking
Projects
None yet
Development

No branches or pull requests

1 participant