[swift-dev] Trying to use Swift libSyntax API. "Module compiled with Swift 4.1 cannot be imported in Swift 4.0.1"

Michael Gubik gubikmic at gmail.com
Thu Oct 19 07:38:07 CDT 2017


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 at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171019/2031a021/attachment.html>


More information about the swift-dev mailing list