-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Build tool plugins don't work on Windows #6859
Comments
|
Hm, I don't see any indication in the log that we compiled anything named |
I see this in
Probably a problem that this doesn't include |
Maybe, but as noted in the original report the previous 2 or 3 commits on that branch tried to remedy that problem and failed. |
We have |
I don't think you can remedy it from your code, it seems like it is constructing the name based on the target name? |
I'm pretty sure I can't work around it, especially because of #6524 |
I think what we're doing is we're producing the the executable with .exe but we write its path to the llbuild manifest without .exe (because of the code snippet pasted above), then when we ask llbuild to produce the output of the plugin, but llbuild tells us it can't find the executable because of the truncated path. |
I hope that means something to you and leads you to a fix! |
Don't think my theory is actually correct. At least I tried to reproduce by setting |
Ah, wait, maybe I can work around it by making a build tool plugin that merely issues shell commands rather than directly running an executable target? (maybe even |
No, the problem is still that invoking the shell executable is impossible on Windows. I am totally stuck without an SPM fix. |
FWIW, our project is dropping Windows support because of this. We're already not testing on Windows (just building) because some of our tests are generated by a plugin, but now we want to start generating source files. /cc @compnerd |
I wonder if you can get away with something like:
I believe that the core issue is the paths. |
@compnerd what would you put where the "..." go? A path including ".exe"? This project is trivial; if you can make the TestGenerationPlugin work, its tests will run on Windows and you can demonstrate the trick in a way I can reproduce it at scale. I pushed my changes to the windows branch where you can see how it fails in CI. |
I'm actually pretty close, having fixed the off-by-one errors in my use of Now on my local VM, the test generation executable runs and generates the appropriate swift file. The problem I'm having now is that the linker seems to be gathering the main from the build tool and the test runner and, of course, failing.
The last command issued by "swift build --build-tests -v" (replacing "C:\Users\dave\src\TestGeneration\.build\aarch64-unknown-windows-msvc\debug" with "Z" for concision) is, FWIW:
In CI, of course, the results are different. It looks like the SPM there thinks the build tool executable file doesn't end in ".exe" and therefore doesn't find it. |
Hmm, I think that the link error is because of tests for executables? Those don't work on Windows due to the way that they are executed (main is linked duplicately and relies on aliasing to not get picked up). Windows doesn't have any tools to emulate such horrible hacks. This one is on @neonichu. |
I think we have an existing GH issue to disable testing executables on Windows, but we never did? IIRC, @tomerd had some concerns. |
? Nothing in that reproducer is trying to test an executable. |
Could you try using a 5.9 nightly toolchain and bumping the tools-version of your example to 5.9? I wonder if #6723 is involved in the linker error you're seeing, it looks like we're incorrectly linking the |
Changing swift-tools-version to 5.9 using my current Swift installation has no apparent effect on the bug. I am running on Arm64, so I can't just grab the latest installer from the website. My current version is: Swift version 5.9-dev (LLVM ad32770d6738638, Swift 753d54576e043ca) |
Seems like it should be new enough to contain the fix for #6723, so I don't think that's the linker issue, then. |
The resource-generation branch of the same project actually demonstrates that the duplicate symbol problem is specific to tests that transitively depend on build tool plugins that depend on executable targets. An executable (which also has a |
…of course, occasionally, seemingly randomly, everything works:
|
I finally found a set of workarounds that portably allows tests to depend (indirectly) on build tool plugins that use Swift executables. I've factored and commented the code extensively if you care to study it, in the resource-generation branch. Almost everything of interest is here. |
I'm encountering this same issue Windows in Swift 5.9.1 when trying to link tests that transiently depend on a macro. Building for debugging...
lld-link: error: duplicate symbol: main
>>> defined at C:\\Users\\lynchsft\\e3\\.build\\x86_64-unknown-windows-msvc\\debug\\SymphonyPackageTests.build\\runner.swift.o
>>> defined at C:\\Users\\lynchsft\\e3\\.build\\x86_64-unknown-windows-msvc\\debug\\WoodwindMacros.build\\Plugin.swift.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[1/2] Linking C:\Users\lynchsft\e3\.build\x86_64-unknown-windows-msvc\debug\SymphonyPackageTests.xctest
error: fatalError
PS C:\Users\lynchsft\e3> As stated above, the main product links correctly and the tests compile. It's the final linking of the test runner that fails. Thank you in advance for your time and attention. |
I have workarounds for these problems; see https://github.com/dabrahams/SPMBuildToolSupport (don't use the |
Thank you for your response @dabrahams . I've read your solution twice, once before and once after posting. My reading says your solution applies to plugins but does not offer any support for macros. Am I misunderstanding? |
There's no specific support for macros. Do they interact with SPM somehow? My solution only addresses the title of this issue. (I've removed the option to run a swift script from the plugin; the swift interpreter simply doesn't work on Windows, and this is the nail in the coffin of any workaround). |
@neonichu Would you like to see this issue ticketed separately for macros? 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. |
What issues with macros do you see on Windows? Macros are not build tool plugins, a separate issues filed with self-contained repro steps would be much appreciated. |
As shown above I'm seeing the duplicate |
@lynchsft the duplicate |
I'm not sure we need a repro case for the macro issue tbh, I believe the issues here are well-known:
The combination of both leads to a pretty bad experience here. |
This is a trivial repo that reproduces the issue: @dabrahams Yes, the problem arises only on Windows. @neonichu The experience is bad (can't test my product on a supported Platform). |
@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. You can find the successful (can link tests on Windows) example in a branch of the same repo: |
|
Thank you for the cleanliness reminder dabrahms. My argument is that common libraries (the two used in this example are linked from the new Swift Package Index in the "macros" section) will force Windows development into an untenable position. |
Description
This PR on a minimal project demonstrates. You can see that builds succeed everywhere but Windows.
This is after I've worked around the SPM
Path
bugs. It complains that it can't find the executable used by the build tool. Various attempts to fix it by adding.exe
to the path are in the preceding commits on the same branch; none of them worked.Expected behavior
Project works on Windows just like on Mac and Linux.
Actual behavior
No response
Steps to reproduce
No response
Swift Package Manager version/commit hash
Swift Package Manager - Swift 5.8.1
Swift & OS version (output of
swift --version ; uname -a
)swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Darwin DaveA-MBP14.localdomain 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64
The text was updated successfully, but these errors were encountered: