I'd like to try the Swift libSyntax API.
I did a fresh clone and compiled with
$ ./utils/build-script --release-debuginfo --xcode
using Xcode 9 beta 2 (9B46).
Now I'd like to try SwiftSyntax so I created a new Xcode project
(TestLibSyntax) and copied these three files to a project folder
(/Users/mmg/src/TestLibSyntax/Libraries)
~/swift-source/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/RelWithDebInfo/lib/swift/macosx/libswiftSwiftSyntax.dylib
~/swift-source/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/RelWithDebInfo/lib/swift/macosx/x86_64/SwiftSyntax.swiftmodule
~/swift-source/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/RelWithDebInfo/lib/swift/macosx/x86_64/SwiftSyntax.swiftdoc
Then in the Build Settings I set
SWIFT_INCLUDE_PATHS = /Users/mmg/src/TestLibSyntax/Libraries
And add a build phase to copy the .dylib to the Frameworks directory.
Upon building this project the compiler now complains that
Module compiled with Swift 4.1 cannot be imported in Swift 4.0.1:
/Users/mmg/src/TestLibSyntax/Libraries/SwiftSyntax.swiftmodule
Is there a way to tell the compiler to build everything in this example
project with Swift 4.1?
Or, how to use the SwiftSyntax swiftmodule and dylib in a regular Xcode
project?
Best,
Michael
What I missed was that you have to use the freshly built compiler to
compile your sample program using SwiftSyntax. (Thanks to Harlan for
pointing that out.)
Xcode won't work here (yet). After building swiftpm (`./utils/build-script
--release-debuginfo --swiftpm`) you can use it to create an executable
/Users/mmg/swift-source/build/Ninja-RelWithDebInfoAssert/swiftpm-macosx-x86_64/x86_64-apple-macosx10.10/debug/swift-package
init --type executable
/Users/mmg/swift-source/build/Ninja-RelWithDebInfoAssert/swiftpm-macosx-x86_64/x86_64-apple-macosx10.10/debug/
swift-build
/Users/mmg/swift-source/build/Ninja-RelWithDebInfoAssert/swiftpm-macosx-x86_64/x86_64-apple-macosx10.10/debug/
swift-run
and then replace the main.swift with e.g. Harlan's example
swift-format.swift
<https://gist.github.com/harlanhaskins/b2ed96b64a551214a7f2c7717c285dce>
It should find the SwiftSyntax.swiftmodule and the corresponding dylib
automatically.
I hope this helps in case you want to try it.
What's worth noting is that if you want a json view of the available syntax
information you can simply run `path/to/your/freshly/built/*swiftc
-frontend -emit-syntax* Example.swift`
ยทยทยท
2017-10-16 15:06 GMT+02:00 Michael Gubik <gubikmic@gmail.com>:
I'd like to try the Swift libSyntax API.
I did a fresh clone and compiled with
$ ./utils/build-script --release-debuginfo --xcode
using Xcode 9 beta 2 (9B46).
Now I'd like to try SwiftSyntax so I created a new Xcode project
(TestLibSyntax) and copied these three files to a project folder
(/Users/mmg/src/TestLibSyntax/Libraries)
~/swift-source/build/Xcode-RelWithDebInfoAssert/swift-
macosx-x86_64/RelWithDebInfo/lib/swift/macosx/libswiftSwiftSyntax.dylib
~/swift-source/build/Xcode-RelWithDebInfoAssert/swift-
macosx-x86_64/RelWithDebInfo/lib/swift/macosx/x86_64/
SwiftSyntax.swiftmodule
~/swift-source/build/Xcode-RelWithDebInfoAssert/swift-
macosx-x86_64/RelWithDebInfo/lib/swift/macosx/x86_64/SwiftSyntax.swiftdoc
Then in the Build Settings I set
SWIFT_INCLUDE_PATHS = /Users/mmg/src/TestLibSyntax/Libraries
And add a build phase to copy the .dylib to the Frameworks directory.
Upon building this project the compiler now complains that
Module compiled with Swift 4.1 cannot be imported in Swift 4.0.1:
/Users/mmg/src/TestLibSyntax/Libraries/SwiftSyntax.swiftmodule
Is there a way to tell the compiler to build everything in this example
project with Swift 4.1?
Or, how to use the SwiftSyntax swiftmodule and dylib in a regular Xcode
project?
Best,
Michael