Open franklyonnet opened 1 year ago
I have the same exact problem, nothing seems to make -target work. Did you have to put the package in a specific directory of the xcodeproject?
The problem here lies within the swift package manager, good thread here
I don't understand much of what is going on here - would one of you mind creating a reproduction repo?
If I'm not mistaken, isn't SwiftLinker
creating the correct build command?
swift build
-c release
--build-path "/Users/flyonnet/Library/Developer/Xcode/DerivedData/Runner-gyjydghdoilsppddiyqqpyifgfkp/Build/Intermediates.noindex/edamame_core.build/cargo_target/aarch64-apple-ios/release/build/edamame_core-7be057f67cfcb7b2/out/swift-rs/EdamameNative"
-Xswiftc "-sdk"
-Xswiftc "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk"
-Xswiftc "-target"
-Xswiftc "aarch64-apple-ios"
It seems like Xcode is producing the wrong target:
swiftc
-vfsoverlay "/var/folders/s9/vlddfbs96d12sz5jgrhg3js40000gn/T/TemporaryDirectory.XDdAsN/vfs.yaml"
-L "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI"
-lPackageDescription
-Xlinker "-rpath"
-Xlinker "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI"
-target "arm64-apple-macosx12.0"
-sdk "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk"
-F "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks"
-I "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib"
-L "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib"
-swift-version 5
-I "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI"
-sdk "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk"
Seems like Xcode is specifying the correct -sdk
but specifying the arm64-apple-macosx12.0
target and macOS frameworks to link against.
Maybe it's supposed to be like this, I'm not sure.
@Brendonovich I bumped into the same issue, and after doing a lot of research, I was able to fix the issue by adding these args to the build script.
@Zack-Xb could you try again in your project by pointing to that fork? If this solves it I'll make a PR to this repository.
This is what I added to my Cargo.toml to make a tauri app work:
[patch.crates-io]
swift-rs = { git = "https://github.com/guillemcordoba/swift-rs", branch = "main" }
@guillemcordoba Oh that's interesting, I don't understand much about this error but if that solves it then I'd be happy to merge your branch. Would you be able to explain a bit about how/why it works?
Mmm I wouldn't know actually, I don't have any experience with xcode, swift or anything iOS related. This was just something I found to work after a full day of research around forums and stack overflow.
Not really a bug but something to add into the docs. It took me a while to figure out what was going on...
When building for an ios target on a macos device, the swift build command generated by SwiftLinker is ignoring the -target specification. See below the command built by cargo from within a xcodeproj built by cargo-xcode. As per my findings trying to wrap the swift command with xcrun as suggested in some threads, or adding a swift -arch with or without -Xswiftc, or prepending the command with export ARCHS= doesn't change the outcome.
A workaround (and probably the best course of action) is to build the package within the xcodeproject itself : 1 - Drag the package folder which contains the Package.swift into your Xcode project 2 - Click the Plus button in the "Link Binary with Libraries" section, locate the package in the modal dialog, select the gray library icon inside the package, and add this one.