[swift-evolution] [Proposal] Linux specific Package.swift file

Said Sikira saidsikira at gmail.com
Mon Nov 21 13:21:09 CST 2016

Hello everyone,

Currently, we use Package.swift manifest file when defining our packages.
Within the manifest file you define your targets, dependencies, excluded
folders etc. This works fairly well while you’re using frameworks that
exist on all supported platforms (ex. Foundation).

The main problem starts if you want to use code that exists only on macOS
platform, for example, if you want to use Objective C runtime calls or
UIKit. Then, you need to use bunch of #if os(Linux) to define what’s
available on Linux and what’s available on macOS. While this approach can
be non problematic for simple projects, it can introduce unnecessary
complexity if you have a large target and dependency graph.

One way people tackle this problem is writing something like this:

#if os(Linux)
let macOnlyTargets = []
let macOnlyTargets = [
    .Target(name: "SomeMacOSTarget")

This structure looks even worse if you need to define more complex
behaviors. For example, look at the RxSwift Package.swift
<https://github.com/ReactiveX/RxSwift/blob/master/Package.swift> file. In
my case, I try to write #if os(Linux) as little as possible which leads me
to writing my packages like:

#if os(Linux)
    // Define full Linux package
    let package = Package(...)
    // Define full macOS package
    let package = Package(..)


I propose that we support using different file for writing Linux package
manifests. This file could be named:

   - PackageLinux.swift
   - Package.Linux.swift
   - Package.linux.swift

Inside this file you would be able to define your package only for Linux in
the same way you’re defining one in regular Package.swift. The defined
behaviors of building a package would be:

   1. If building on Linux and PackageLinux.swift is present, use that file
   when building the package.
   2. If building on Linux and PackageLinux.swift is not present, use
   regular Package.swift manifest.
   3. If building on macOS always use Package.swift manifest.

Possible problems

This behavior would only introduce problems when SPM gains support for new
platforms, but then again, you would need to use new #if os(somethingNew)
Compatibility with current packages

This would be only a additive feature for Swift Package Manager and
backwards compatibility will be maintained.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161121/361fbf4c/attachment.html>

More information about the swift-evolution mailing list