Skip to content
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

Fix compilation with Xcode >= 16.0 #5

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

jkrukowski
Copy link
Contributor

@jkrukowski jkrukowski commented Oct 30, 2024

I came across the issue when my package (which indirectly depends on Jinja) was built on swiftpackageindex.com
The build resulted in error, more info here:
https://swiftpackageindex.com/builds/EF6D0DF9-542C-47AE-9D1A-D16C8790BF71

Looks like the easiest fix is to provide a separate Package.swift for Swift 6.0. To repro it locally you can try to build it from command line using:

env DEVELOPER_DIR=/Applications/Xcode-16.1.0.app xcrun xcodebuild -skipMacroValidation -skipPackagePluginValidation build -scheme Jinja -destination platform=macOS,arch=arm64 OTHER_SWIFT_FLAGS=-strict-concurrency=complete

Without [email protected] this should give an error, with it, it should build.

@jkrukowski
Copy link
Contributor Author

Same happens in swift-transformers repo https://swiftpackageindex.com/builds/F6095453-30D2-4175-8FBF-E28D9AD440FE it fails to compile because seems like swift 6 has BareSlashRegexLiterals enabled by default https://github.com/swiftlang/swift-evolution/blob/main/proposals/0354-regex-literals.md#source-compatibility

@jkrukowski
Copy link
Contributor Author

Another solution would be to wrap regex literals in #/.../#, let me know how you want to proceed @maiqingqiang

@johnmai-dev
Copy link
Owner

Thank you, I'll review it tonight.

@johnmai-dev
Copy link
Owner

Adding [email protected] only solved the build issue, it didn't really make Jinja support Swift 6, right?

@jkrukowski
Copy link
Contributor Author

Adding [email protected] only solved the build issue, it didn't really make Jinja support Swift 6, right?

yes, that's correct, it makes Jinja compile with >= Xcode 16.0, I'll update the PR title

@jkrukowski jkrukowski changed the title Added support for Swift 6 Fix compilation with >= Xcode 16.0 Oct 31, 2024
@jkrukowski jkrukowski changed the title Fix compilation with >= Xcode 16.0 Fix compilation with Xcode >= 16.0 Oct 31, 2024
@johnmai-dev
Copy link
Owner

Another solution would be to wrap regex literals in #/.../#, let me know how you want to proceed @maiqingqiang

Perhaps we could do it this way?
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md

#if compiler(>=5.7)
  #if hasFeature(BareSlashRegexLiterals)
  let regex = /.../
  #else
  let regex = #/.../#
  #endif
#else
let regex = try NSRegularExpression(pattern: "...")
#endif

@jkrukowski
Copy link
Contributor Author

Another solution would be to wrap regex literals in #/.../#, let me know how you want to proceed @maiqingqiang

Perhaps we could do it this way? https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md

#if compiler(>=5.7)
  #if hasFeature(BareSlashRegexLiterals)
  let regex = /.../
  #else
  let regex = #/.../#
  #endif
#else
let regex = try NSRegularExpression(pattern: "...")
#endif

Looks good, however:

  • this might be a bit excessive because this package will not work with Swift < 5.8, that's the version which is specified in Package.swift
  • why don't we wrap every regex literal between # so for example this line becomes .replacing(#/{##}/#, with: "")wdyt? This way we don't need additional package.swift for swift 6 only

@johnmai-dev
Copy link
Owner

Another solution would be to wrap regex literals in #/.../#, let me know how you want to proceed @maiqingqiang

Perhaps we could do it this way? https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md

#if compiler(>=5.7)
  #if hasFeature(BareSlashRegexLiterals)
  let regex = /.../
  #else
  let regex = #/.../#
  #endif
#else
let regex = try NSRegularExpression(pattern: "...")
#endif

Looks good, however:

  • this might be a bit excessive because this package will not work with Swift < 5.8, that's the version which is specified in Package.swift
  • why don't we wrap every regex literal between # so for example this line becomes .replacing(#/{##}/#, with: "")wdyt? This way we don't need additional package.swift for swift 6 only

Sure, you can directly use .replacing(#/{##}/#, with: "").

Copy link
Owner

@johnmai-dev johnmai-dev left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@johnmai-dev johnmai-dev merged commit 6dbe4c4 into johnmai-dev:main Oct 31, 2024
3 checks passed
@jkrukowski jkrukowski deleted the swift-6-support branch October 31, 2024 14:20
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.

2 participants