<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 Feb 11, 2016, at 9:41 PM, Jeff Kelley via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m trying to use the Swift Package Manager to import libgit2 and am running into some issues. I have libgit2 installed via Homebrew and have configured the module map thusly:<div class=""><br class=""></div><div class=""><div class=""></div></div><blockquote type="cite" class=""><div class=""><div class="">module CGit2 [system] {</div><div class="">&nbsp; &nbsp; header "/usr/local/include/git2.h"</div><div class="">&nbsp; &nbsp; link "git2"</div><div class="">&nbsp; &nbsp; export *</div><div class="">}</div></div></blockquote><div class=""><br class=""></div><div class="">I can then use this with the SPM to initialize the Git system:</div><div class=""><br class=""></div><div class=""><div class=""></div><blockquote type="cite" class=""><div class="">import CGit2</div><div class=""><br class=""></div><div class="">let result = git_libgit2_init()</div><div class=""><br class=""></div><div class="">defer { git_libgit2_shutdown() }</div><div class=""><br class=""></div><div class="">print("Result: \(result)")</div></blockquote><div class=""><br class=""></div></div><div class="">This all works fine. When I start to try to use it—for instance, opening a repository:</div><div class=""><br class=""></div><div class=""><div class=""></div></div><blockquote type="cite" class=""><div class=""><div class="">var repo: git_repository = nil</div><div class=""><br class=""></div><div class="">let error = git_repository_open(&amp;repo, "/Users/jeff/Projects/CGit2")</div><div class=""><br class=""></div><div class="">guard let repo = repo else { print("No repo!"); exit(error) }</div></div><span id="x-apple-selection:end" class=""></span></blockquote><div class=""><br class=""></div><div class="">I get an error: “use of undeclared type ‘git_repository’”</div><div class=""><br class=""></div><div class="">Here’s how git_repository is declared in /usr/local/include/git2/types.h:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><span id="x-apple-selection:end" class=""></span>typedef struct git_repository git_repository;<br class=""></blockquote><br class=""></div><div class="">An empty struct. Interesting. A quick sample project in Xcode shows that this line will not generate anything in the Swift generated interface. So it appears to me that this type is <i class="">invisible</i> to Swift.</div><div class=""><br class=""></div><div class=""><b class="">Question:</b>&nbsp;Is there a way to use libraries like this in Swift? Should I file a bug that typedef’d structs like this are not imported into the generated interface? Thanks in advance for any pointers!</div></div></div></blockquote><br class=""></div><div>If a struct is incomplete in C, it can only be manipulated via pointers. We don't import `git_repository`, but `git_repository*` should be imported as a typealias for COpaquePointer. We have plans to eventually improve the type safety here by importing the type, though even then, you would not be able to construct or pass around values of the incomplete type, only pointers.</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>