Skip to content

Optimized macOS test build fails to link: native_sdk_update_verify_* undefined #462

Description

@sepehr-safari

zig build test -Doptimize=ReleaseFast fails on macOS for an app built with addAppArtifacts, and so does the model-contract tool:

error: undefined symbol: _native_sdk_update_verify_archive
    note: referenced by appkit_host.o: -[NativeSdkAppKitHost installDownloadedUpdate:version:archiveBytes:sha256:]_block_invoke
error: undefined symbol: _native_sdk_update_verify_feed
    note: referenced by appkit_host.o: -[NativeSdkAppKitHost checkForUpdatesUserInitiated:]_block_invoke

Debug links. Seen with CLI 0.10.1, Zig 0.16.0, on an Apple Silicon Mac; the code below is as of 6b05318 on main.

build/app.zig:2614 compiles src/platform/macos/appkit_host.m into the app module, so every binary built from it carries the host, the test binary included. The two functions are export fns in src/updater/c_api.zig (:14, :82), and the only thing that references them is the comptime block at src/platform/macos/root.zig:13. That file is only analysed when something reaches native_sdk.platform.macos, which the app runner's run path does and a test binary does not. A Debug link drops the unused host object; an optimized link keeps it, and the two symbols are missing.

A fix on the toolkit side could reference the two exports from wherever appkit_host.m is added, or from the module root on macOS, so they exist in every binary that carries the host. In the meantime an app can reference them itself, which is what I do in Plaza (zig-nostr/plaza#390):

comptime {
    if (builtin.os.tag == .macos) {
        _ = native_sdk.updater.c_api.native_sdk_update_verify_feed;
        _ = native_sdk.updater.c_api.native_sdk_update_verify_archive;
    }
}

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions