Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribute portable binary #360

Closed
keith opened this issue Apr 13, 2017 · 13 comments
Closed

Distribute portable binary #360

keith opened this issue Apr 13, 2017 · 13 comments

Comments

@keith
Copy link
Contributor

keith commented Apr 13, 2017

It would be nice if, along side the current package installer, we distributed a "portable" version of sourcekitten, that could be run from any directory without the installation. Similar to how it's done on SwiftLint

Semi related realm/SwiftLint#1395

@jpsim
Copy link
Owner

jpsim commented Apr 13, 2017

If we're to do this at all, it should be done with SwiftPM rather than the complex build flow used for SwiftLint's portable build at the moment.

@keith
Copy link
Contributor Author

keith commented Apr 13, 2017

SGTM. This works with the nightly build of swiftpm without any changes

@jpsim
Copy link
Owner

jpsim commented Apr 13, 2017

Is there a problem with the latest official release? In my tests, the SwiftPM included in Xcode 8.3.1 works just fine for this.

@keith
Copy link
Contributor Author

keith commented Apr 13, 2017

This still depends on that C library right? I the 8.3.1 swiftpm still requires that to be dynamic. (I haven't tried today, only recalling from my testing with swiftlint)

@jpsim
Copy link
Owner

jpsim commented Apr 13, 2017

Oh, so the -static-stdlib flag also builds other Packages statically too in the nightly builds?

@keith
Copy link
Contributor Author

keith commented Apr 13, 2017

Even without that flag, everything gets built statically.

@norio-nomura
Copy link
Collaborator

I tried with swift-DEVELOPMENT-SNAPSHOT-2017-04-13-a:

$ TOOLCHAINS=org.swift.3020170413a swift build -c release
Fetching https://github.com/Carthage/Commandant.git
Fetching https://github.com/drmohundro/SWXMLHash.git
Fetching https://github.com/jpsim/Yams.git
Fetching https://github.com/norio-nomura/Clang_C.git
Fetching https://github.com/norio-nomura/SourceKit.git
Fetching https://github.com/antitypical/Result.git
Cloning https://github.com/jpsim/Yams.git
Resolving https://github.com/jpsim/Yams.git at 0.3.1
Cloning https://github.com/norio-nomura/SourceKit.git
Resolving https://github.com/norio-nomura/SourceKit.git at 1.0.1
Cloning https://github.com/antitypical/Result.git
Resolving https://github.com/antitypical/Result.git at 3.2.1
Cloning https://github.com/drmohundro/SWXMLHash.git
Resolving https://github.com/drmohundro/SWXMLHash.git at 3.0.4
Cloning https://github.com/norio-nomura/Clang_C.git
Resolving https://github.com/norio-nomura/Clang_C.git at 1.0.2
Cloning https://github.com/Carthage/Commandant.git
Resolving https://github.com/Carthage/Commandant.git at 0.12.0
Compile CYaml src/writer.c
Compile CYaml src/reader.c
Compile CYaml src/scanner.c
Compile CYaml src/dumper.c
Compile CYaml src/api.c
Compile CYaml src/emitter.c
Compile CYaml src/loader.c
Compile CYaml src/parser.c
Compile Swift Module 'Result' (2 sources)
Compile Swift Module 'SWXMLHash' (2 sources)
Compile Swift Module 'Yams' (12 sources)
Compile Swift Module 'Commandant' (10 sources)
/Users/norio/github/swift-dev/SourceKitten/.build/checkouts/SWXMLHash.git-5776748636326364470/Source/SWXMLHash.swift:497:46: warning: 'flatMap' is deprecated: This call uses implicit promotion to optional. Please use map instead.
        for elem in all.map({ $0.element! }).flatMap({ $0 }) {
                                             ^
/Users/norio/github/swift-dev/SourceKitten/.build/checkouts/Yams.git-8068124914099325722/Sources/Yams/Representer.swift:157:25: warning: 'flatMap' is deprecated: This call uses implicit promotion to optional. Please use map instead.
        let nodes = try flatMap(represent)
                        ^
Compile Swift Module 'SourceKittenFramework' (33 sources)
/Users/norio/github/swift-dev/SourceKitten/Source/SourceKittenFramework/ClangTranslationUnit.swift:23:33: warning: redundant conformance constraint 'U': 'Hashable'
    fileprivate func grouped<U: Hashable>(by transform: (Iterator.Element) -> U) -> [U: [Iterator.Element]] {
                                ^
/Users/norio/github/swift-dev/SourceKitten/Source/SourceKittenFramework/ClangTranslationUnit.swift:23:85: note: conformance constraint 'U': 'Hashable' inferred from type here
    fileprivate func grouped<U: Hashable>(by transform: (Iterator.Element) -> U) -> [U: [Iterator.Element]] {
                                                                                    ^
Compile Swift Module 'sourcekitten' (10 sources)
Linking ./.build/release/sourcekitten
TOOLCHAINS=org.swift.3020170413a swift build -c release  148.99s user 8.84s system 123% cpu 2:07.39 total
$ otool -L .build/release/sourceKitten
.build/release/sourceKitten:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1349.63.0)
	@rpath/libswiftCore.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libswiftCoreGraphics.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libswiftDarwin.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libswiftDispatch.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libswiftFoundation.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libswiftIOKit.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libswiftObjectiveC.dylib (compatibility version 0.0.0, current version 0.0.0)

It still needs -static-stdlib:

$ otool -L .build/release/sourceKitten
.build/release/sourceKitten:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1349.63.0)
	/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1070.22.0)

@keith
Copy link
Contributor Author

keith commented Apr 14, 2017

Sorry what I meant was, regardless of whether or not you pass -static-stdlib, the dependencies are statically linked. We would definitely pass -static-stdlib as well.

@keith
Copy link
Contributor Author

keith commented Apr 14, 2017

Any thoughts on doing this with releases now, even though we'd have to build it with a snapshot? Or do you think we'd want to wait until there was an Xcode version released with this swiftpm behavior?

@norio-nomura
Copy link
Collaborator

If SourceKitten can pass the test, it may be good to release it, but now it can not pass by using snapshot.

@jpsim
Copy link
Owner

jpsim commented Apr 14, 2017

For a portable binary that SourceKitten maintainers upload to GitHub releases, sure I could get behind doing this (once it compiles, as @norio-nomura mentions), however I wouldn't want to require Xcode 9 or whatever for users of Homebrew who want to compile from source.

@norio-nomura
Copy link
Collaborator

Since #443 has been merged to master, now brew install sourcekitten --HEAD installs statically linked sourcekitten:

$ brew install sourcekitten --HEAD
==> Cloning https://github.com/jpsim/SourceKitten.git
Cloning into '/Users/norio/Library/Caches/Homebrew/sourcekitten--git'...
remote: Counting objects: 180, done.
remote: Compressing objects: 100% (160/160), done.
remote: Total 180 (delta 36), reused 52 (delta 14), pack-reused 0
Receiving objects: 100% (180/180), 284.08 KiB | 416.00 KiB/s, done.
Resolving deltas: 100% (36/36), done.
==> Checking out branch master
==> make prefix_install PREFIX=/usr/local/Cellar/sourcekitten/HEAD-cc3499f TEMPORARY_FOLDER=/private/tmp/sourcekitten-20171121-11791-199ghw7/SourceKitten.dst
🍺  /usr/local/Cellar/sourcekitten/HEAD-cc3499f: 6 files, 11.8MB, built in 1 minute 52 seconds
brew install sourcekitten --HEAD  105.29s user 22.00s system 110% cpu 1:55.54 total
$ otool -L `which sourcekitten`
/usr/local/bin/sourcekitten:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1445.12.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1443.14.0)
	/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1125.3.4)
	/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 59.1.0)

@jpsim jpsim closed this as completed Nov 21, 2017
@keith
Copy link
Contributor Author

keith commented Nov 21, 2017

🎉 thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants