Skip to content

Migrate examples to snippets #1069

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Migrate examples to snippets #1069

wants to merge 3 commits into from

Conversation

fwcd
Copy link
Member

@fwcd fwcd commented Nov 9, 2022

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 fwcd requested a review from ahoppen as a code owner November 9, 2022 20:34
@fwcd
Copy link
Member Author

fwcd commented Nov 9, 2022

@swift-ci please test

@SimplyDanny
Copy link
Contributor

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

@fwcd
Copy link
Member Author

fwcd commented Nov 11, 2022

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
Copy link
Member Author

fwcd commented Nov 11, 2022

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.

@ahoppen
Copy link
Member

ahoppen commented Nov 24, 2022

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?

@bitjammer
Copy link

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?

@ahoppen
Copy link
Member

ahoppen commented Nov 24, 2022

I think that would solve the problem here.

@bitjammer
Copy link

I've opened swiftlang/swift-package-manager#5929 to address this problem if you would like to give it a spin with this PR.

fwcd added 3 commits November 29, 2022 12:34
As per the Python convention
This fixes an error when invoking the build script without arguments.
@ahoppen
Copy link
Member

ahoppen commented Nov 29, 2022

@bitjammer
Copy link

bitjammer commented Nov 29, 2022

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

@bitjammer
Copy link

@bitjammer
Copy link

Cool, looks like swiftlang/swift-package-manager#5931 will unblock you. Thanks for your patience while I worked out those issues.

@bitjammer
Copy link

✅ All swiftpm blockers landed on main.

@fwcd
Copy link
Member Author

fwcd commented Nov 30, 2022

Very nice, thanks for looking into this!

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to wait for the SwiftPM changes to land in Xcode before we can merge this. I’m marking the PR as ”Request changes” to make sure we don’t accidentally merge it.

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

Successfully merging this pull request may close these issues.

5 participants