ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.94k stars 2.55k forks source link

Link warning does not fail the build and is not shown on subsequent builds #21416

Open pfgithub opened 2 months ago

pfgithub commented 2 months ago

Zig Version

0.14.0-dev.1570+8ddce90e6

Steps to Reproduce and Observed Behavior

// a.zig
export fn add(a: i32, b: i32) i32 {
    return a + b;
}
// b.zig
extern fn add(a: i32) i32;

test "add" {
    try @import("std").testing.expectEqual(@as(i32, 5), add(5));
}
// build.zig
const std = @import("std");

pub fn build(b: *std.Build) !void {
    const optimize = b.standardOptimizeOption(.{});
    const obj = b.addObject(.{
        .name = "a",
        .root_source_file = b.path("a.zig"),
        .target = b.resolveTargetQuery(try std.Build.parseTargetQuery(.{.arch_os_abi = "wasm32-freestanding"})),
        .optimize = optimize,
    });
    const test_exe = b.addTest(.{
        .root_source_file = b.path("b.zig"),
        .target = b.resolveTargetQuery(try std.Build.parseTargetQuery(.{.arch_os_abi = "wasm32-wasi-musl"})),
        .optimize = optimize,
    });
    test_exe.addObject(obj);
    b.installArtifact(test_exe);
}

Run zig build once. Note the warning:

$> zig build
install
└─ install test
   └─ zig test Debug wasm32-wasi-musl failure
error: warning(link): unexpected LLD stderr:
wasm-ld: warning: function signature mismatch: add
>>> defined as (i32) -> i32 in test.wasm.o
>>> defined as (i32, i32) -> i32 in a.o
$> echo $?
0

Run zig build again. No output.

$> zig build
$> echo $?
0

Expected Behavior

The first build should have failed, or at minimum the error message should be cached and subsequent builds should display the same error.

pfgithub commented 1 month ago

Maybe it should not fail the build because some other link warnings don't seem to cause any problems, but it should show on every build.

This seemingly causes no problems:

error: warning(link): unexpected LLD stderr:
ld.lld: warning: libzdawn.a: archive member 'libdawn.a' is neither ET_REL nor LLVM bitcode