R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Swift Package Manager Support

Open keithcml opened this issue 3 years ago • 8 comments

Hi team, I would like to ask how to use with SPM.

I have checkout the modularization using SPM on PointFree. https://www.pointfree.co/episodes/ep171-modularization-part-1

I want to implement R.swift for each module. But I faced some problems.

  1. How to generate hosting bundle with Bundle.module
  2. How to run Rswift to generate files and put in each module.

keithcml avatar Dec 24 '21 03:12 keithcml

I also tried that and ended up in a dependency cycle. I got two targets, the app target and a local SPM package ("Assets") offering a library target. After adding R.swift into the library target and the build script to the app target we run into a dependency cycle:

Cycle in dependencies between targets 'MyApp' and 'Assets'; building could produce unreliable results.
Cycle path: MyApp → Assets → MyApp
Cycle details:
→ Target 'MyApp' has target dependency on Target 'Assets'
→ Target 'Assets' has target dependency on Target 'Assets'
○ Target 'Assets' has compile command for Swift source files
○ That command depends on command in Target 'MyApp': script phase "R.Swift"
→ Target 'MyApp' has target dependency on Target 'Assets'

@keithcml I don't think that's fixable unless SPM supports build phase scripts. :(

aregler avatar Jan 03 '22 12:01 aregler

@aregler then it is good as Swift5.6 will support that 😏

keithcml avatar Jan 03 '22 12:01 keithcml

@keithcml are you referring to this proposal?

fruitcoder avatar Jan 03 '22 13:01 fruitcoder

@fruitcoder exactly.. The code was merged so I think is is coming.

keithcml avatar Jan 03 '22 13:01 keithcml

Xcode 13.3 Beta came out yesterday and it seems "Swift Packages now support build tool plugins" 🎉 In case anyone wants to try it out, this post might point you in the right direction.

fruitcoder avatar Jan 28 '22 11:01 fruitcoder

Hey @keithcml, did you manage to create a plugin with the new Xcode beta? I have trouble to do so :(

aregler avatar Mar 01 '22 08:03 aregler

Hi, I've tried to create SPM custom command for R.swift, but it's not working completely according to R.swift - is using xcodeproj for detecting resources in project. It's time to add possibility in R.swift to take package.swift resources.

My example of build tool plugin:

https://github.com/martinpristas/SPM-Plugins-Example

martinpristas avatar Mar 24 '22 09:03 martinpristas

We couldn't make it work as well, so we switched to SwiftGen for now

fruitcoder avatar Mar 25 '22 09:03 fruitcoder