<div dir="ltr"><div>Hi Said,</div><div><br></div><div>Since `Package.targets` is a mutable public property,</div><div><a href="https://github.com/apple/swift-package-manager/blob/master/Sources/PackageDescription/Package.swift#L60-L67">https://github.com/apple/swift-package-manager/blob/master/Sources/PackageDescription/Package.swift#L60-L67</a></div><div>you can freely mutate it later, as documented in</div><a href="https://github.com/apple/swift-package-manager/blob/master/Documentation/Reference.md#customizing-builds">https://github.com/apple/swift-package-manager/blob/master/Documentation/Reference.md#customizing-builds</a><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-11-22 4:21 GMT+09:00 Said Sikira via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p>Hello everyone,</p>
<p>Currently, we use <code>Package.swift</code> 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. <code>Foundation</code>). </p>
<p>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 <code>#if os(Linux)</code> 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. </p>
<p>One way people tackle this problem is writing something like this:</p>
<pre><code class="m_-3603044645591756360swift">#if os(Linux)
let macOnlyTargets = []
#else
let macOnlyTargets = [
.Target(name: "SomeMacOSTarget")
]
#end
</code></pre>
<p>This structure looks even worse if you need to define more complex behaviors. For example, look at the <a href="https://github.com/ReactiveX/RxSwift/blob/master/Package.swift" target="_blank">RxSwift <code>Package.swift</code></a> file. In my case, I try to write <code>#if os(Linux)</code> as little as possible which leads me to writing my packages like:</p>
<pre><code class="m_-3603044645591756360swift">#if os(Linux)
// Define full Linux package
let package = Package(...)
#else
// Define full macOS package
let package = Package(..)
#end
</code></pre>
<h3 id="m_-3603044645591756360proposal">Proposal</h3>
<p>I propose that we support using different file for writing Linux package manifests. This file could be named:</p>
<ul>
<li><code>PackageLinux.swift</code></li>
<li><code>Package.Linux.swift</code></li>
<li><code>Package.linux.swift</code></li>
</ul>
<p>Inside this file you would be able to define your package only for Linux in the same way you’re defining one in regular <code>Package.swift</code>. The defined behaviors of building a package would be:</p>
<ol>
<li>If building on Linux and <code>PackageLinux.swift</code> is present, use that file when building the package.</li>
<li>If building on Linux and <code>PackageLinux.swift</code> is not present, use regular <code>Package.swift</code> manifest.</li>
<li>If building on macOS always use <code>Package.swift</code> manifest.</li>
</ol>
<h3 id="m_-3603044645591756360possibleproblems">Possible problems</h3>
<p>This behavior would only introduce problems when SPM gains support for new platforms, but then again, you would need to use new <code>#if os(somethingNew)</code> checks.</p>
<h3 id="m_-3603044645591756360compatibilitywithcurrentpackages">Compatibility with current packages</h3>
<p>This would be only a additive feature for Swift Package Manager and backwards compatibility will be maintained. </p></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>