sweetpad-dev / sweetpad

Develop Swift/iOS projects using VSCode
https://marketplace.visualstudio.com/items?itemName=sweetpad.sweetpad
MIT License
575 stars 19 forks source link

The linker specified in $LD is used, even when a specific linker is needed for the build #72

Open jp-hoehmann opened 1 week ago

jp-hoehmann commented 1 week ago

When I try to build any project using sweetpad, the build fails with an error unknown option: -XLinker from ld. Checking man, it seems that that isn't an option of ld at all, but rather an option of clang.

Environment:

Steps taken:

Observed error:

/usr/bin/ld -Xlinker -reproducible -target arm64-apple-ios18.1-simulator -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.1.sdk -O0 -L/Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -L/Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Products/Debug-iphonesimulator -F/Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -F/Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Products/Debug-iphonesimulator -filelist /Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Intermediates.noindex/hello.build/Debug-iphonesimulator/hello.build/Objects-normal/arm64/hello.LinkFileList -install_name @rpath/hello.debug.dylib -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Intermediates.noindex/hello.build/Debug-iphonesimulator/hello.build/Objects-normal/arm64/hello_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -Xlinker -debug_variant -fobjc-link-runtime -fprofile-instr-generate -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Intermediates.noindex/hello.build/Debug-iphonesimulator/hello.build/Objects-normal/arm64/hello.swiftmodule -Xlinker -alias -Xlinker _main -Xlinker ___debug_main_executable_dylib_entry_point -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Intermediates.noindex/hello.build/Debug-iphonesimulator/hello.build/Objects-normal/arm64/hello_dependency_info.dat -o /Users/jean-pierre/Library/Developer/Xcode/DerivedData/hello-cqxmeaanyfjkveblntpnmewtpaxd/Build/Products/Debug-iphonesimulator/hello.app/hello.debug.dylib
ld: warning: -rpath missing <path>
ld: unknown option: -Xlinker
jp-hoehmann commented 5 days ago

Digging a little bit further, the problem doesn't occur, when the LD environment variable isn't set. The above output was produced with LD=/usr/bin/ld. With LD unset, it seems to pass these arguments to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang instead.

As a workaround, LD can be unset, but this is liable to cause problems with other tools that need to know the correct linker to use when building for the system (which in the case of macOS should typically be /usr/bin/ld). If clang needs to be run as a linker instead of ld when building for iOS, I think it would be nice if Sweetpad would ignore the environment variable (which is also what XCode does).