diff --git a/project-template-ios/internal/nsld.sh b/project-template-ios/internal/nsld.sh index 04cd96a5..e73c7bda 100755 --- a/project-template-ios/internal/nsld.sh +++ b/project-template-ios/internal/nsld.sh @@ -1,12 +1,6 @@ #!/usr/bin/env bash source ./.build_env_vars.sh -MODULES_DIR="$SRCROOT/internal/Swift-Modules" - -function DELETE_SWIFT_MODULES_DIR() { - rm -rf "$MODULES_DIR" -} - function getArch() { while [[ $# -gt 0 ]] do @@ -24,6 +18,21 @@ function getArch() { done } +# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments. +TARGET_ARCH=$(getArch "$@") + +if [ -z "$TARGET_ARCH" ]; then + printf '%s\n' "NSLD: Unable to determine target architecture from arguments: $*" >&2 + exit 1 +fi + +# Use per-architecture directory to avoid race conditions with parallel linker invocations +MODULES_DIR="$SRCROOT/internal/Swift-Modules-$TARGET_ARCH" + +function DELETE_SWIFT_MODULES_DIR() { + rm -rf "$MODULES_DIR" +} + function GEN_MODULEMAP() { ARCH_ARG=$1 SWIFT_HEADER_DIR=$PER_VARIANT_OBJECT_FILE_DIR/$ARCH_ARG @@ -52,9 +61,8 @@ function GEN_METADATA() { popd } -# 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\"" printf "Generating metadata..." GEN_METADATA $TARGET_ARCH DELETE_SWIFT_MODULES_DIR diff --git a/project-template-vision/internal/nsld.sh b/project-template-vision/internal/nsld.sh index 01dbdec9..e07521a8 100755 --- a/project-template-vision/internal/nsld.sh +++ b/project-template-vision/internal/nsld.sh @@ -1,12 +1,6 @@ #!/usr/bin/env bash source ./.build_env_vars.sh -MODULES_DIR="$SRCROOT/internal/Swift-Modules" - -function DELETE_SWIFT_MODULES_DIR() { - rm -rf "$MODULES_DIR" -} - function getArch() { while [[ $# -gt 0 ]] do @@ -24,6 +18,21 @@ function getArch() { done } +# Workaround for ARCH being set to `undefined_arch` here. Extract it from command line arguments. +TARGET_ARCH=$(getArch "$@") + +if [ -z "$TARGET_ARCH" ]; then + echo "NSLD: Failed to determine target architecture from arguments: $*" >&2 + exit 1 +fi + +# Use per-architecture directory to avoid race conditions with parallel linker invocations +MODULES_DIR="$SRCROOT/internal/Swift-Modules-$TARGET_ARCH" + +function DELETE_SWIFT_MODULES_DIR() { + rm -rf "$MODULES_DIR" +} + function GEN_MODULEMAP() { ARCH_ARG=$1 SWIFT_HEADER_DIR=$PER_VARIANT_OBJECT_FILE_DIR/$ARCH_ARG @@ -52,9 +61,8 @@ function GEN_METADATA() { popd } -# 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:+$HEADER_SEARCH_PATHS }\"$MODULES_DIR\"" printf "Generating metadata..." GEN_METADATA $TARGET_ARCH DELETE_SWIFT_MODULES_DIR