Xcode 14.0 ships with the old macOS SDK and therefore not with the Swift 5.7 standard library. Try on iOS or with an Xcode 14 beta (Xcode 14.1 works but also older 14.0 betas because they contain the macOS beta SDK).
Thank you all for your help.
Based on your answers, I found some solutions.
On Linux, using Swift 5.7 : the below works (compile and run)
swift --version
Swift version 5.7 (swift-5.7-RELEASE)
Target: aarch64-unknown-linux-gnu
swift build -Xswiftc -enable-bare-slash-regex
Building for debugging...
[4/4] Emitting module mm
Build complete! (0.60s)
On macOS 12, it is not enough, I also add to install Xcode 14 beta 3
Compiling from Xcode does not work. Compiling from the command line using the above command works too.
swift --version
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.134.3 clang-1400.0.29.51)
Target: arm64-apple-macosx12.0
swift build -Xswiftc -enable-bare-slash-regex
Building for debugging...
[3/3] Linking mm
Build complete! (0.59s)
Runnin on macOS 12 does not work :
swift run -Xswiftc -enable-bare-slash-regex
Building for debugging...
Build complete! (0.13s)
dyld[31783]: Library not loaded: '/usr/lib/swift/libswift_StringProcessing.dylib'
Referenced from: '/Users/stormacq/Documents/amazon/code/amplify/amplify-ios-workshop/migrate_markdown/.build/arm64-apple-macosx/debug/mm'
Reason: tried: '/usr/lib/swift/libswift_StringProcessing.dylib' (no such file), '/usr/local/lib/libswift_StringProcessing.dylib' (no such file), '/usr/lib/libswift_StringProcessing.dylib' (no such file)
[1] 31783 abort swift run -Xswiftc -enable-bare-slash-regex
Now that Xcode 14.1 and macOS 13 Ventura are available : I still can not get Xcode 14.1 to compile and run code with regex literals. This is a Swift PM only project - no .xcodeproj file, only Package.swift
Code :
let markdownFiles = /.md$/
Xcode Error : '/' is not a postfix unary operator
Package.swift :
platforms: [
.macOS(.v13)
],
Building and running from the command line, using -Xswiftc -enable-bare-slash-regex works.
You mean you opened the Package in Xcode? In that case since you can't set the setting in Xcode like a normal project, you have to set it in the package by passing what you passed at the command line as an unsafe flags in your Package.
I'm not sure if you're aware of it, but there is also the #/.../# syntax which works without any flags. That is what I would personally recommend for as long as your package needs to continue building on 5.7.
IMO, the rollout of bare-slash regexes has been less than successful. The efforts to try to mitigate source-breakage appear to have resulted in worse incompatibilities and greater confusion than we would have had to suffer in the first place.
I switched to the #/ ... /# syntax which is natively recognised. Thank you.
Unfortunately, most blog outlets picked up the / ... / syntax when Swift 5.7 went out. And none (that I found) are sharing details about additional command line switches required to make their examples compile.