Skip to content

Commit b7d4225

Browse files
committed
fix: resolve race condition in nsld.sh with parallel linker invocations
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.
1 parent 17ed63a commit b7d4225

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

  • project-template-ios/internal
  • project-template-vision/internal

project-template-ios/internal/nsld.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/usr/bin/env bash
22
source ./.build_env_vars.sh
33

4-
MODULES_DIR="$SRCROOT/internal/Swift-Modules"
5-
6-
function DELETE_SWIFT_MODULES_DIR() {
7-
rm -rf "$MODULES_DIR"
8-
}
9-
104
function getArch() {
115
while [[ $# -gt 0 ]]
126
do
@@ -24,6 +18,16 @@ function getArch() {
2418
done
2519
}
2620

21+
# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
22+
TARGET_ARCH=$(getArch "$@")
23+
24+
# Use per-architecture directory to avoid race conditions with parallel linker invocations
25+
MODULES_DIR="$SRCROOT/internal/Swift-Modules-$TARGET_ARCH"
26+
27+
function DELETE_SWIFT_MODULES_DIR() {
28+
rm -rf "$MODULES_DIR"
29+
}
30+
2731
function GEN_MODULEMAP() {
2832
ARCH_ARG=$1
2933
SWIFT_HEADER_DIR=$PER_VARIANT_OBJECT_FILE_DIR/$ARCH_ARG
@@ -52,9 +56,8 @@ function GEN_METADATA() {
5256
popd
5357
}
5458

55-
# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
56-
TARGET_ARCH=$(getArch "$@")
5759
GEN_MODULEMAP $TARGET_ARCH
60+
export HEADER_SEARCH_PATHS="$HEADER_SEARCH_PATHS $MODULES_DIR"
5861
printf "Generating metadata..."
5962
GEN_METADATA $TARGET_ARCH
6063
DELETE_SWIFT_MODULES_DIR

project-template-vision/internal/nsld.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/usr/bin/env bash
22
source ./.build_env_vars.sh
33

4-
MODULES_DIR="$SRCROOT/internal/Swift-Modules"
5-
6-
function DELETE_SWIFT_MODULES_DIR() {
7-
rm -rf "$MODULES_DIR"
8-
}
9-
104
function getArch() {
115
while [[ $# -gt 0 ]]
126
do
@@ -24,6 +18,16 @@ function getArch() {
2418
done
2519
}
2620

21+
# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
22+
TARGET_ARCH=$(getArch "$@")
23+
24+
# Use per-architecture directory to avoid race conditions with parallel linker invocations
25+
MODULES_DIR="$SRCROOT/internal/Swift-Modules-$TARGET_ARCH"
26+
27+
function DELETE_SWIFT_MODULES_DIR() {
28+
rm -rf "$MODULES_DIR"
29+
}
30+
2731
function GEN_MODULEMAP() {
2832
ARCH_ARG=$1
2933
SWIFT_HEADER_DIR=$PER_VARIANT_OBJECT_FILE_DIR/$ARCH_ARG
@@ -52,9 +56,8 @@ function GEN_METADATA() {
5256
popd
5357
}
5458

55-
# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
56-
TARGET_ARCH=$(getArch "$@")
5759
GEN_MODULEMAP $TARGET_ARCH
60+
export HEADER_SEARCH_PATHS="$HEADER_SEARCH_PATHS $MODULES_DIR"
5861
printf "Generating metadata..."
5962
GEN_METADATA $TARGET_ARCH
6063
DELETE_SWIFT_MODULES_DIR

0 commit comments

Comments
 (0)