Using DocC for an Objective-C project - docc

I am working on an Objective-C library, that is also available via Swift Package Manager, namely Sentry. We want to generate API docs using DocC, but I am running into the problem where when I generate the documentation I get this error:
error: target 'Sentry' is not a Swift source module
Weirdly enough when I build the documentation within Xcode itself (Product -> Build Documentation) it works perfectly well.
This is the command I am using on the command line to try to generate the docs:
swift package \
generate-documentation \
--allow-writing-to-directory ./docs \
--target Sentry \
--output-path ./docs \
--transform-for-static-hosting \
--hosting-base-path Sentry
And our Package.swift can be found here.
So why is it that Xcode can generate the docs perfectly fine, but I can't do it using swift-docc-plugin?

Related

How can I build a Swift Package for iOS over command line?

In Xcode, I can select my destination as a "generic iOS device" or any iOS simulator, and my package will build platform-specific code for ios.
Via command line "swift build" only builds my target for macOS.
I want to build the target for iOS for CI purposes. The problem with building for macOS is that UIKit-specific code won't be built.
For example:
#if canImport(UIKit)
// some invalid code
#endif
The invalid code will not be noticed and will pass the build phase.
Ideally, I could say something like swift build -platform iOS. Is there a way to do something like this?
At time of writing (Feb 16, 2019), a working solution is:
swift build -v \
-Xswiftc "-sdk" \
-Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" \
-Xswiftc "-target" \
-Xswiftc "x86_64-apple-ios13.0-simulator"
This command uses -Xswiftc to workaround the issue by overriding the sdk from macOS to iphonesimulator.
Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.
Source
So I'm guessing there will be a more elegant solution in the future.
Starting with Xcode 11, xcodebuild supports SwiftPM packages out of the box.
An example invocation would look like this:
xcodebuild -scheme Foo \
-destination 'platform=iOS Simulator,OS=13.5,name=iPhone 11 Pro'
where Foo would be the name of the library product you're trying to build. You can
get the full list of available schemes for you SwiftPM package with xcodebuild -list.
You can get the list of available destinations for a given scheme with this invocation:
xcodebuild -showdestinations -scheme Foo

Convert XCodeProj to Package.swift

I have recently inherited a swift project and would prefer to do my development on a Linux VM, rather then the under powered Mac I have. I have found lots of tutorials on how to got from a Package.swift to a xcodeproj. But I haven't found anything to go the other direction (xcodeproj to Package.swift). It seems that I need the Package.swift to be able to use the swift cli (swift build).
Is there a way to build without the Package.swift file?
Is there a way to do this that I haven't found?
Is there a technical reason that we can't go from a xcodeproj to a Package.swift?
1./2.
A Package.swift file is internally translated to a set of swiftc commands.
If you run swift build -v (verbose) on a fully working Swift package, you can see the commands that are being run. Using these commands, you may be able to figure out how to compile any collection of Swift sources without a Package.swift.
For a framework, one command could look something like this:
swiftc -module-name TestPackage -emit-dependencies -emit-module -c Path/to/Sources/*.swift -Onone -g -enable-testing -j8 -DSWIFT_PACKAGE -DDEBUG -Xfrontend -color-diagnostics
When compiling an executable, there may be additional commands to link the standard library, etc.
3.
The feature set of Xcode far exceeds the capabilities of Swift packages (e.g. .app bundles, Storyboards, Metal source files, ObjC, C, C++, etc.)
However, you can convert your command line project to a Swift package by running swift package init --type library|executable to create a Package.swift file. You can then specify a path parameter for the target in the Package.swift file:
.target(name: "YourTarget", path: "Path/To/Your/Swift/Files")

Can not import TensorFlow for Swift in Xcode Playground

I'm trying to use Swift for TensorFlow and have followed the directions found here: https://github.com/tensorflow/swift/blob/master/Installation.md
When I go ahead and import TensorFlow as such within a Swift Playground file:
import TensorFlow
I get this error: "The active toolchain is not compatible with playgrounds. libswiftCore.dylib could not be loaded"
I was able to use Swift for TensorFlow within the REPL so I know it should work. Anyone have any ideas as to how to fix this issue? It clearly works as shown in this demonstration: https://www.youtube.com/watch?time_continue=819&v=Yze693W4MaU
Get the latest stable toolchain (e.g. v 0.6), install it, then go to Xcode > File > New > Project > Macos - Command Line Tools (instead of Playground). Additionally, the December 23, 2019 development toolchain—and beyond—should not require switching to the Legacy Build System. More information in this discussion here.
Was running into this as well. Answered in the Google Group - turns out you need to make sure you are creating a macOS playground and not an iOS playground.
I had the same issue and it turns out is the playground type.
From the Google Group reply:
As a synthesis of answers above and my own experience now with the latest May 8, 2020 builds and comments from the Google Group, I find:
SUCCESS
Xcode Project Command-line (as #8bitmp3 answered above)
Command-line swiftc (using the -O argument. Note this is the compiler)
FAILURE
Xcode Playground macOS (as #ian-do originally asked)
Command-line swift (and confirmed by Google Group. Note this is the interpreter)
For those interested in the command-line success (macOS 10.15.4), install the toolchain from here, create the source code file inference.swift per this page, and execute the following:
# Test this command. Expected outcome is your existing Xcode app as show below
$ xcrun -f swift
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
# Switch to the new TensorFlow toolchain you installed
# Mine was located at /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.9.xctoolchain/
# Open the Info.plist file, locate CFBundleIdentifier, and copy the string value
# Mine was com.google.swift.20200507
$ export TOOLCHAINS=com.google.swift.20200507
# Test the switch to your TensorFlow toolchain. Note the different result
$ xcrun -f swift
/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.9.xctoolchain/usr/bin/swift
# Compile your Swift for TensorFlow source code
$ cd <directory with .swift file>
$ swiftc -O -sdk `xcrun --show-sdk-path` inference.swift
# Run the program
$ ./inference
[[0.68070436]]

vapor build command not working with Swift 3.0

I am currently following the small and brief introduction to Swift Vapor by following their "Hello World" tutorial on their website. However I keep getting an error from swift-package when I try to build the project where it shows the following.
$ vapor build
No .build folder, fetch may take a while...
Fetching Dependencies [Failed]
Error: swift-package: error: unknown command: --enable-prefetching
I cannot seem to find out how to resolve this online. Anybody have any idea?
you have not mentioned your environment, so i'm giving solution for macOS.
I had the same issue, my swift version is 3.0.2 and vapor toolbox version is 1.0.9,
I tried the following thing to make it work
get into your project directory
create xcode project with command
swift package generate-xcodeproj
open xcode project
Select your scheme as App like this
and then build and run app
hope this helps!!
Make sure that you're using the correct command line tools for the Swift Version that you're using.
You can check from Xcode > Preferences > Locations > Command Line Tools
For me, using swift 3.0.2, vapor build command doesn't work neither.
However using swift 3.1.0, vapor build command works well.
My Vapor toolbox version is v1.1.0
I had the same problem, and I had Swift 3.1 installed. I deleted old version completely and installed new one and now it's building fine.
Try
rm -rf /usr/local/bin/vapor
brew tap vapor/homebrew-tap

than
brew install vapor
or
brew link vapor
if you have installed a new version previously.

Unity Facebook SDK v 7.7 and Google Play Services

B.S: I am specifically talking about facebook-unity-sdk-7.7.0 not v 7.3.0
I am using facebook-unity-sdk-7.7.0 and GooglePlayGamesPlugin-0.9.32 in my project. It does not let me build for android and fails with error Unable to convert classes into dex format. See the Console for details.. In Facebook SDK 7.3.0 it works by deleting android support v4, but in 7.7 the same thing does not work.
I had the same problem and this was the way I solved it:
Delete the following files from the folder:
\ Assets \ FacebookSDK \ Plugins \ Android \ libs:
support-annotations-23.4.0.jar
support-annotations-23.4.0.meta
support-v4-23.4.0.aar
support-v4-23.4.0.meta