Open lynchsft opened 12 months ago
Is this reproducible for you with latest development snapshots? (at the moment of writing it's https://download.swift.org/development/windows10/swift-DEVELOPMENT-SNAPSHOT-2023-11-27-a/swift-DEVELOPMENT-SNAPSHOT-2023-11-27-a-windows10.exe)
It is reproducible with the latest snapshot:
> swift --version
Swift version 5.11-dev (LLVM d50917983d84235, Swift 3f06b5efd0ebcfb)
Target: x86_64-unknown-windows-msvc
I have a slightly different example though:
https://github.com/tishin/MacroTestIssue
It has two targets - an empty macro implementation target with a @main
attribute (which I believe causes this issue)
import SwiftCompilerPlugin
import SwiftSyntaxMacros
@main
struct MyMacroPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
]
}
And a trivial test target:
import XCTest
final class MyMacroTests: XCTestCase {
func testMacro() throws {
XCTAssertTrue(true)
}
}
Running swift test -v
using the latest snapshot (as well as 5.9.2 release) fails with the duplication error:
lld-link: error: duplicate symbol: main
>>> defined at C:\Projects\MacroTestIssue\.build\x86_64-unknown-windows-msvc\debug\MyMacroMacros.build\MyMacroMacro.swift.o
>>> defined at C:\Projects\MacroTestIssue\.build\x86_64-unknown-windows-msvc\debug\MyMacroPackageTests.build\runner.swift.o
Thank you @tishin . @MaxDesiatov, @neonichu Are you able to provide a read on the situation? Have I concluded wrongly that as time goes on this bug will strand Windows projects in the past?
Description
Tests fail to link on Windows using swift 5.9.1-RELEASE when macros are present.
This is a trivial repo that reproduces the issue: https://github.com/lynchsft/swift-windows-macro-testing
The locus of this problem is on Windows platform, but I conclude that it indirectly negatively affects the entire Swift community. As macros proliferate through common libraries, all swift-on-windows tools will either have to abandon testing or wholly abandon windows as a platform. Neither of these outcomes speaks well of the "swift is a cross platform language" story.
Particularly, I'm asserting that this is a rapidly worsening problem because library authors that don't usually concern themselves with Windows are eagerly adopting macros feature. Soon, the libraries that Windows projects currently rely on will be un-ingestiable, effectively locking our dependences at the last-macro-free version. This in turn, is a security problem as code-currency (up-to-date dependencies) are a crucial topic for averting and responding to security threats.
@neonichu, @MaxDesiatov During construction of that ^^ trivial reproduction repo, I actually encountered a success case, where I WAS able to ingest a macro and use it on Windows. The linker error did not arise. Including this state in case its a useful resource to have.
Branch: success_case Repo: https://github.com/lynchsft/swift-windows-macro-testing
Expected behavior
The tests should link and run properly.
Actual behavior
The tests fail to link (compilation succeeds):
Steps to reproduce
swift --test
Swift Package Manager version/commit hash
5.9.1-RELEASE
Swift & OS version (output of
swift --version ; uname -a
)