apple / swift-numerics

Advanced mathematical types and functions for Swift
Apache License 2.0
1.69k stars 147 forks source link

[CMake] [Windows] Add command plugins #241

Closed benrimmington closed 1 year ago

benrimmington commented 1 year ago

Resolves #199

Command plugins require swift-tools-version: 5.6 or later.

benrimmington commented 1 year ago

The first half of this PR generates all existing files, making it easier to check the results. The second half reduces the number of generated files to:

  1. Sources/CMakeLists.txt
  2. Tests/CMakeLists.txt
  3. Tests/WindowsMain.swift

I haven't tested the new CMake build. Only a few changes to the plugin were needed (in commit 50cd09373b756cd06b8c53ec714125ace374ea02).

I'm not sure about the two package manifests. If I change Package.swift to use swift-tools-version:5.8 then SwiftPM and Xcode show an error. However, it works if I swap the manifests, so that Package.swift uses 5.4, and the plugins are in Package@swift-5.6.swift (or Package@swift-5.8.swift).

stephentyrone commented 1 year ago

I'm not entirely sure that this is what we want to do; if someone is using SwiftPM to invoke the plugins, why wouldn't they just use SwiftPM to build the package as well? It may be that we simply want to remove CMake support as SwiftPM matures on Windows...

benrimmington commented 1 year ago

I'm not entirely sure that this is what we want to do; if someone is using SwiftPM to invoke the plugins, why wouldn't they just use SwiftPM to build the package as well?

SwiftPM would be used to build on macOS and Linux. However, the CMake for Windows support needs to be kept in sync by someone. This can either be written by hand, or automated by commands. In other words, swift package generate-windows-main in this PR has the same purpose as the deprecated swift test --generate-linuxmain command.


It may be that we simply want to remove CMake support as SwiftPM matures on Windows...

This would be the best outcome, but I have no idea when SwiftPM for Windows will be ready.

CMake and SwiftPM will both be required for parts of the Swift compiler: https://forums.swift.org/t/implementing-parts-of-the-swift-compiler-in-swift/59524

benrimmington commented 1 year ago

I'll move the command plugins to a new package.