kishikawakatsumi / swift-power-assert

Power Assert in Swift.
https://power-assert.swiftfiddle.com/
MIT License
486 stars 10 forks source link

linker command failed with exit code 1 #501

Closed nikitabobko closed 5 months ago

nikitabobko commented 5 months ago

Linker fails in the hello world project

Full project:

git clone git@github.com:nikitabobko/bug-reports.git --branch swift-power-assert-linker-failure
cd bug-reports
swift test

Fails with (The full build log out.txt):

Building for debugging...
ld: Undefined symbols:
  (extension in SwiftSyntaxBuilder):SwiftParser.SyntaxParseable.init(stringInterpolation: SwiftSyntaxBuilder.SyntaxStringInterpolation) -> A, referenced from:
      PowerAssertPlugin.(CodeGenerator in _08D5255B25F249C11B440531FBE8E5FA).expand<A where A: SwiftSyntax.SyntaxProtocol>(expression: A, parameters: PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA)) -> Swift.String in PowerAssertMacro.swift.o
      PowerAssertPlugin.PowerAssertRewriter.visit(SwiftSyntax.MemberAccessExprSyntax) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
  protocol conformance descriptor for SwiftSyntax.SourceFileSyntax : SwiftParser.SyntaxParseable in SwiftParser, referenced from:
      lazy protocol witness table accessor for type SwiftSyntax.SourceFileSyntax and conformance SwiftSyntax.SourceFileSyntax : SwiftParser.SyntaxParseable in SwiftParser in PowerAssertMacro.swift.o
  protocol conformance descriptor for SwiftSyntax.SourceFileSyntax : SwiftSyntax.SyntaxProtocol in SwiftSyntax, referenced from:
      lazy protocol witness table accessor for type SwiftSyntax.SourceFileSyntax and conformance SwiftSyntax.SourceFileSyntax : SwiftSyntax.SyntaxProtocol in SwiftSyntax in PowerAssertMacro.swift.o
  type metadata for SwiftSyntax.SourceFileSyntax, referenced from:
      PowerAssertPlugin.(CodeGenerator in _08D5255B25F249C11B440531FBE8E5FA).expand<A where A: SwiftSyntax.SyntaxProtocol>(expression: A, parameters: PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA)) -> Swift.String in PowerAssertMacro.swift.o
      lazy protocol witness table accessor for type SwiftSyntax.SourceFileSyntax and conformance SwiftSyntax.SourceFileSyntax : SwiftParser.SyntaxParseable in SwiftParser in PowerAssertMacro.swift.o
      lazy protocol witness table accessor for type SwiftSyntax.SourceFileSyntax and conformance SwiftSyntax.SourceFileSyntax : SwiftSyntax.SyntaxProtocol in SwiftSyntax in PowerAssertMacro.swift.o
  protocol conformance descriptor for SwiftSyntax.ClosureExprSyntax : SwiftSyntax.ExprSyntaxProtocol in SwiftSyntax, referenced from:
      lazy protocol witness table accessor for type SwiftSyntax.ClosureExprSyntax and conformance SwiftSyntax.ClosureExprSyntax : SwiftSyntax.ExprSyntaxProtocol in SwiftSyntax in PowerAssertRewriter.swift.o
  type metadata for SwiftSyntax.ClosureExprSyntax, referenced from:
      PowerAssertPlugin.PowerAssertRewriter.visit(SwiftSyntax.ClosureExprSyntax) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      lazy protocol witness table accessor for type SwiftSyntax.ClosureExprSyntax and conformance SwiftSyntax.ClosureExprSyntax : SwiftSyntax.ExprSyntaxProtocol in SwiftSyntax in PowerAssertRewriter.swift.o
  protocol conformance descriptor for SwiftSyntax.KeyPathExprSyntax : SwiftSyntax.SyntaxProtocol in SwiftSyntax, referenced from:
      lazy protocol witness table accessor for type SwiftSyntax.KeyPathExprSyntax and conformance SwiftSyntax.KeyPathExprSyntax : SwiftSyntax.SyntaxProtocol in SwiftSyntax in PowerAssertRewriter.swift.o
  type metadata for SwiftSyntax.KeyPathExprSyntax, referenced from:
      PowerAssertPlugin.PowerAssertRewriter.visit(SwiftSyntax.KeyPathExprSyntax) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      lazy protocol witness table accessor for type SwiftSyntax.KeyPathExprSyntax and conformance SwiftSyntax.KeyPathExprSyntax : SwiftSyntax.SyntaxProtocol in SwiftSyntax in PowerAssertRewriter.swift.o
  SwiftSyntax.LabeledExprSyntax.expression.getter : SwiftSyntax.ExprSyntax, referenced from:
      PowerAssertPlugin.(CodeGenerator in _08D5255B25F249C11B440531FBE8E5FA).generate() -> SwiftSyntax.ExprSyntax in PowerAssertMacro.swift.o
      PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA).init<A, B where A: SwiftSyntax.FreestandingMacroExpansionSyntax, B: SwiftSyntaxMacros.MacroExpansionContext>(macro: A, context: B) -> PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA) in PowerAssertMacro.swift.o
      PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA).init<A, B where A: SwiftSyntax.FreestandingMacroExpansionSyntax, B: SwiftSyntaxMacros.MacroExpansionContext>(macro: A, context: B) -> PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA) in PowerAssertMacro.swift.o
      PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA).init<A, B where A: SwiftSyntax.FreestandingMacroExpansionSyntax, B: SwiftSyntaxMacros.MacroExpansionContext>(macro: A, context: B) -> PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA) in PowerAssertMacro.swift.o
      PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA).init<A, B where A: SwiftSyntax.FreestandingMacroExpansionSyntax, B: SwiftSyntaxMacros.MacroExpansionContext>(macro: A, context: B) -> PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA) in PowerAssertMacro.swift.o
  SwiftSyntax.LabeledExprSyntax.init<A where A: SwiftSyntax.ExprSyntaxProtocol>(leadingTrivia: SwiftSyntax.Trivia?, _: SwiftSyntax.UnexpectedNodesSyntax?, label: SwiftSyntax.TokenSyntax?, _: SwiftSyntax.UnexpectedNodesSyntax?, colon: SwiftSyntax.TokenSyntax?, _: SwiftSyntax.UnexpectedNodesSyntax?, expression: A, _: SwiftSyntax.UnexpectedNodesSyntax?, trailingComma: SwiftSyntax.TokenSyntax?, _: SwiftSyntax.UnexpectedNodesSyntax?, trailingTrivia: SwiftSyntax.Trivia?) -> SwiftSyntax.LabeledExprSyntax, referenced from:
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o

...

  SwiftSyntaxBuilder.SyntaxStringInterpolation.init(literalCapacity: Swift.Int, interpolationCount: Swift.Int) -> SwiftSyntaxBuilder.SyntaxStringInterpolation, referenced from:
      PowerAssertPlugin.(CodeGenerator in _08D5255B25F249C11B440531FBE8E5FA).expand<A where A: SwiftSyntax.SyntaxProtocol>(expression: A, parameters: PowerAssertPlugin.(Parameters in _08D5255B25F249C11B440531FBE8E5FA)) -> Swift.String in PowerAssertMacro.swift.o
      PowerAssertPlugin.PowerAssertRewriter.visit(SwiftSyntax.MemberAccessExprSyntax) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
      PowerAssertPlugin.PowerAssertRewriter.(apply in _B676B0649EA1307B1860CA0ABF455ABB)(_: SwiftSyntax.ExprSyntax, column: Swift.Int) -> SwiftSyntax.ExprSyntax in PowerAssertRewriter.swift.o
  (extension in SwiftSyntaxBuilder):SwiftSyntaxBuilder.SyntaxExpressibleByStringInterpolation.init(stringLiteral: Swift.String) -> A, referenced from:
      PowerAssertPlugin.(CodeGenerator in _08D5255B25F249C11B440531FBE8E5FA).generate() -> SwiftSyntax.ExprSyntax in PowerAssertMacro.swift.o
      PowerAssertPlugin.(CodeGenerator in _08D5255B25F249C11B440531FBE8E5FA).generate() -> SwiftSyntax.ExprSyntax in PowerAssertMacro.swift.o
  protocol descriptor for SwiftCompilerPlugin.CompilerPlugin, referenced from:
      l_got.$s19SwiftCompilerPlugin0bC0Mp in PowerAssertPlugin.swift.o
  static (extension in SwiftCompilerPlugin):SwiftCompilerPlugin.CompilerPlugin.main() throws -> (), referenced from:
      static PowerAssertPlugin.PowerAssertPlugin.$main() throws -> () in PowerAssertPlugin.swift.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[0/1] Linking spmPackageTests
error: fatalError

The project listing

.
├── Package.resolved
├── Package.swift
├── Sources
│   ├── spm
│   │   └── spm.swift
│   └── spmTests
│       └── MyLibraryTests.swift
└── Tests
    └── spmTests
        └── spmTests.swift

6 directories, 5 files

import PackageDescription

let package = Package( name: "spm", products: [ // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "spm", targets: ["spm"] ), ], dependencies: [ .package( url: "https://github.com/kishikawakatsumi/swift-power-assert.git", from: "0.12.0" ), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. .target( name: "spm" ), .testTarget( name: "spmTests", dependencies: [ "spm", .product(name: "PowerAssert", package: "swift-power-assert"), ] ), ] )

- Sources/spmTests/MyLibraryTests.swift

import XCTest import PowerAssert @testable import MyLibrary

final class MyLibraryTests: XCTestCase { func testExample() { let a = 7 let b = 4 let c = 12

#assert(max(a, b) == c)

} }

nikitabobko commented 5 months ago

I just checked it on my other machine and, of course, it's not reproducible there

The problem is reproducible on my home machine M1 Pro. Sonoma 14.3.1

$ swift -v
Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0

And it's not reproducible on my work machine M3 Max. Sonoma 14.3.1

$ swift -v
Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
nikitabobko commented 5 months ago

Updating Xcode to 15.3 (15E204a) and consequently swift to 5.10 resolved the problem

Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0