Skip to content

Commit a61d35c

Browse files
authored
fix: resolve race condition in nsld.sh with parallel linker invocations (#356)
1 parent 961dc76 commit a61d35c

File tree

2 files changed

+32
-16
lines changed
  • project-template-ios/internal
  • project-template-vision/internal

2 files changed

+32
-16
lines changed

project-template-ios/internal/nsld.sh

Lines changed: 16 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,21 @@ 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+
if [ -z "$TARGET_ARCH" ]; then
25+
printf '%s\n' "NSLD: Unable to determine target architecture from arguments: $*" >&2
26+
exit 1
27+
fi
28+
29+
# Use per-architecture directory to avoid race conditions with parallel linker invocations
30+
MODULES_DIR="$SRCROOT/internal/Swift-Modules-$TARGET_ARCH"
31+
32+
function DELETE_SWIFT_MODULES_DIR() {
33+
rm -rf "$MODULES_DIR"
34+
}
35+
2736
function GEN_MODULEMAP() {
2837
ARCH_ARG=$1
2938
SWIFT_HEADER_DIR=$PER_VARIANT_OBJECT_FILE_DIR/$ARCH_ARG
@@ -52,9 +61,8 @@ function GEN_METADATA() {
5261
popd
5362
}
5463

55-
# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
56-
TARGET_ARCH=$(getArch "$@")
5764
GEN_MODULEMAP $TARGET_ARCH
65+
export HEADER_SEARCH_PATHS="$HEADER_SEARCH_PATHS \"$MODULES_DIR\""
5866
printf "Generating metadata..."
5967
GEN_METADATA $TARGET_ARCH
6068
DELETE_SWIFT_MODULES_DIR

project-template-vision/internal/nsld.sh

Lines changed: 16 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,21 @@ 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+
if [ -z "$TARGET_ARCH" ]; then
25+
echo "NSLD: Failed to determine target architecture from arguments: $*" >&2
26+
exit 1
27+
fi
28+
29+
# Use per-architecture directory to avoid race conditions with parallel linker invocations
30+
MODULES_DIR="$SRCROOT/internal/Swift-Modules-$TARGET_ARCH"
31+
32+
function DELETE_SWIFT_MODULES_DIR() {
33+
rm -rf "$MODULES_DIR"
34+
}
35+
2736
function GEN_MODULEMAP() {
2837
ARCH_ARG=$1
2938
SWIFT_HEADER_DIR=$PER_VARIANT_OBJECT_FILE_DIR/$ARCH_ARG
@@ -52,9 +61,8 @@ function GEN_METADATA() {
5261
popd
5362
}
5463

55-
# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments.
56-
TARGET_ARCH=$(getArch "$@")
5764
GEN_MODULEMAP $TARGET_ARCH
65+
export HEADER_SEARCH_PATHS="${HEADER_SEARCH_PATHS:+$HEADER_SEARCH_PATHS }\"$MODULES_DIR\""
5866
printf "Generating metadata..."
5967
GEN_METADATA $TARGET_ARCH
6068
DELETE_SWIFT_MODULES_DIR

0 commit comments

Comments
 (0)