R.swift
R.swift copied to clipboard
Document how to use R.swift together with SPM
have used swift package manager for R.swift but i can't see any document for generating R.generated.swift using Swift package manager
We'll have to write a proper documentation in the Readme. In short:
- Use SPM to add https://github.com/mac-cain13/R.swift.Library to your project
- Use rswift executable in some other way. It's currently not possible to use development dependencies in SPM (like devDependencies in NPM)
have used swift package manager for R.swift but i can't see any document for generating R.generated.swift using Swift package manager
There's a walkthrough setting up R.swift with SPM here :) https://blog.apptekstudios.com/2019/12/spm-xcode-build-tools/
Is it possible to use R.swift with resources inside SPM packages? This was added in Xcode 12.
@szotp yes, you can embed resources in your Swift Package and the R.generated.swift
will work fine when adding the dependency R.swift.Library
, that means someone, or yourself can use you packaged containing R.swift-referenced resources. (You might need a "ResourceBundle hack" so that it uses Bundle.module
However as @tomlokhorst said, Use swift executable in some other way
. It means you'll have to run the "generate" command manually when adding new resources to your Swift package. Where in the past, your framework likely was maintained by an Xcodeproj with a Script Build phase.
Ideally what I would love to see for a Swift package opened in Xcode, is an Xcode extension running R.swift generate
on your current target sources...
..and ideally, the same for SwiftLint ;)
Any update on this ? I would love to stop maintaining xcodeproj
and only focus on Package.swift, however R.swift cannot generate R.generated.swift without an Xcodeproj file... !
@tomlokhorst I've worked on a branch that allows usage of R.swift to work on a given Swift Package & target name, without using Xcodeproj. It may not be perfect but it seems to do the job. I'm happy to work a bit more on it but would gladly accept your advice on what to Unit Test & which command-line arguments would be preferred.
See here https://github.com/quentinfasquel/R.swift/tree/feature/generate-swift-package-resources
@quentinfasquel Does your version allow to generate R.swift for separate package without xcproj? It would be cool to see this feature in master, did you try to create a PR?
@mmbabaev yes indeed, the version I suggested does work to generate R.swift.generated for a given Swift package, which doesn't rely on an xcodeproj.
The typical example would be a Swift package library that internally uses R.swift for its resources. Currently there's no way around that without using an xcodeproj. It's restricting developers to move forward with SPM, or could have them give up R.swift if they decide to move forward with it fully. I find it quite annoying to have to maintain an xcodeproj when you've discovered the ease of a Package.swift.
However I did not create a PR for a few reasons. The approach I took forces swift tools 5.3 and actually depends on SPM itself to retrieve the package's resources. I would like to have a followup with the maintainers of R.swift and possibly have it reach master
like you suggest.
I don't know if this can work like SwiftFormat. For example: https://github.com/nicklockwood/SwiftFormat#using-swift-package-manager It does this by creating a BuildTools folder and working in it
have used swift package manager for R.swift but i can't see any document for generating R.generated.swift using Swift package manager
There's a walkthrough setting up R.swift with SPM here :) https://blog.apptekstudios.com/2019/12/spm-xcode-build-tools/
I refer to SwiftFormat and report an error when running build phases.
it report:
An error occurred: Missing value for `SDKROOT
my Package.swift :
// swift-tools-version:5.4
import PackageDescription
let package = Package(
name: "BuildTools",
platforms: [
.macOS(.v10_11)
],
dependencies: [
.package(url: "https://github.com/mac-cain13/R.swift", from: "5.4.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.48.10")
],
targets: [
.target(name: "BuildTools", path: "")
])
and my script :
# Type a script or drag a script file from your workspace to insert its path.
cd BuildTools
SDKROOT=(xcrun --sdk macosx --show-sdk-path)
#Temporarily uncomment the following line to update your packages (based on the versions defined in BuildTools/Package.swift)
#swift package update
#Run your build tool - using swiftformat as an example
swift run -c release rswift generate "$SRCROOT/generated/R.generated.swift"
I guess R.swift not yet support SPM with resources bundle? Seems R.swift will scan resources bundle in Xcode Target only.