`swift package generate-xcodeproj` fails with "Swift does not support the SDK" - swift

I'm having trouble running swift package generate-xcodeproj. I created my package like this:
$ /Applications/Xcode9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift package init --type executable
(as I have many Xcode versions installed I explicitly targeted a swift binary when running the command so that I don't need to xcode-select all the time)
This created a Package.swift with the version header // swift-tools-version:4.0.
Now, when I run swift package generate-xcodeproj I get a fatal error:
$ /Applications/Xcode9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift package generate-xcodeproj
/Users/max.chuquimia/Desktop/xcode/MyPackage: error: manifest parse error(s):
<unknown>:0: error: Swift does not support the SDK 'MacOSX10.12.sdk'
No .xcodeproj is generated. Why is this occurring?

It seems the problem is the $DEVELOPER_DIR environment variable is wrong - it should also be made to point to the Xcode version that the swift binary resides in.
$ DEVELOPER_DIR=/Applications/Xcode9.4.1.app/Contents/Developer /Applications/Xcode9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift package generate-xcodeproj

Related

Is it possible to produce an XCFramework from a Swift Package with dependencies?

I want to be able to take an internal SPM package, which depends on several other internal (and one external) SPM packages, and compile it into an XCFramework, using a series of xcodebuild like you would for a framework project. For example, I have PackageB, which references PackageA, and I'm trying to build PackageB.xcframework. The first step would be:
xcodebuild -scheme PackageB -destination "generic/platform=iOS" -configuration Release ARCHS="arm64" BUILD_DIR="./Build
The tool's output indicates that the dependency packages are being resolved, but they are then not recognized by the compiler (i.e. code in PackageB which references PackageA will not compile because PackageA is unknown at that point).
Thanks for any pointers.
You can create xcframework from swift package by using swift-create-xcframework command line tool, there is also GitHub action available for this.
If you don't want to use this tool, you can generate Xcode project by using swift package generate-xcodeproj command:
OVERVIEW: Generates an Xcode project. This command will be deprecated soon.
USAGE: swift package generate-xcodeproj
OPTIONS:
--xcconfig-overrides
Path to xcconfig file
--output Path where the Xcode project should be generated
--legacy-scheme-generator
Use the legacy scheme generator
--watch Watch for changes to the Package manifest to
regenerate the Xcode project
--skip-extra-files Do not add file references for extra files to the
generated Xcode project
--version Show the version.
-h, -help, --help Show help information.
and then create xcframework with the generated Xcode project.

Swift package build error: could not build Objective-C module 'Darwin'

I'm trying to create a kitura app, but got stuck at the first steps:
Created empty directory
swift package init --type executable
swift build
The result: Build output
I've tried reinstalling command line tools as well as xcode itself with no success..
Thanks in advance!

vapor build error: manifest parse error(s)

macOS Height Sierra 10.13.4
Xcode version 9.3
$ swift --version
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
$ brew info vapor
vapor/tap/vapor: stable 3.1.4.l
https://vapor.codes
/usr/local/Cellar/vapor/3.1.4.l (4 files, 17.0MB) *
Built from source on 2018-04-01 at 23:55:47
From: https://github.com/vapor/homebrew-tap/blob/master/vapor.rb
==> Dependencies
Required: ctls ✔, libressl ✔
$ eval "$(curl -sL check.vapor.sh)"
✅ Xcode 9 is compatible with Vapor 2.
✅ Xcode 9 is compatible with Vapor 3.
✅ Swift 4.1 is compatible with Vapor 2.
✅ Swift 4.1 is compatible with Vapor 3.
$ vapor version
Vapor Toolbox: 3.1.4
I create new project with:
vapor new Hello --template=api
and when I try to build it:
vapor build --verbose
I get the error:
No .build folder, fetch may take a while...
Fetching Dependencies ...
warning: 'fetch' command is deprecated; use 'resolve' instead
/PATH-TO-PROJECT: error: manifest parse error(s):
<module-includes>:5:9: note: in file included from <module-includes>:5:
#import "copyfile.h"
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/copyfile.h:36:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Develo. per/SDKs/MacOSX10.13.sdk
/usr/include/copyfile.h:36:
#include <stdint.h>
^
/usr/local/include/stdint.h:59:11: note: in file included from /usr/local/include/stdint.h:59:
# include <stdint.h>
^
/usr/local/include/stdbool.h:4:10: note: in file included from /usr/local/include/stdbool.h:4:
#include <stdbool.h>
^
<unknown>:0: error: could not build Objective-C module 'Darwin'
Building Project [Failed]
Error: execute(1)
Does anyone have any idea what is going wrong there? Thanks in advance!
I found the solution:
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected header files:
/usr/local/include/base.h
/usr/local/include/bcj.h
/usr/local/include/block.h
/usr/local/include/cdefs.h
/usr/local/include/check.h
...
and solved the problem by deleting all "Unbrewed header files" from /usr/local/include/
That is bizarre! Just to confirm you’re in the right folder? If you run swift build does it do the same thing?
I had a similar issue unrelated to brew.
Error: backgroundExecute(code: 1, error: "/path/to/project: error: manifest parse error(s):\nInvalid version string: x.0.0\n", output: "")
My Package file looked like this;
...
.package(url: "https://github.com/../something.git", .upToNextMajor(from: "x.0.0")),
...
Looking into .upToNextMajor(from:) I didn't see any parsing for 'x' so I just went to the github page and found which major version I wanted and replaced it for the placeholder in my package file:
...
.package(url: "https://github.com/../something.git", .upToNextMajor(from: "1.0.0")),
...
This resolved the issue for me, Hope this helps the next person that comes by! upvote if it helps you!

Pod lib lint Error: Warn Swift Version

Every time I run pod lib lint file.podspec I receive this storage warning and I can't figure out how to fix it
You won't receive this warning if you are using CocoaPods 1.7.0.beta.1 or newer because the .swift-version file was deprecated, see this link for more details. Use the swift_versions attribute to specify the Swift version:
s.swift_versions = ['5.0']
The .swift-version is a file that serves as a hint for cocoapods to know which version of Swift your pod target, for the given branch/commit/tag.
The content of the file should exclusively contain the Swift version your pod targets, so 4.2 for example if you target Swift 4.2. You can easily create such a file by navigating to the podspec's folder using the Terminal app, and then write:
echo '4.2' > .swift-version
(replace 4.2 with the Swift version you target)
You can find an example of such a file on Sourcery's repository: https://github.com/krzysztofzablocki/Sourcery/blob/master/.swift-version

How to install Swift package via package manager?

I am currently following the document from swift.org to play around with the new Swift Package Manager.
I cloned the demo project from Github and run the following command from terminal.
git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift build
.build/debug/Dealer
While I run swift build, error arise.
<unknown>:0: error: no such file or directory: 'build'
Any idea?
I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong swift package. If you want to use swift build, MAKE SURE you download the development version.
You did not add the newly installed swift to your PATH. The instructions for doing that are here.
On OS X:
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
On Linux:
export PATH=/path/to/Swift/usr/bin:"${PATH}"
Then to test it works:
swift build --version
I think it is a problem with the latest snapshot:
Ubuntu 14.04 Swift 2.2 Snapshot of January 11 contains swift-build in usr/bin
Ubuntu 14.04 Swift 2.2 Snapshot of January 25 doesn't contain swift-build in usr/bin
Besides, the January 25 release also seems to miss other files (libFoundation.so and libXCTest.so in usr/lib/swift/linux for instances).
Either there has been a structure change....or, simply, the latest snapshot had a problem ;)
While they fix the snapshot, simply take the older (January 11th) snapshot, and you should be fine.
I was facing the same issue and in my case, I recently updated my Xcode to 8.2.1 and swift 3.0 comes with it.
I was getting this log.
Ranvijay-Mac-mini:PerfectTemplate ranaranvijaysingh$ swift build
error: unable to invoke subcommand: /Library/Developer/CommandLineTools/usr/bin/swift-build (No such file or directory)
The path it was taking was incorrect. It was suppose to be:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
To change the path, run this command.
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH
And DONE.
Run : swift build again on your project and if you get this error.
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
error: Invalid platform path
then you need to change the SDK path as well.
In my case, I had two .sdk at path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX.sdk MacOSX10.12.sdk
To know what is your SDK path, run this command.
xcrun --sdk macosx --show-sdk-path
My case i got this.
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
To change it run this command.
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
and NOW DONE.
Try running swift build now.