<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 22, 2016, at 3:28 AM, rintaro ishizaki via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi Said,</div><div class=""><br class=""></div><div class="">Since `Package.targets` is a mutable public property,</div><div class=""><a href="https://github.com/apple/swift-package-manager/blob/master/Sources/PackageDescription/Package.swift#L60-L67" class="">https://github.com/apple/swift-package-manager/blob/master/Sources/PackageDescription/Package.swift#L60-L67</a></div><div class="">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" class="">https://github.com/apple/swift-package-manager/blob/master/Documentation/Reference.md#customizing-builds</a></div></div></blockquote><div><br class=""></div><div>Right. If they were immutable, it seems that another (more general) solution to this would be to relax the restrictions around #if checks, enabling them to apply to elements in lists. That would allow you to write:</div><div><br class=""></div><div><div class="">let macOnlyTargets = [</div><div class="">#if !os(Linux)</div><div class=""> .Target(name: "SomeMacOSTarget")</div><div>#end</div><div class="">]</div><div class=""><br class=""></div></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-11-22 4:21 GMT+09:00 Said Sikira via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><p class="">Hello everyone,</p><p class="">Currently, we use <code class="">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 class="">Foundation</code>). </p><p class="">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 class="">#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 class="">One way people tackle this problem is writing something like this:</p>
<pre class=""><code class="m_-3603044645591756360swift">#if os(Linux)
let macOnlyTargets = []
#else
let macOnlyTargets = [
.Target(name: "SomeMacOSTarget")
]
#end
</code></pre><p class="">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" class="">RxSwift <code class="">Package.swift</code></a> file. In my case, I try to write <code class="">#if os(Linux)</code> as little as possible which leads me to writing my packages like:</p>
<pre class=""><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" class="">Proposal</h3><p class="">I propose that we support using different file for writing Linux package manifests. This file could be named:</p>
<ul class="">
<li class=""><code class="">PackageLinux.swift</code></li>
<li class=""><code class="">Package.Linux.swift</code></li>
<li class=""><code class="">Package.linux.swift</code></li>
</ul><p class="">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 class="">Package.swift</code>. The defined behaviors of building a package would be:</p>
<ol class="">
<li class="">If building on Linux and <code class="">PackageLinux.swift</code> is present, use that file when building the package.</li>
<li class="">If building on Linux and <code class="">PackageLinux.swift</code> is not present, use regular <code class="">Package.swift</code> manifest.</li>
<li class="">If building on macOS always use <code class="">Package.swift</code> manifest.</li>
</ol>
<h3 id="m_-3603044645591756360possibleproblems" class="">Possible problems</h3><p class="">This behavior would only introduce problems when SPM gains support for new platforms, but then again, you would need to use new <code class="">#if os(somethingNew)</code> checks.</p>
<h3 id="m_-3603044645591756360compatibilitywithcurrentpackages" class="">Compatibility with current packages</h3><p class="">This would be only a additive feature for Swift Package Manager and backwards compatibility will be maintained. </p></div>
<br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>