From e7e49a614c417657c079b3c6ef326922e055ee62 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 7 Sep 2025 17:28:48 -0700 Subject: [PATCH 1/4] fix: metal toolchain is not included in Xcode 26 and can be ignored --- project-template-ios/internal/nsld.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/project-template-ios/internal/nsld.sh b/project-template-ios/internal/nsld.sh index 9b5dda3a..26e1e45d 100755 --- a/project-template-ios/internal/nsld.sh +++ b/project-template-ios/internal/nsld.sh @@ -59,4 +59,9 @@ printf "Generating metadata..." GEN_METADATA $TARGET_ARCH DELETE_SWIFT_MODULES_DIR NS_LD="${NS_LD:-"$TOOLCHAIN_DIR/usr/bin/clang"}" +# Skip linking if the resolved linker path points to a transient Metal.xctoolchain +if [[ "$NS_LD" == *"Metal.xctoolchain"* ]]; then + echo "NSLD: Skipping link because NS_LD resolves to a Metal.xctoolchain: $NS_LD" + exit 0 +fi $NS_LD "$@" From a5d265dee0d63d66bbbf0191035b6c975ad6a573 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 7 Sep 2025 17:44:12 -0700 Subject: [PATCH 2/4] fix: link if clang path is found otherwise skip and log that it was skipped with directory --- project-template-ios/internal/nsld.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/project-template-ios/internal/nsld.sh b/project-template-ios/internal/nsld.sh index 26e1e45d..417b87a0 100755 --- a/project-template-ios/internal/nsld.sh +++ b/project-template-ios/internal/nsld.sh @@ -58,10 +58,22 @@ GEN_MODULEMAP $TARGET_ARCH printf "Generating metadata..." GEN_METADATA $TARGET_ARCH DELETE_SWIFT_MODULES_DIR -NS_LD="${NS_LD:-"$TOOLCHAIN_DIR/usr/bin/clang"}" -# Skip linking if the resolved linker path points to a transient Metal.xctoolchain -if [[ "$NS_LD" == *"Metal.xctoolchain"* ]]; then - echo "NSLD: Skipping link because NS_LD resolves to a Metal.xctoolchain: $NS_LD" + +# Resolve linker: prefer provided NS_LD, otherwise use toolchain clang if present. +DEFAULT_LD="$TOOLCHAIN_DIR/usr/bin/clang" +if [[ -z "$NS_LD" ]]; then + if [[ -x "$DEFAULT_LD" ]]; then + NS_LD="$DEFAULT_LD" + else + echo "NSLD: Skipping link because toolchain clang not found: $DEFAULT_LD (TOOLCHAIN_DIR may be missing)." + exit 0 + fi +fi + +# If NS_LD was explicitly set to the default path but it's missing, skip as well. +if [[ "$NS_LD" == "$DEFAULT_LD" && ! -x "$NS_LD" ]]; then + echo "NSLD: Skipping link because toolchain clang not found: $NS_LD (TOOLCHAIN_DIR may be missing)." exit 0 fi -$NS_LD "$@" + +"$NS_LD" "$@" From 08811e657a2fb08f2d20eb98510d42d0d58308cf Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 7 Sep 2025 20:30:47 -0700 Subject: [PATCH 3/4] chore: cleanup Removed early exit on missing toolchain clang and added execution of NS_LD. --- project-template-ios/internal/nsld.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/project-template-ios/internal/nsld.sh b/project-template-ios/internal/nsld.sh index 417b87a0..048566c4 100755 --- a/project-template-ios/internal/nsld.sh +++ b/project-template-ios/internal/nsld.sh @@ -66,14 +66,12 @@ if [[ -z "$NS_LD" ]]; then NS_LD="$DEFAULT_LD" else echo "NSLD: Skipping link because toolchain clang not found: $DEFAULT_LD (TOOLCHAIN_DIR may be missing)." - exit 0 fi fi # If NS_LD was explicitly set to the default path but it's missing, skip as well. if [[ "$NS_LD" == "$DEFAULT_LD" && ! -x "$NS_LD" ]]; then echo "NSLD: Skipping link because toolchain clang not found: $NS_LD (TOOLCHAIN_DIR may be missing)." - exit 0 +else + "$NS_LD" "$@" fi - -"$NS_LD" "$@" From bf2bbedb5b920051ad83d61e6ce90693c20bd7d5 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 7 Sep 2025 21:59:17 -0700 Subject: [PATCH 4/4] feat: improve NSLD script to resolve clang paths --- project-template-ios/internal/nsld.sh | 63 +++++++++++++++++++++------ 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/project-template-ios/internal/nsld.sh b/project-template-ios/internal/nsld.sh index 048566c4..04cd96a5 100755 --- a/project-template-ios/internal/nsld.sh +++ b/project-template-ios/internal/nsld.sh @@ -59,19 +59,56 @@ printf "Generating metadata..." GEN_METADATA $TARGET_ARCH DELETE_SWIFT_MODULES_DIR -# Resolve linker: prefer provided NS_LD, otherwise use toolchain clang if present. -DEFAULT_LD="$TOOLCHAIN_DIR/usr/bin/clang" -if [[ -z "$NS_LD" ]]; then - if [[ -x "$DEFAULT_LD" ]]; then - NS_LD="$DEFAULT_LD" - else - echo "NSLD: Skipping link because toolchain clang not found: $DEFAULT_LD (TOOLCHAIN_DIR may be missing)." +function resolve_clang() { + # 1) If NS_LD is set and executable, honor it. + if [[ -n "$NS_LD" && -x "$NS_LD" ]]; then + echo "$NS_LD" + return 0 + fi + + # 2) TOOLCHAIN_DIR (if provided) + if [[ -n "$TOOLCHAIN_DIR" && -x "$TOOLCHAIN_DIR/usr/bin/clang" ]]; then + echo "$TOOLCHAIN_DIR/usr/bin/clang" + return 0 + fi + + # 3) Xcode's DT_TOOLCHAIN_DIR (provided by xcodebuild) + if [[ -n "$DT_TOOLCHAIN_DIR" && -x "$DT_TOOLCHAIN_DIR/usr/bin/clang" ]]; then + echo "$DT_TOOLCHAIN_DIR/usr/bin/clang" + return 0 + fi + + # 4) xcrun lookup (most reliable within Xcode build env) + local xcrun_clang + xcrun_clang=$(xcrun --find clang 2>/dev/null) || true + if [[ -n "$xcrun_clang" && -x "$xcrun_clang" ]]; then + echo "$xcrun_clang" + return 0 fi -fi -# If NS_LD was explicitly set to the default path but it's missing, skip as well. -if [[ "$NS_LD" == "$DEFAULT_LD" && ! -x "$NS_LD" ]]; then - echo "NSLD: Skipping link because toolchain clang not found: $NS_LD (TOOLCHAIN_DIR may be missing)." -else - "$NS_LD" "$@" + # 5) Xcode default toolchain from xcode-select + local xcode_path + xcode_path=$(xcode-select -p 2>/dev/null) || true + if [[ -n "$xcode_path" && -x "$xcode_path/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" ]]; then + echo "$xcode_path/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" + return 0 + fi + + # 6) System fallback + if [[ -x "/usr/bin/clang" ]]; then + echo "/usr/bin/clang" + return 0 + fi + + return 1 +} + +CLANG_PATH=$(resolve_clang) +if [[ -z "$CLANG_PATH" ]]; then + echo "NSLD: ERROR: Could not locate a usable clang. TOOLCHAIN_DIR='${TOOLCHAIN_DIR}' DT_TOOLCHAIN_DIR='${DT_TOOLCHAIN_DIR}'." + exit 1 fi + +# For visibility downstream, set NS_LD to the resolved path and invoke. +NS_LD="$CLANG_PATH" +"$NS_LD" "$@"