undefined symbols (RegexParser)
svanimpe opened this issue · comments
Steps to reproduce:
- Create a new package with
swift package init --type executable
- Add JavaScriptKit as a dependency. My Package.swift file is as follows:
// swift-tools-version: 5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "RegexParserIssue", dependencies: [ .package(url: "https://github.com/swiftwasm/JavaScriptKit", from: "0.19.0") ], targets: [ .executableTarget( name: "RegexParserIssue", dependencies: [ .product(name: "JavaScriptKit", package: "JavaScriptKit") ] ), ] )
- Build using:
swift build --triple wasm32-unknown-wasi -Xswiftc -static-stdlib -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor -Xlinker --export=__main_argc_argv
This results in a long list of errors like:
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser3ASTV28GlobalMatchingOptionSequenceVMn
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser13PrettyPrinterVMn
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser9_TreeNodeMp
wasm-ld: error: /Users/steven/Library/Developer/Toolchains/swift-wasm-6.0-SNAPSHOT-2024-04-16-a.xctoolchain/usr/lib/swift_static/wasi/libswift_StringProcessing.a(_StringProcessing.o): undefined symbol: $s12_RegexParser9_TreeNodeP8childrenSayxGSgvgTq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Workaround:
Add import _RegexParser
in a Swift file.
Environment:
swift-wasm-6.0-SNAPSHOT-2024-04-16-a-macos_x86_64
I've also encountered this issue when using JSONEncoder
from Foundation, in a project that doesn't use JavaScriptKit.
https://github.com/kateinoigakukun/swiftwasm-issue-gh-5580
I finally could reproduce the issue and it's already incidentally fixed by --gc-sections
support in the main branch. So it's reproducible with 6.0 snapshot.
But the root cause is still unclear... There should be something wrong in incremental compilation of swift-driver, so it might happen again