<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 Dec 20, 2015, at 3:51 PM, Daniel Dunbar <<a href="mailto:daniel_dunbar@apple.com" class="">daniel_dunbar@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 17, 2015, at 1:40 PM, Tom Sheffler 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">I’m learning about Swift on Linux and using modules to wrap C libraries. One of the things I wanted to do was use libdispatch with blocks from Swift. I thought it would be easy to use a module to wrap <dispatch/dispatch.h>.<div class=""><br class=""></div><div class="">I made a module called “CDispatch” with a module.modulemap like this</div><div class=""><br class=""></div><div class="">=======</div><div class=""><div class="">module CDispatch [system] {</div><div class=""> header "/usr/include/dispatch/dispatch.h"</div><div class=""> export *</div><div class=""> link "dispatch"</div><div class="">}</div></div><div class="">========</div><div class=""><br class=""></div><div class="">Then I created a little demo project called gcd4 whose Source/main.swift prints some things and then uses a dispatch queue and a block to print a message after 2 seconds delay.</div><div class=""><br class=""></div><div class="">=========</div><div class=""><div class="">CDispatch.dispatch_after(time, queue, {</div><div class=""> print("Delayed!")</div><div class="">})</div></div><div class="">========</div><div class=""><br class=""></div><div class="">The entire project is checked in at <a href="https://github.com/sheffler/gcd4" class="">https://github.com/sheffler/gcd4</a></div><div class="">and the CDispatch module is checked in at <a href="https://github.com/sheffler/CDispatch" class="">https://github.com/sheffler/CDispatch</a></div><div class=""><br class=""></div><div class="">If I try to “swift build” the project, it almost works but reports that dispatch_after is not found. It seems that this function is not defined if the “blocks" feature is not provided at compilation time.</div><div class=""><br class=""></div><div class="">========</div><div class=""><div class="">Compiling Swift Module 'gcd4' (1 sources)</div><div class="">/home/sheffler/swift/gcd4/Sources/main.swift:42:1: error: module 'CDispatch' has no member named 'dispatch_after'</div><div class="">CDispatch.dispatch_after(time, queue, {</div><div class="">^~~~~~~~~ ~~~~~~~~~~~~~~</div><div class=""><unknown>:0: error: build had 1 command failures</div><div class="">swift-build: exit(1): ["/home/sheffler/src/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/swift-build-tool", "-f", "/home/sheffler/swift/gcd4/.build/debug/gcd4.o/llbuild.yaml”]</div></div><div class="">========</div><div class=""><br class=""></div><div class="">I got the demo program to work by first using “swift build” to retrieve the CDispatch module, and then manually running the compiler like this (and including the “-Xcc -fblocks” arguments)</div><div class=""><br class=""></div><div class="">swiftc -v -o gcd4 Sources/main.swift -I .build/debug -j8 -Onone -g -Xcc -fblocks -Xcc -F-module-map=Packages/CDispatch-1.0.0/module.modulemap -I Packages/CDispatch-1.0.0 -I /usr/local/include</div><div class=""><br class=""></div><div class="">This is all pretty neat! I’ve got blocks, dispatch queues and ARC on Ubuntu. I have one question and one remark.</div><div class=""><br class=""></div><div class="">- Am i missing something about how to create the CDispatch module? Why can’t “swift build” build this?</div></div></div></blockquote><div class=""><br class=""></div>This is mostly an oversight, the libdispatch port has been coming up and you are perhaps the first person to try to integrate all of these things.</div></div></blockquote><div><br class=""></div>It’s not normal, i know. I’m looking forward to using blocks/dispatch on Linux for a media project.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">I'm not sure yet exactly how we should resolve this, it might be the case that swiftc should just default to enabling blocks support in the Clang importer. In any case, can you open a specific bug in JIRA for this issue?</div></div></blockquote><div><br class=""></div>I’ll add the issue.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">- Creating Git repositories for simple modules that wrap a single library and include a header file or two seems like too much. I would love to have been able to create a sub-directory in my project with a modulemap that includes <dispatch/dispatch.h> and links libdispatch.so</div></div></div></blockquote><div class=""><br class=""></div><div class="">There will be an easier avenue to getting this working once we have some amount of C support in the package manager.</div><div class=""><br class=""></div><div class="">Even then, one pro of encouraging the separate definition of module map packages is so that they can be used by other people. It is cumbersome until we have a the ecosystem of those packages (and easy ways for people to find them), but it would be worse if they never ever ended up being shared.</div></div></div></blockquote><div><br class=""></div><div>I think the package manager direction for Swift is great actually. I just took the opportunity to share some of my early experiences whil I had the chance.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div> - Daniel</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">Thanks</div><div class="">Tom</div><div class=""><br class=""></div><div class="">P.S. - I tried to make this easy to check out and compile</div><div class=""><br class=""></div><div class=""><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=AdkfTiApI80cNEyortTzHbERtY5det-2FDBvSxuhs4q2MmAasusHpnfYLvSCk2vx1gIiPs9JPdTU94ewYDwYZyETDy5Y3OCpSEtXmh3s0lRT8j6-2FmRKvS4Wrr67ftBoVvHHSkDKPP4esQyK-2B0INK7vtdIYoq2pOdGsBAiV1PmjalhgmQWeLAJec7yHVsfHqu5Ls6tXOmL9ELU-2B3aTKvYNaBlbmu8eOM6pNraxSLB4suto-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a></div></blockquote></div></div></blockquote></div><br class=""></body></html>