Skip to content

wasm incremental compilation does not handle object updates #22501

Closed as not planned

Description

@andrewrk

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.

Activity

  1. added
    bug
    enhancement
    arch-wasm
    incremental compilation
    on Jan 16, 2025
  2. added this to the 0.15.0 milestone on Jan 16, 2025
  3. mlugg commented on Apr 26, 2026

    @mlugg
    Member

    Superseded by https://codeberg.org/ziglang/zig/issues/32081 (which instead suggests handling this in the frontend for now so that linkers need not worry about link inputs changing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmbugenhancementincremental compilationlinking

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions