SwiftCurrent
SwiftCurrent copied to clipboard
[Bug] [Triaged]: SwiftCurrent_CLI not building successfully in consuming iOS application
What happened?
While testing aspects of the new data-driven workflow feature, I created a brand new SwiftUI Project and added the SwiftCurrent, SwiftCurrent_SwiftUI, and SwiftCurrent_CLI dependencies via SPM.
Building after doing this resulted in 15 build errors in the SwiftCurrent_CLI target stemming from a library called "_InternalSwiftSyntaxParser". Likely due to this bit from the SwiftSyntax README:
Embedding SwiftSyntax in an Application
SwiftSyntax depends on the
lib_InternalSwiftSyntaxParser.dylib/.so
library which provides a C interface to the underlying Swift C++ parser. When you doswift build
SwiftSyntax links and uses the library included in the Swift toolchain. If you are building an application make sure to embed_InternalSwiftSyntaxParser
as part of your application's libraries.
You can either copy
lib_InternalSwiftSyntaxParser.dylib/.so
directly from the toolchain or even build it yourself from the Swift repository, as long as you are matching the same tags or branches in both the SwiftSyntax and Swift repositories. To build it for the host os (macOS/linux) use the following steps:
git clone https://github.com/apple/swift.git
./swift/utils/update-checkout --clone
./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build
Embedding in an iOS Application
You need to build
lib_InternalSwiftSyntaxParser.dylib
yourself, you cannot copy it from the toolchain. Follow the instructions above and change the invocation ofbuild-parser-lib
accordingly:
./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build-iossim --host iphonesimulator --architectures x86_64
./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build-ios --host iphoneos --architectures arm64
Version
SwiftCurrent Version 5.1.3 Xcode Version 13.3 macOS version 12.3
Relevant code sample
No response
Relevant log output
ld: warning: Could not find or use auto-linked library '_InternalSwiftSyntaxParser'
Undefined symbols for architecture x86_64:
"_swiftparse_syntax_structure_versioning_identifier", referenced from:
static SwiftSyntax.SyntaxParser.verifyNodeDeclarationHash() -> Swift.Bool in SwiftSyntax.o
"_swiftparse_diagnostic_get_fixit", referenced from:
closure #2 (Swift.UInt32) -> SwiftSyntax.FixIt in SwiftSyntax.Diagnostic.init(diag: Swift.UnsafeRawPointer, using: SwiftSyntax.SourceLocationConverter?) -> SwiftSyntax.Diagnostic in SwiftSyntax.o
"_swiftparse_diagnostic_get_range", referenced from:
closure #1 (Swift.UInt32) -> SwiftSyntax.SourceRange in SwiftSyntax.Diagnostic.init(diag: Swift.UnsafeRawPointer, using: SwiftSyntax.SourceLocationConverter?) -> SwiftSyntax.Diagnostic in SwiftSyntax.o
"_swiftparse_diagnostic_get_message", referenced from:
SwiftSyntax.Diagnostic.Message.init(Swift.UnsafeRawPointer) -> SwiftSyntax.Diagnostic.Message in SwiftSyntax.o
"_swiftparse_diagnostic_get_range_count", referenced from:
SwiftSyntax.Diagnostic.init(diag: Swift.UnsafeRawPointer, using: SwiftSyntax.SourceLocationConverter?) -> SwiftSyntax.Diagnostic in SwiftSyntax.o
"_swiftparse_diagnostic_get_fixit_count", referenced from:
SwiftSyntax.Diagnostic.init(diag: Swift.UnsafeRawPointer, using: SwiftSyntax.SourceLocationConverter?) -> SwiftSyntax.Diagnostic in SwiftSyntax.o
"_swiftparse_parse_string", referenced from:
closure #4 (Swift.UnsafePointer<Swift.Int8>) -> Swift.UnsafeMutableRawPointer? in static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
"_swiftparse_diagnostic_get_source_loc", referenced from:
SwiftSyntax.Diagnostic.init(diag: Swift.UnsafeRawPointer, using: SwiftSyntax.SourceLocationConverter?) -> SwiftSyntax.Diagnostic in SwiftSyntax.o
"_swiftparse_diagnostic_get_severity", referenced from:
closure #3 (Swift.UnsafeRawPointer?) -> () in static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
SwiftSyntax.Diagnostic.Message.init(Swift.UnsafeRawPointer) -> SwiftSyntax.Diagnostic.Message in SwiftSyntax.o
"_swiftparse_parser_create", referenced from:
static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
"_swiftparse_parser_set_node_handler", referenced from:
static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
"_swiftparse_parser_set_node_lookup", referenced from:
static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
"_swiftparse_parser_dispose", referenced from:
$defer #1 () -> () in static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
"_swiftparse_parser_set_diagnostic_handler", referenced from:
static SwiftSyntax.SyntaxParser.(parseRaw in _FF480AC1827F0899EF1492D28392D5EA)(Swift.String, SwiftSyntax.IncrementalParseTransition?, Swift.String, SwiftSyntax.DiagnosticEngine?) -> SwiftSyntax.RawSyntax in SwiftSyntax.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
These will be useful in solving this:
https://forums.swift.org/t/unable-to-compile-lib-internalswiftsyntaxparser-myself-from-latest-commit/38020/10 https://github.com/apple/swift-syntax
The 5.7 version of Swift-Syntax should do even better at fixing this issue.