swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.75k stars 1.35k forks source link

Add more support for building on Windows using SwiftPM #7873

Closed jakepetroules closed 3 months ago

jakepetroules commented 3 months ago

This continues from the support added in #7866.

While we can't build on Windows as-is due to exceeding the 65k exported symbol limit, in turn due to limitations in the build system, we can apply -static to all of the library targets which are known to be linked statically, in order to get that symbol count down.

Note that this uses unsafeFlags, which is normally not recommended, however given that we are already using unsafeFlags elsewhere in the manifest, this seems reasonable enough for now until we can improve support for static linking on Windows.

Building the test targets still exceeds the symbol count though.

jakepetroules commented 3 months ago

@swift-ci please smoke test

jakepetroules commented 3 months ago

@swift-ci please test

dschaefer2 commented 3 months ago

Can you create an issue for the Windows symbol count issue so we can track it and gather ideas? Thanks!

compnerd commented 3 months ago

Can you create an issue for the Windows symbol count issue so we can track it and gather ideas? Thanks!

I don't think that the issue is gathering ideas. In fact, I believe a radar exists for the issue. It is caused by SPM not knowing how too build libraries. A static and dynamic libraries are not products, but targets. The output type changes the required compiler flags, the generated code, and cannot be used interchangeably. The current model of building everything for a shared library, using it as an object library is fundamentally incorrect and results in the over-exported symbol list. The idea here is to simply do what CMake does and model the build properly, tracking the linkage type across each dependency edge and building the dependency appropriately.

owenv commented 3 months ago

https://github.com/swiftlang/swift-package-manager/issues/5597 contains some previous discussion

jakepetroules commented 3 months ago

@swift-ci please test windows

dschaefer2 commented 3 months ago

5597 contains some previous discussion

Cool. I think that's definitely the root of the problem. In the Windows world, DLLs are usually the default. I want to see if that solves the symbol count issue.

compnerd commented 3 months ago

I want to see if that solves the symbol count issue.

We know that it does - see the CMake build.

dschaefer2 commented 3 months ago

I want to see if that solves the symbol count issue.

We know that it does - see the CMake build.

Ah, I see :)

option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)

compnerd commented 3 months ago

Yes, we default to shared libraries and then selectively convert to static where it is profitable (the changes to make them static usually give stats on the size reduction).