swift-syntax
swift-syntax copied to clipboard
Migrate examples to snippets
Now that Xcode 14.1 has been released, there shouldn't be any issues with SwiftPM snippets anymore, therefore this PR migrates the examples folder to snippets again (thus superseding #531).
Additionally this PR renames the buildProduct method to snake_case again, as per the Python convention, and fixes a minor issue where the build script would throw an error when invoked without arguments (instead of producing a proper help message).
cc @ahoppen @SimplyDanny
@swift-ci please test
What about the main functions? Can they be removed/replaced?
We can probably just remove them, to make the scripts a bit less noisy. Not sure about the CI failure, the build script builds the snippets just fine on my machine.
There's also something strange going on with the libraries snippets link with. When I run swift run CodeGenerationUsingSwiftSyntaxBuilder it builds fine, but fails at runtime, noting that libXCTestSwiftSupport.dylib could not be found:
$ swift run CodeGenerationUsingSwiftSyntaxBuilder
Building for debugging...
[3/3] Linking CodeGenerationUsingSwiftSyntaxBuilder
Build complete! (0.71s)
dyld[23402]: Library not loaded: @rpath/libXCTestSwiftSupport.dylib
Referenced from: <B2F88FC4-45E7-3E80-ADCC-75B7F64F9907> /Users/<user>/git/swift-syntax/.build/arm64-apple-macosx/debug/CodeGenerationUsingSwiftSyntaxBuilder
Reason: tried: '/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file), '/Users/<user>/git/swift-syntax/.build/arm64-apple-macosx/debug/libXCTestSwiftSupport.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file), '/Users/<user>/git/swift-syntax/.build/arm64-apple-macosx/debug/libXCTestSwiftSupport.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/libXCTestSwiftSupport.dylib' (no such file), '/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file), '/Users/<user>/git/swift-syntax/.build/arm64-apple-macosx/debug/libXCTestSwiftSupport.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libXCTestSwiftSupport.dylib' (no such file), '/Users/<user>/git/swift-syntax/.build/arm64-apple-macosx/debug/libXCTestSwiftSupport.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libXCTestSwiftSupport.dylib' (no such file), '/usr/local/lib/libXCTestSwiftSupport.dylib' (no such file), '/usr/lib/libXCTestSwiftSupport.dylib' (no such file, not in dyld cache)
zsh: abort swift run CodeGenerationUsingSwiftSyntaxBuilder
I think the issue could be that snippets always try to link all targets, which in this case includes the test support target.
I think the issue could be that snippets always try to link all targets, which in this case includes the test support target.
Oh, this is super annoying. @bitjammer Do you know if there is any way to make the snippets only link against specific targets to avoid this issue?
There isn’t currently a way to specify that. However, is the test support target a product? I recently ran into this issue and I have a todo item to only automatically link product libraries in this way. Would that help here?
I think that would solve the problem here.
I've opened https://github.com/apple/swift-package-manager/pull/5929 to address this problem if you would like to give it a spin with this PR.
https://github.com/apple/swift-package-manager/pull/5929
@swift-ci Please test
Looks like we uncovered another issue, I believe this may have been caused by c1bfac62d536d8cfce6cd6e7b85d2bd7ec2b98a9 – looking into it now.
https://github.com/apple/swift-package-manager/pull/5931
@swift-ci Please test
Cool, looks like https://github.com/apple/swift-package-manager/pull/5931 will unblock you. Thanks for your patience while I worked out those issues.
✅ All swiftpm blockers landed on main.
Very nice, thanks for looking into this!