SwiftFoundation icon indicating copy to clipboard operation
SwiftFoundation copied to clipboard

Building on OS X with SPM fails

Open ky1ejs opened this issue 9 years ago • 13 comments

This is because the JSONParse.swift uses the JSON module on OS X:

https://github.com/PureSwift/SwiftFoundation/blob/develop/Sources/SwiftFoundation/JSONParse.swift#L9

but in the Package.swift the CJSONC module is defined as a dependancy instead:

https://github.com/PureSwift/SwiftFoundation/blob/develop/Package.swift#L8

Is there a reason for no using CJSONC on OS X or vice versa for JSON on Linux?

ky1ejs avatar Feb 27 '16 21:02 ky1ejs

/Users/kylejm/Developer/Loot/OSS/bitrise-slack/Packages/SwiftFoundation-1.1.1/Sources/SwiftFoundation/JSONParse.swift:10:12: error: no such module 'JSON'
    import JSON
           ^

ky1ejs avatar Feb 27 '16 21:02 ky1ejs

SPM is for Linux only. Use Carthage for Darwin platforms.

colemancda avatar Feb 27 '16 21:02 colemancda

Sorry, I must be missing something. Where is SPM documented as only being for Linux platforms? Or do PureSwift projects specifically only support SPM for Linux?

ky1ejs avatar Feb 27 '16 21:02 ky1ejs

PureSwift only supports SPM for Linux.

colemancda avatar Feb 27 '16 22:02 colemancda

Why is this, again? There's nothing stopping you from supporting both...

Danappelxx avatar Feb 28 '16 00:02 Danappelxx

There isn't, im just not committed to always maintaining it since I see little benefit from it. Also you should always use dynamic frameworks on OS X, even for server applications. See http://colemancda.github.io/programming/2015/02/12/embedded-swift-frameworks-osx-command-line-tools/

colemancda avatar Feb 28 '16 04:02 colemancda

There's no maintenance involved and it's actually very important for a lot of people. People don't develop SPM applications on Linux, they do it on OSX. Building on OSX is not always done through Xcode, especially if you're not making a framework.

I think this is worthy of more discussion so I'm going to go ahead and reopen this.

Danappelxx avatar Feb 28 '16 04:02 Danappelxx

Ok then.

colemancda avatar Feb 28 '16 05:02 colemancda

I totally agree with @Danappelxx. A great deal, if not the majority, of Swift developers creating apps for Linux will be developing them on Mac OS. Having to use two different dependancy managers on each platform just seems absurd, especially when the idea is that SPM is made agnostically of the platform.

It's kind of ironic that Carthage, the dependancy manager you suggest, statically links Swift. Dynamically linking against CLI applications, which a lot of server apps will be, isn't straight forward. There is discussion all over the place about it:

  • https://github.com/kylef/Commander#frameworks-and-rpath
  • https://github.com/krzyzanowskim/CryptoSwift/issues/137
  • https://github.com/CocoaPods/CocoaPods/issues/3707

I like what neonichu said about this in the last link in that list back in June 2015 when SPM was not public:

I don't think it is entirely solvable by us, considering that there is no "standard" way to distribute frameworks alongside a command line tool.

I'm sure Apple intend for SPM to be the "standard".

ky1ejs avatar Feb 28 '16 14:02 ky1ejs

There is no support for SPM for iOS, WatchOS or tvOS. Also the link you mentioned regarding Carthage statically linking Swift, does not apply if you follow the my method. If you use a App Bundle Structure, it will dynamically link it. Getting down to business, I am open to supporting this since users may want it, but I personally will not make the changes to support this. If you want to open a PR, I am open to that.

On OS X the only dependency would be JSON-C which you can get from Homebrew. I cannot name the JSON-C dynamic framework CJSONC, because the generated module map expects "JSON" to be the name of the module. That has been my issue so far.

colemancda avatar Feb 28 '16 17:02 colemancda

Cool, I'll open a PR as soon as I can get around to it, but hopefully Foundation gets to implementing NSURLSession etc. first. The side project I was working on with SeeURL has taken a lower priority for a while.

ky1ejs avatar Feb 29 '16 15:02 ky1ejs

What about this issue???

Blackjacx avatar Aug 15 '16 12:08 Blackjacx

The solution for this issue would be to install JSON-C using homebrew and remove the "import JSON" statement, right?

foldericon avatar Nov 20 '16 14:11 foldericon