Skip to content

Tests fail to link on Windows when macros are present #7174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lynchsft opened this issue Dec 10, 2023 · 3 comments
Open

Tests fail to link on Windows when macros are present #7174

lynchsft opened this issue Dec 10, 2023 · 3 comments

Comments

@lynchsft
Copy link

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):

Building for debugging...
lld-link: error: duplicate symbol: main
>>> defined at C:\Users\lynchsft\swift-windows-macro-testing\.build\x86_64-unknown-windows-msvc\debug\PowerAssertPlugin.build\PowerAssertPlugin.swift.o
>>> defined at C:\Users\lynchsft\swift-windows-macro-testing\.build\x86_64-unknown-windows-msvc\debug\SwiftWindowsPackageTestingPackageTests.build\runner.swift.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[238/239] Linking C:\Users\lynchsft\swift-windows-macro-testing\.build\x86_64-unknown-windows-msvc\debug\SwiftWindowsPackageTestingPackageTests.xctest
error: fatalError

Steps to reproduce

swift --test

Swift Package Manager version/commit hash

5.9.1-RELEASE

Swift & OS version (output of swift --version ; uname -a)

Swift version 5.9.1 (swift-5.9.1-RELEASE)
Target: x86_64-unknown-windows-msvc
MSYS_NT-10.0-22631 lynchal-z01 3.4.6.x86_64 2023-05-18 20:39 UTC x86_64 Msys
@MaxDesiatov
Copy link
Contributor

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)

@MaxDesiatov MaxDesiatov changed the title Tests Fail to link on Windows when macros are present, jeopardizing Swift's cross-platform support. Tests fail to link on Windows when macros are present Dec 14, 2023
@tishin
Copy link

tishin commented Dec 22, 2023

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

@lynchsft
Copy link
Author

lynchsft commented Jan 5, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants