Skip to content

ios: native dev --target ios fails to link — zig-built archive members not 8-byte aligned for Apple ld #428

Description

@donpark

An embed static library built by the iOS dev loop is rejected by Xcode's linker before the app can ever run: native dev --target ios fails on every TypeScript-core app at the host-compile step, with a low-level ld error about archive member alignment. The zig build lib step itself succeeds; the failure happens when the toolkit-owned UIKit host is linked against the archive it just produced.

Repro

native init demo && cd demo
native dev --target ios

Expected: the embed library builds, the UIKit host compiles and links, the app installs and launches in the simulator.

Actual:

native dev (ios): compiling the toolkit UIKit host
ld: 64-bit mach-o member 'libIdfon_zcu.o' not 8-byte aligned in '.native/embed/aarch64-ios-simulator/lib/libIdfon.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
native (ios): `xcrun` step failed

Modern ld64 requires 64-bit mach-o archive members to be 8-byte aligned; the archive zig emits doesn't guarantee that. Xcode 26.6's ld enforces it.

Workaround

Extract the members and repack with libtool before the link:

mkdir repack && cd repack
xcrun ar x ../libIdfon.a
chmod 644 *.o          # members extract with mode 000
rm -f __.SYMDEF*
xcrun libtool -static -o ../libIdfon-aligned.a *.o

Gotcha for the fix: repacking from the archive directly (libtool -static -o out.a in.a) is not equivalent — it silently drops members, and the linked app then fails with all 48 _native_sdk_app_* C-API symbols undefined. Members must be extracted first, then repacked from the individual .o files. Worth an assertion after any repack (nm -g still finds _native_sdk_app_create).

Environment

  • native 0.10.1 (064ca98), CLI reports native 0.10.1 (commit 064ca98, automation protocol 0x51f7889bbe3305e7)
  • macOS 26.6.2 (arm64), Xcode 26.6
  • Zig 0.16.0, Node v24.20.0

Notes

  • Fix lives in src/tooling/ios.zig (and the xcodeproj packaging path): repack the embed archive after buildEmbedLib, before the clang link. Cheap relative to the build.
  • The alignment failure and the UBSan failure (sibling issue) are independent — fixing one does not unblock native dev --target ios; both must be fixed for the dev loop to complete.

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