swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

Migrate examples to snippets

Open fwcd opened this issue 3 years ago • 14 comments

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

fwcd avatar Nov 09 '22 20:11 fwcd

@swift-ci please test

fwcd avatar Nov 09 '22 20:11 fwcd

What about the main functions? Can they be removed/replaced?

SimplyDanny avatar Nov 09 '22 21:11 SimplyDanny

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.

fwcd avatar Nov 11 '22 13:11 fwcd

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.

fwcd avatar Nov 11 '22 13:11 fwcd

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?

ahoppen avatar Nov 24 '22 06:11 ahoppen

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?

bitjammer avatar Nov 24 '22 11:11 bitjammer

I think that would solve the problem here.

ahoppen avatar Nov 24 '22 11:11 ahoppen

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.

bitjammer avatar Nov 29 '22 04:11 bitjammer

https://github.com/apple/swift-package-manager/pull/5929

@swift-ci Please test

ahoppen avatar Nov 29 '22 11:11 ahoppen

Looks like we uncovered another issue, I believe this may have been caused by c1bfac62d536d8cfce6cd6e7b85d2bd7ec2b98a9 – looking into it now.

bitjammer avatar Nov 29 '22 22:11 bitjammer

https://github.com/apple/swift-package-manager/pull/5931

@swift-ci Please test

bitjammer avatar Nov 29 '22 23:11 bitjammer

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.

bitjammer avatar Nov 30 '22 02:11 bitjammer

✅ All swiftpm blockers landed on main.

bitjammer avatar Nov 30 '22 02:11 bitjammer

Very nice, thanks for looking into this!

fwcd avatar Nov 30 '22 02:11 fwcd