Trouble with Swift modules, git submodules, and bindings to a C library

I'm trying to get started with the minimum viable bindings to this C library which uses CMake: GitHub - uber/h3: Hexagonal hierarchical geospatial indexing system

I am guessing I could prove the concept out if I just copied all the .c/.h files into my new project, but I'd like to make it as easy as possible to stay synced with upstream. I've been stumbling around guessing at relative path problems in the clang modulemap.

But after several permutations, XCode still complains "no such module" on: h3-swift/h3-swift.swift at master · SCUPPERfoundation/h3-swift · GitHub

Did I miss something obvious (I hope)? I'm operating from a tutorial that seems to be based on Swift 3 (from the author of Zip.swift) and I haven't found anything newer.

1 Like

You need to include the directory that includes the module.modulemap in the "Import Paths" under "Swift Compiler - Search Paths". In the repo that file is at the top level so adding ${SRCROOT} does the trick -- doing that I see the module import working fine. Some compile errors on the C side but I think unrelated to this part.

2 Likes

Thank you! (I didn't even have to go to brunch to wait for an answer!) I wasn't seeing the "Swift Compiler - Search Paths" in XCode, despite knowing to look for it. Assumed it was a Swift 3 -> 4 but either I wasn't looking hard enough, or I did something that un-hid that between before and now.