by js2 · 4y ago · 0 comments
I guess the bug is apparently in the Swift runtime itself, and since Swift 5.0 and ABT stability, the runtime version is tied to the OS version.
https://www.swift.org/blog/abi-stability-and-apple/
But I think that only applies to deployments via the App Store. I think for local development you can run against the current runtime by setting the TOOLCHAINS environment variable (you may also need to set SDKROOT).
https://www.swift.org/getting-started/#on-macos
ETA. Apple does not make it easy to replace the runtime, but I got it to work like this:
$ sw_vers
ProductName: macOS
ProductVersion: 12.6
BuildVersion: 21G115
$ cat foo.swift
let a = "gnmCjzwnmCPTPhBwPjzBgqPjllJJSWlhfhQDSrpJRhDSlfJl"
let b = "rLHNHrLHVNbVHMMctZFHsbcsDSDWpSDSGfSRsRWSRllfGSSG"
let c = "NNtdMVrLNdZNvLvLZrzCndqBgwwPmwgjggBn"
var s1 = Set(a)
s1.formIntersection(b)
s1.formIntersection(c)
print(s1)
var s2 = Set(a)
s2.formIntersection(Set(b))
s2.formIntersection(Set(c))
print(s2)
$ swiftc -version
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: arm64-apple-macosx12.0
$ swiftc foo.swift
$ ./foo
["P", "r", "C", "z", "w", "m", "B", "q", "j", "g", "n"]
["r"]
$ otool -L foo
foo:
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
/usr/lib/swift/libswiftCore.dylib (compatibility version 1.0.0, current version
$ DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-5.7.1-RELEASE.xctoolchain/usr/lib/swift/macosx ./foo
["r"]
["r"]
Note that I had to download and install Swift 5.7.1 from swift.org. Trying to use libswiftCore.dylib from Xcode-14.1 is no bueno: $ /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -version
Xcode 14.1
Build version 14B47b
$ DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx ./foo
["B", "P", "q", "C", "r", "n", "j", "w", "m", "z", "g"]
["r"]
Oh, it's because /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/macosx/libswiftCore.dylib is x86_64 only for some reason and I'm testing on an MBA M1.The dylibs under /Library/Developer/Toolchains/swift-5.7.1-RELEASE.xctoolchain/usr/lib/swift/macosx are arm64 and x86_64.
WTF Apple?
$ otool -L AdventOfCode2022
AdventOfCode2022:
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
/usr/lib/swift/libswiftCore.dylib (compatibility version 1.0.0, current version 5.7.1)
/usr/lib/swift/libswiftCoreFoundation.dylib (compatibility version 1.0.0, current version 120.100.0, weak)
/usr/lib/swift/libswiftDarwin.dylib (compatibility version 1.0.0, current version 0.0.0, weak)
/usr/lib/swift/libswiftDispatch.dylib (compatibility version 1.0.0, current version 17.0.0, weak)
/usr/lib/swift/libswiftIOKit.dylib (compatibility version 1.0.0, current version 1.0.0, weak)
/usr/lib/swift/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 6.0.0, weak)
/usr/lib/swift/libswiftXPC.dylib (compatibility version 1.0.0, current version 6.0.0, weak)
/usr/lib/swift/libswiftFoundation.dylib (compatibility version 1.0.0, current version 1.0.0, weak)
Not only does it say that libswiftcore is 5.7.1, but that /usr/lib/swift folder doesn't have any of those files there. Very very confusing. I don't like any of this.I appreciate your write-up and research into all of this though! I tried googling for what runtime version of Swift is installed in Monterey and couldn't find anything. This is incredibly opaque.
I wasn't able to get `swift repl` to use anything but the system runtime, maybe because it's signed. Maybe it can be made to work by stripping the out the signing but to be quite honest, I'm done with this at this point.
I've been happily using Python to solve AoC. Y'all gluttons for punishment doing this in Swift:
def part2():
total = 0
group = []
for line in INPUT.splitlines():
group.append(line.strip())
if len(group) < 3:
continue
common = list(set(group[0]) & set(group[1]) & set(group[2]))
group = []
assert len(common) == 1
c = common[0]
p = ascii_letters.index(c) + 1
# print(c, p)
total += p
print(total)