xcodebuild using Ld rather than Clang for linking

I have a strange issue with a react native project. Building the project in XCode works fine, but building at the command line throws a strange error. Specifically this invocation (where values in <..> are replaced with real values)

Code Block bash
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace <workspace name>.xcworkspace -configuration <configuration> -scheme <schema> -sdk iphonesimulator13.6


Throws this strange error when linking the application:

Code Block bash
ld: unknown option: -target


Now this seems to be because the linking step is called like this:


Code Block bash
Ld /Users/<username>/Library/Developer/Xcode/DerivedData/<project derviced data directory> normal x86_64 (in target '<target>' from project '<project>')
cd /<project direvtory>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -target x86_64-apple-ios11.0-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.6.sdk -L <list of libraries included>


What seems strange about this step is the it is using ld whereas in the build log in XCode this step is

Code Block
Ld /Users/alex/Library/Developer/Xcode/DerivedData/<project derived data directory> normal x86_64 (in target '<Target>' from project '<project>')
cd /<project directory>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-ios11.0-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.6.sdk -L <libraries>


The difference being that XCode appears to be linking using clang, whereas xcodebuild is linking using ld. Anyone any idea why this might be happening?
I'm experiencing the same issue… embedded inside a nix derivation.
Some additional information that may be pertinent:

The two projects I'm having issues with work without issue outside of a nix-shell… One builds with xcodebuild, the other with swift. In the swift package, I noticed that if arch is specified, e.g. --arch x86_64 --arch arm64, it triggers the issue, but if no arch is specified, it builds ok inside the nix-shell.
xcodebuild using Ld rather than Clang for linking
 
 
Q