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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the NativeScript iOS linker wrapper (nsld.sh) to eliminate intermittent incremental-build failures caused by parallel linker invocations racing on a shared Swift-Modules/ directory.

Changes:

  • Derive TARGET_ARCH from linker CLI args and use an arch-specific MODULES_DIR (Swift-Modules-$TARGET_ARCH) to isolate parallel invocations.
  • Export the arch-specific MODULES_DIR into HEADER_SEARCH_PATHS so the metadata generator can still locate module.modulemap.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
project-template-vision/internal/nsld.sh Switch Swift modules temp dir to per-arch path and extend HEADER_SEARCH_PATHS accordingly.
project-template-ios/internal/nsld.sh Same per-arch Swift modules temp dir + HEADER_SEARCH_PATHS export for metadata generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
TARGET_ARCH=$(getArch "$@")

# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
TARGET_ARCH=$(getArch "$@")
GEN_MODULEMAP $TARGET_ARCH
export HEADER_SEARCH_PATHS="$HEADER_SEARCH_PATHS $MODULES_DIR"

# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
TARGET_ARCH=$(getArch "$@")

# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
TARGET_ARCH=$(getArch "$@")
GEN_MODULEMAP $TARGET_ARCH
export HEADER_SEARCH_PATHS="$HEADER_SEARCH_PATHS $MODULES_DIR"
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.

2 participants