<div dir="ltr"><div>I agree that portability is valuable and that it’s something that’s lacking in the c/makefile workflow. I just don’t think empty git repositories are the right solution. Perhaps we can get the best of both worlds with something like this in the SwiftPM:<br><br></div><span style="font-family:monospace,monospace"></span><div><br><span style="font-family:monospace,monospace">    .Package(include: &quot;cairo.h&quot;, link: &quot;cairo&quot; version: &quot;1.1.4&quot;, remote: &quot;</span><code>git://<a href="http://anongit.freedesktop.org/git/cairo">anongit.freedesktop.org/git/cairo</a></code><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">&quot;)</span><br><br></div><div>It would search for the <span style="font-family:monospace,monospace">cairo</span> lib on local machine in <span style="font-family:monospace,monospace">/usr/lib</span> and <span style="font-family:monospace,monospace">/usr/local/lib</span> , and if it can’t find it, or if the version doesn’t match, it will then download the C sources from the Cairo project’s *official* git repository and build it for you. Options could be added to specify alternative search paths or user prompts.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 29, 2017 at 12:42 PM, Ankit Aggarwal <span dir="ltr">&lt;<a href="mailto:ankit_aggarwal@apple.com" target="_blank">ankit_aggarwal@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I agree that libressl isn&#39;t a good example because of the security questions it raises, but libYAML is a good self contained package IMO. With custom targets layout proposal, the forks can be replaced by submodules. The problem with apt-get approach is, it takes away the &quot;portability&quot; from the package and it doesn&#39;t work in cases when you don&#39;t have full access to the system. That said, we do support this approach upto a certain degree. For e.g., swiftpm allows system package authors to declare hints for installing a system package dependency (via brew or apt-get). The /usr/include, /usr/lib etc are searched by default and non-standard paths are supported using pkg config. See: <a href="https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#require-system-libraries" target="_blank">https://github.com/apple/<wbr>swift-package-manager/blob/<wbr>master/Documentation/Usage.md#<wbr>require-system-libraries</a></div><div><div class="h5"><br><div><blockquote type="cite"><div>On 29-Mar-2017, at 10:55 PM, Kelvin Ma &lt;<a href="mailto:kelvinsthirteen@gmail.com" target="_blank">kelvinsthirteen@gmail.com</a>&gt; wrote:</div><br class="m_-8177756868474421089Apple-interchange-newline"><div><div dir="ltr"><div><div>I don’t think this is a good approach, the <a href="https://github.com/vapor/clibressl" target="_blank">libressl</a> repo is pretty much just the source code of the C library copied and pasted into a Swift module. That’s not a good thing™. The linux build paradigm is, the library maintains its own *official* source repository, the OS package distributors build it, users install the built dependencies with `sudo apt-get install libwhatever-dev` and the project source just builds and links to the library managed by the system.<br><br></div>Here you have to keep the forked library source up to date with the real library source, download it from the internet and build the entire project plus the libraries of which there could be many.<br><br></div>IMO the ideal way to import system libs would be for the user to install the dependency with `apt`, just as you would for any C program, have the `include` statements within the project source (like you would for any C program), and then have the paths to `/usr/include` and `/usr/lib` and `/usr/local/include` etc in a Makefile (or Package.swift). Usually it’s only “specialty” libraries like libspiro that people download and build manually, and even then, it’s downloaded from the Spiro project’s own official repository, not a third party fork. That’s the “accepted” way to do things, that linux ecosystems are designed around. Of course, this is very similar to the modulemap system that currently works in Swift. I just wish modulemaps could be streamlined a little, maybe combined with the top level Package.swift.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 29, 2017 at 1:03 AM, Ankit Aggarwal <span dir="ltr">&lt;<a href="mailto:ankit_aggarwal@apple.com" target="_blank">ankit_aggarwal@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On 29-Mar-2017, at 11:22 AM, <a href="mailto:kelvinsthirteen@gmail.com" target="_blank">kelvinsthirteen@gmail.com</a> wrote:</div><br class="m_-8177756868474421089m_-4824070616837390027Apple-interchange-newline"><div><div dir="auto"><div></div><div>I figured that was the intention, but we can’t be too surprised that everyone is maintaining personal modulemap repositories (and polluting search results — just try googling for a Swift PNG library!), especially when this central repo still doesn’t exist yet.</div></div></div></blockquote><div><br></div></span><div>Yeah thats unfortunate, maybe this will improve once we have an index.</div><span><br><blockquote type="cite"><div><div dir="auto"><div>If Swift ever comes on par with C in terms of being usage and the lingua franca of the FOSS world, I can see linux distributions shipping standard modulemaps the same way they ship C headers, but you have to admit this is years (decades?) away at best.</div><div><br></div><div>On the flip side of it, it does wonders in terms of motivating people (me at least) to start writing pure Swift replacements for some of these C libraries (like libpng)…</div></div></div></blockquote><div><br></div></span><div>I think its better to reuse existing libraries than writing from scratch (unless really needed). A good approach that works is &quot;porting&quot; these libraries to build with SwiftPM, see: <a href="https://github.com/jpsim/Yams" target="_blank">libYAML</a>, <a href="https://github.com/vapor/clibressl" target="_blank">libressl</a>. However, this porting can be difficult to do right but it should become much easier once we have build settings support and <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170320/034469.html" target="_blank">custom targets layout</a>.</div><div><div class="m_-8177756868474421089h5"><br><blockquote type="cite"><div><div dir="auto"><div><br>On Mar 29, 2017, at 12:42 AM, Ankit Aggarwal &lt;<a href="mailto:ankit_aggarwal@apple.com" target="_blank">ankit_aggarwal@apple.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I think the idea was that there will be one such repository which other packages can use, that too only until the system libraries start shipping their standard modulemap. I thought we had this written down in our documentation somewhere but couldn&#39;t find it.<div><br></div><div>Maybe Daniel can expand on this.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 29, 2017 at 10:48 AM, Kelvin Ma via swift-build-dev <span dir="ltr">&lt;<a href="mailto:swift-build-dev@swift.org" target="_blank">swift-build-dev@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This worked! Thanks! But why is having empty git repositories strewn about the “correct” way? System libraries should be imported from within the project, as they are in C. You have to admit it’s getting quite silly that Swift devs keep repositories like <a href="https://github.com/kelvin13/swift-zlib" target="_blank">these</a> on our github accounts. That zlib repository contains exactly ten lines of code. I used to have 6 or 7 repos like that one up there before I got rid of them and switched to local repos. <br></div><div class="m_-8177756868474421089m_-4824070616837390027HOEnZb"><div class="m_-8177756868474421089m_-4824070616837390027h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 29, 2017 at 12:03 AM, Ankit Aggarwal <span dir="ltr">&lt;<a href="mailto:ankit_aggarwal@apple.com" target="_blank">ankit_aggarwal@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">In this case, these are just umbrella headers. If your modulemap contains absolute path to the header, then you don&#39;t need the header files, but SwiftPM will probably warn about this. Note that this is a &quot;hack&quot; to have system packages inside a single repository. The correct way is to have system package as a separate published package which you only need to do once.<div><div class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712h5"><div><br><div><blockquote type="cite"><div>On 29-Mar-2017, at 10:26 AM, Kelvin Ma &lt;<a href="mailto:kelvinsthirteen@gmail.com" target="_blank">kelvinsthirteen@gmail.com</a>&gt; wrote:</div><br class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252Apple-interchange-newline"><div><div dir="ltr">I will try this, but why are the header files inside the Sources directory? System headers should live in /usr/include…<br><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 28, 2017 at 11:48 PM, Ankit Aggarwal <span dir="ltr">&lt;<a href="mailto:ankit_aggarwal@apple.com" target="_blank">ankit_aggarwal@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div>Apologies for not replying to this earlier. <div><br></div><div>You can have multiple targets in a single package. Each target can either be Swift or C-family. The type of target is determined by the sources contained in it (*.c/*.cpp etc means C target, *.swift means Swift target). So if you want to create multiple C targets, this layout should work:<br></div><div><br></div><div>Package.swift</div><div>Sources/</div><div>    Bitmap</div><div>    Cubify</div><div>    Cairo/anchor.c &lt;---- This is just an empty file to tell SwiftPM that this is a C target.</div><div>    Cairo/include/Cairo.h<br></div><div>    Cairo/include/module.modulemap<br></div><div><div>    GLFW/anchor.c</div><div>    GLFW/include/GLFW.h<br></div><div>    GLFW/include/module.modulema<wbr>p</div></div><div><br></div><div>The modulemap is automatically generated, if not provided. This is a package which contains two targets (one C and one Swift): <a href="https://github.com/jpsim/Yams" target="_blank">https://github.com/jpsim/Yams</a></div><div><br></div><div>If you need to pass a bunch of compiler flags, you can use SwiftPM&#39;s pkgConfig feature but that will require you to have a separate repository for Cario and GLFW. You can experiment without creating tags using the <a href="https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#editable-packages" target="_blank">edit feature</a>.</div><div><br></div><div>PS: You can join SwiftPM slack channel for quicker turn around time: <a href="https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20160530/000497.html" target="_blank">https://lists.swift.org/<wbr>pipermail/swift-build-dev/Week<wbr>-of-Mon-20160530/000497.html</a></div><div><br></div><div>Thanks,</div><div>Ankit</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252h5">On Wed, Mar 29, 2017 at 6:06 AM, Michael Ilseman via swift-build-dev <span dir="ltr">&lt;<a href="mailto:swift-build-dev@swift.org" target="_blank">swift-build-dev@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252h5"><div style="word-wrap:break-word">This is into uncharted territory for me, but it seems you’re building with SwiftPM. You’ll probably want to configure extra compiler flags if that’s possible. You could also bite the bullet and build your C libraries with SwiftPM as well. Hopefully someone on swift-build-dev can help you out.<div><br></div><div>CC-ing Ankit<div><br></div><div><br><div><blockquote type="cite"><span><div>On Mar 28, 2017, at 5:09 PM, Kelvin Ma &lt;<a href="mailto:kelvinsthirteen@gmail.com" target="_blank">kelvinsthirteen@gmail.com</a>&gt; wrote:</div><br class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393Apple-interchange-newline"></span><div><div dir="ltr"><span>How do I compile a project with many modules? My tree looks like this:<br><br></span><span id="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393cid:ii_j0u7s58g0_15b1765689e74dba">&lt;Selection_001.png&gt;</span><br>​<br></div><span><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 28, 2017 at 12:47 PM, Michael Ilseman <span dir="ltr">&lt;<a href="mailto:milseman@apple.com" target="_blank">milseman@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Sure! In this example, I have built libgit2. I have a directory called Git, and inside that I have the following module map:</div><div><br></div><div>module Git [system] {<br>       header &quot;&lt;my path&gt;/libgit2/include/git2.h&quot;<br>       export *<br>}<br><br></div><div>When I run, I use:</div><div><br></div><div>swift -I &lt;path-to-“Git”-directory&gt; -L &lt;path-to-built-libgit2&gt; -lgit2 foo.swift</div><div><br></div><div>inside foo.swift I can:</div><div><br></div><div>import Git</div><div>// … use libGit2</div><div><br></div><div><br></div><div>Read more about how to write a more appropriate module.map file for your purposes at <a href="https://clang.llvm.org/docs/Modules.html" target="_blank">https://clang.llvm.org/docs<wbr>/Modules.html</a>. For example, you might be able to define link flags inside the module.map, use umbrella directories, submodules, etc.</div><div><div class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393h5"><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On Mar 28, 2017, at 6:27 AM, Kelvin Ma &lt;<a href="mailto:kelvinsthirteen@gmail.com" target="_blank">kelvinsthirteen@gmail.com</a>&gt; wrote:</div><br class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393m_8432716316639870101Apple-interchange-newline"><div><div dir="ltr">Can you give an example?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 27, 2017 at 3:59 PM, Michael Ilseman <span dir="ltr">&lt;<a href="mailto:milseman@apple.com" target="_blank">milseman@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sure. At a low level, you can create a module.map file and use -L/-l flags in your invocation of Swift. If you want to do so at a higher level, then perhaps SwiftPM can. CCing swift-build-dev for the SwiftPM part.<br>
<span class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393m_8432716316639870101HOEnZb m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393m_8432716316639870101im"><br>
<br>
&gt; On Mar 26, 2017, at 3:20 PM, Kelvin Ma via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Idk if this has been asked before, but is there a way to import C libraries into a Swift project without creating a local git repo? Preferably something similar to C where you can just `#include` headers and then specify the link flags (in Package.swift?)<br>
&gt;<br>
&gt; It’s getting very cumbersome to make a bunch of empty git repos just to use libglfw or libcairo.<br>
</span><div class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393m_8432716316639870101HOEnZb"><div class="m_-8177756868474421089m_-4824070616837390027m_1344320728419705712m_184815635025639252m_-2620461552307021340m_1575458746599134393m_8432716316639870101h5">&gt; ______________________________<wbr>_________________<br>
&gt; swift-users mailing list<br>
&gt; <a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br>
</div></div></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div>
</span></div></blockquote></div><br></div></div></div><br></div></div><span>______________________________<wbr>_________________<br>
swift-build-dev mailing list<br>
<a href="mailto:swift-build-dev@swift.org" target="_blank">swift-build-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-build-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-build-dev</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div></div></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
swift-build-dev mailing list<br>
<a href="mailto:swift-build-dev@swift.org" target="_blank">swift-build-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-build-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-build-dev</a><br>
<br></blockquote></div><br></div>
</div></blockquote></div></div></blockquote></div></div></div><br></div></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div>