Skip to content

fix: resolve race condition in nsld.sh with parallel linker invocations#356

Open
NathanWalker wants to merge 1 commit intomainfrom
fix/linker-race-condition
Open

fix: resolve race condition in nsld.sh with parallel linker invocations#356
NathanWalker wants to merge 1 commit intomainfrom
fix/linker-race-condition

Conversation

@NathanWalker
Copy link
Copy Markdown
Contributor

Summary

  • Fixes intermittent Invalid argument build failures on incremental iOS builds
    caused by parallel linker invocations racing on a shared Swift-Modules/ directory
  • Changes MODULES_DIR from Swift-Modules to Swift-Modules-$TARGET_ARCH so each
    architecture gets its own isolated temp directory
  • Exports the arch-specific path into HEADER_SEARCH_PATHS so the metadata generator
    still finds the module.modulemap

Context

nsld.sh is configured as both LD and LDPLUSPLUS in nativescript-build.xcconfig.
During incremental builds, Xcode may invoke the linker for multiple architectures in
parallel. The script's flow is: delete Swift-Modules/ > create it > write
module.modulemap > run metadata generator > delete Swift-Modules/ > invoke clang.

With a shared directory, a second invocation can rm -rf the directory between another
invocation's mkdir -p and printf > module.modulemap, producing an APFS EINVAL.
This most often (randomly) surfaced on non-fresh builds when Xcode parallelizes more aggressively.

Xcode can invoke nsld.sh concurrently for different architectures during
incremental builds. All invocations shared a single Swift-Modules directory,
causing EINVAL errors on APFS when one process deletes the directory while
another is writing module.modulemap.

Use per-architecture directories (Swift-Modules-$TARGET_ARCH) so parallel
invocations no longer collide. Export the arch-specific path into
HEADER_SEARCH_PATHS so the metadata generator can still locate the modulemap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant