Manually specifying include directory for Swift C module

Viewed 76

I have a C library MyLib that I am trying to use in a Swift app. I want to use a local copy of the library, so I don't want to install it or add my bridge header to its files. I clone the library to Sources/ClibMyLib/MyLib so the package structure looks like this:

App
  | Package.swift
  | Sources/
    | ClibMyLib/
      | module.modulemap
      | bridge.h
      | MyLib/
        | include/
          | myLibHeader.h
        | source/
          | *.c

I specify bridge.h as the header in the module map:

module ClibMyLib {
    umbrella header "bridge.h"
    link "MyLib"
    export *
}

The problem is that the include directory of MyLib is not visible to bridge.h So if bridge.h looks like this:

#include "myLibHeader.h"

it fails to build since it can't find myLibHeader.h. If I specify the path from bridge.h to the local copy like this:

#include "MyLib/include/myLibHeader.h"

then any transitive includes in myLibHeader.h still fail.

This would be very easy to solve in a C build, I would just add MyLib/include as an include directory. I haven't been able to find a way to do something similar in Swift - most guides I have found install the library and include from /usr/local/include/.

Are my only options to place bridge.h in the library's include directory or to install the headers to /usr/local/include? Adding bridge.h to the library is not ideal, the include directory file structure is more complicated than the simple example I gave. I just want to be able to manually specify an include directory.

0 Answers
Related