<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="">Hello mailing-list,<div class=""><br class=""></div><div class="">I’m planning on adding options to the <font face="Menlo" class=""><b class="">swift build</b></font> command to allow building specific targets or products in the package and its dependencies. And allow <font face="Menlo" class=""><b class="">swift run</b></font> to execute arbitrary products in all the package’s dependencies. I’d like to get feedback on those before going forward or not.</div><div class=""><br class=""></div><div class=""><b class="">Motivation</b></div><div class=""><br class=""></div><div class="">The <font face="Menlo" class=""><b class="">swift build</b></font> command builds all the package targets but doesn’t allow building a specific target or a dependency’s product. This can be useful during development when concentrating on a single target.</div><div class=""><br class=""></div><div class="">The <font face="Menlo" class=""><b class="">swift run</b></font> command searches for an executable to run in the package dependency graph but won’t find it unless it is declared as a target dependency, which is rarely the case. For example, a package using the code generation capabilities of the executable product in the&nbsp;<a href="https://github.com/krzysztofzablocki/Sourcery" class="">Sourcery</a>&nbsp;package can’t run it with <font face="Menlo" class=""><b class="">swift run sourcery</b></font> unless the executable is added as a product dependency, linking the executable's module, which doesn't make much sense.</div><div class=""><br class=""></div><div class=""><b class="">Build</b></div><div class=""><br class=""></div><div class="">To solve both issues above, I was planning on adding 3 new options to the <font face="Menlo" class=""><b class="">swift build</b></font> tool:<br class=""><br class=""><font face="Menlo" class="">&nbsp; --target &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Specify target to build<br class="">&nbsp; --product &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Specify product to build from the package or its dependencies<br class="">&nbsp; --package &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Specify the package to build</font><br class=""><br class="">Here are different examples using those options:<br class=""><br class=""><font face="Menlo" class=""># Builds the Basic target from the root package.<br class="">$ swift build —target Basic<br class=""><br class=""># Searches for a product named SwiftyJSON in the root package and its dependencies and builds it.<br class="">$ swift build —product SwiftyJSON<br class=""><br class=""># Builds all products of the Sourcery package dependency.<br class="">$ swift build —package Sourcery<br class=""><br class=""># Builds the sourcery product from the Sourcery package.<br class="">$ swift build —package Sourcery —product sourcery</font><br class=""><br class="">To mirror the behavior of products in the package definition format in&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md" class="">SE-0146</a>:<br class=""><ul class=""><li class="">The <font face="Menlo" class=""><b class="">--target</b></font> option can not reference targets in dependent packages because they are considered as implementation details.</li><li class="">The <font face="Menlo" class=""><b class="">--product</b></font> option is generally enough to unambiguously reference a product because product names are expected to be unique. If it is not the case, the <font face="Menlo" class=""><b class="">--package</b></font> option is available for disambiguation.</li></ul><div class=""><b class="">Run</b></div><div class=""><br class=""></div>To allow the <font face="Menlo" class=""><b class="">swift run</b></font> command to reference products which are not depended on, the <font face="Menlo" class=""><b class="">swift build --package</b></font> option will also support referencing products which are not depended on. Indeed, as the <font face="Menlo" class=""><b class="">run</b></font> command implicitly runs the <font face="Menlo" class=""><b class="">build</b></font> command, it makes more sense to give both commands to same features.</div><div class=""><br class=""></div><div class="">Thanks in advance for your feedback,</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">David.</div></body></html>