swiftlang / swift-package-manager

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

[SR-12687] Let me add package dependencies that use CMake #4555

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12687
Radar rdar://problem/62895037
Original Reporter mattdipasquale (JIRA User)
Type New Feature
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 5 | |Component/s | Package Manager | |Labels | New Feature | |Assignee | None | |Priority | Medium | md5: a099242e58e51479ea615ca4bd9f1123

Issue Description:

When I try to add a package dependency to my app with the repository URL (eg, https://github.com/signalapp/libsignal-protocol-c.git) of a library that uses CMake to manage its build process, I get the error:

https://github.com/signalapp/libsignal-protocol-c.git has no Package.swift manifest for version 2.3.3

It'd be nice if the Swift Package Manager (SwiftPM) could recognize when a project uses CMake and then use CMake to compile that project.

Possible Solutions

  1. Maybe Xcode could come with CMake, and then SwiftPM could use CMake to build such projects when added as package dependencies. One problem with this approach for the project I used as an example (above) is that its maintainers set (via CMake) the project name to signal-protocol-c, but I don't think that's a valid name for a Swift module. So either SwiftPM could automatically set the module name to SignalProtocolC or allow me to specify a name when adding it as a package dependency. (I'd rather call it SignalProtocol anyway.) [Aside: Does SwiftPM even allow me to set the name of a package dependency? That'd especially be useful to resolve naming collisions, in cases where I wanted to add two or more different package dependencies with the same name.]

  2. Even if I had to install CMake myself and fork the libsignal-protocol-c repository and add a `Package.swift` file to it, it'd still be nice if I could put something in the `Package.swift` file that told SwiftPM to just use CMake to build the package. This would be helpful because I don't want to have to respecify all of the build configurations that are already specified in the project's CMakeLists.txt files.

Related

beccadax commented 4 years ago

@swift-ci create

swift-ci commented 4 years ago

Comment by Brennan Saeta (JIRA)

This is a great suggestion, and having this feature implemented would be very helpful to the Swift for TensorFlow project (among other projects at Google). Thanks!

sergeiromanov commented 1 year ago

This is much needed for our project too. We have a cmake c++ project which swift code depends on. Would be great if we could just add cmake project as a dependency to a swift target.

neonichu commented 1 year ago

I think doing this would be extremely problematic for build correctness and performance. By definition, SwiftPM would not be able to introspect what is happening in a CMake build, leading to poor parallelism and making it impossible to cache build artifacts in any meaningful way.

sergeiromanov commented 1 year ago

The only way to have cmake in xcode is to build .xcodeproj from it which I did. Is it possible to include it into SwiftPM?