<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="">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=""> header "/usr/local/include/git2.h"</div><div class=""> link "git2"</div><div class=""> 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(&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"></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"></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> 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 class=""><br class=""></div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><span class="Apple-style-span" style="border-collapse: separate; line-height: normal; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div class="">Jeff Kelley</div><div class=""><br class=""></div><div class=""><a href="mailto:SlaunchaMan@gmail.com" class="">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" class="">@SlaunchaMan</a> | <a href="http://jeffkelley.org" class="">jeffkelley.org</a></div></div></span></div></div></div>
</div>
<br class=""></div></body></html>