<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">==================================================<div class="">This works:</div>==================================================<div class=""><br class="">First I need openSSL from Swift, that I have done with COpenSsl:<div class=""><div class=""><br class=""></div><div class="">Package.swift:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> PackageDescription</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> package = Package(</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; name: </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"COpenSsl"</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; pkgConfig: </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"openssl"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">module.modulemap:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">module</span><span style="font-variant-ligatures: no-common-ligatures" class=""> COpenSsl [system] {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">header</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">"/usr/local/include/openssl/ssl.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">header</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">"/usr/local/include/openssl/err.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">header</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">"/usr/local/include/openssl/crypto.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">header</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">"/usr/local/include/openssl/evp.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">header</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">"/usr/local/include/openssl/x509v3.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">export</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> *</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">And then import this into Swift with:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> COpenSsl</span></div><div class=""><br class=""></div><div class=""><br class=""></div>==================================================<div class="">This does not work</div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">==================================================</span></div><div class=""><br class=""></div><div class="">Package.swift for the C-glue code:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> PackageDescription</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> package = Package(</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; name: </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"OpenSsl"</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; dependencies: [</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; .Package(url: </span><span style="font-variant-ligatures: no-common-ligatures" class="">"<a href="https://github.com/Swiftrien/COpenSsl" class="">https://github.com/Swiftrien/COpenSsl</a>"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">"0.1.0"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; ]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">OpenSsl.h:</div><div class="">(In Sources/include)</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// #import "openssl/ssl.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// #import "openssl/x509.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// #import "openssl/x509v3.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> COpenSsl;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> sslCtxSetTlsExtServernameCallback(SSL_CTX *ctx, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (*cb)(SSL *, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *), </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *arg);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> skGeneralNamePopFree(STACK_OF(GENERAL_NAME) *san_names);</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">OpenSsl.c:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(In Sources)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #78492a" class="">#include </span><span style="font-variant-ligatures: no-common-ligatures" class="">"OpenSsl.h"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> sslCtxSetTlsExtServernameCallback(SSL_CTX *ctx, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (*cb)(SSL *, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *, </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *), </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *arg) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; SSL_CTX_set_tlsext_servername_arg(ctx, arg);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; SSL_CTX_set_tlsext_servername_callback(ctx, cb);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> skGeneralNamePopFree(STACK_OF(GENERAL_NAME) *san_names) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; sk_GENERAL_NAME_pop_free(san_names, GENERAL_NAME_free);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></span></div></span></div><div class=""><br class=""></div><div class="">The&nbsp;<span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">@import</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp;COpenSsl; </span>statement does not work. Nor do the normal includes.</div><div class="">Hence the compilation fails.</div><div class=""><br class=""></div><div class="">Maybe the import statement is wrong? is there another way to do this?</div><div class=""><div class=""><br class="webkit-block-placeholder"></div><div class="">Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Swiftrien" class="">http://github.com/Swiftrien</a><br class="">Project: <a href="http://swiftfire.nl" class="">http://swiftfire.nl</a><br class=""><br class=""><br class=""><br class=""></div><br class=""><blockquote type="cite" class="">On 22 Jan 2017, at 06:25, Daniel Dunbar &lt;<a href="mailto:daniel_dunbar@apple.com" class="">daniel_dunbar@apple.com</a>&gt; wrote:<br class=""><br class="">What is the glue code you need?<br class=""><br class="">You can define a C/Obj-C target in the same Swift package, and then use it from your Swift targets. See:<br class="">&nbsp;&nbsp;<a href="https://github.com/apple/swift-package-manager/blob/master/Documentation/Reference.md#source-layouts" class="">https://github.com/apple/swift-package-manager/blob/master/Documentation/Reference.md#source-layouts</a><br class="">for more information.<br class=""><br class="">&nbsp;- Daniel<br class=""><br class=""><blockquote type="cite" class="">On Jan 21, 2017, at 2:24 AM, Rien via swift-users &lt;swift-users@swift.org&gt; wrote:<br class=""><br class="">The thing I was missing is the “system module”.. found it now though ;-)<br class=""><br class="">So far so good, I want to put that little glue code I need in its own module. However I cannot find how to specify the import search path.<br class=""><br class="">“swift build -I /usr/local/include/“ does not work (unknown command -I)<br class=""><br class="">And pkgConfig cannot be used on a non-system module.<br class=""><br class="">But without specifying the import search path, SPM cannot compile the c-code.<br class=""><br class="">Any suggestions?<br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site:&nbsp;http://balancingrock.nl<br class="">Blog:&nbsp;http://swiftrien.blogspot.com<br class="">Github:&nbsp;http://github.com/Swiftrien<br class="">Project:&nbsp;http://swiftfire.nl<br class=""><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 20 Jan 2017, at 19:48, Rien via swift-users &lt;swift-users@swift.org&gt; wrote:<br class=""><br class="">I may be missing something here, so please bear with me...<br class=""><br class="">The client of the lib only has to see the headers that describe the lib, not the headers of the files that were used to create the lib.<br class="">Or are you referring to a case were the lib also exposes the headers of the libs that were used to create the lib?<br class=""><br class="">Additional info:<br class="">In my particular case I use openSSL and have created a few Swift operations that use (wrap) openSSL. My lib does not expose openSSL to the client of the lib.<br class="">I did have to create a 2 line c-function for a callback. That function is not exposed to the lib client. But this two line function is the reason for the “mixed language” target.<br class="">Ideally no client should use openSSL directly, but it cannot be prevent of course that a client links its own files to openSSL using his own bridging file.<br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site:&nbsp;http://balancingrock.nl<br class="">Blog:&nbsp;http://swiftrien.blogspot.com<br class="">Github:&nbsp;http://github.com/Swiftrien<br class="">Project:&nbsp;http://swiftfire.nl<br class=""><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 20 Jan 2017, at 18:39, Jordan Rose &lt;jordan_rose@apple.com&gt; wrote:<br class=""><br class="">Hi, Rien. Libraries don’t support bridging headers because the client of the library has to be able to import the header, and arbitrary bridging headers may conflict. (This is&nbsp;actually the primary purpose of modules for Objective-C: to declare a group of headers that are self-contained—besides what other modules they import—and can therefore be&nbsp;imported earlier or later without difficulty.) The compiler will mildly try to stop you from doing this if it can figure out you’re building a library, but it’s a bad idea no matter what.&nbsp;Even if everything appears to compile fine, it’s likely you’ll get inscrutable errors when trying te debug anything that uses your library.<br class=""><br class="">The particular difference between Xcode-created frameworks and SwiftPM-generated libraries is that Xcode frameworks are set up to be mixed-source, using the Objective-C&nbsp;public umbrella header in place of a bridging header. SwiftPM doesn’t support mixed-source targets. (Since I don’t work on SwiftPM myself I don’t know if there are any public&nbsp;plans to do so.)<br class=""><br class="">The recommended solution is to group your Objective-C headers into modules (usually just frameworks) and import them that way, rather than to jam them in via a bridging&nbsp;header.<br class=""><br class="">Sorry for the trouble,<br class="">Jordan<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Jan 20, 2017, at 08:49, Rien via swift-users &lt;swift-users@swift.org&gt; wrote:<br class=""><br class="">I noticed something strange about Xcode and SPM concerning the capability to generate Libraries.<br class=""><br class="">When I try to create a Library in Xcode and then want to add an Objective-C bridging header, that is denied. It claims that bridging is not supported for Libraries.<br class=""><br class="">When I create an Xcode project through the SPM (with “swift package generate-xcodeproj”) then I can use bridging headers, even though the end result is a library.<br class=""><br class="">Question: Is this a viable work around? or are there hidden dangers that might not be immediately apparent?<br class=""><br class="">As a side note: SPM complains about multiple languages and currently only supports pure Swift modules.<br class="">This creates the strange situation that I now use SPM to create an xcode project and then use Xcode to create bridged mixed language libraries.<br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site:&nbsp;http://balancingrock.nl<br class="">Blog:&nbsp;http://swiftrien.blogspot.com<br class="">Github:&nbsp;http://github.com/Swiftrien<br class="">Project:&nbsp;http://swiftfire.nl<br class=""><br class=""><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class="">swift-users@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-users mailing list<br class="">swift-users@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-users mailing list<br class="">swift-users@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class=""></blockquote><br class=""></div></div></div></body></html>