macosmoduleframeworksmodule-map

How do I use libproc.h in a modular Swift framework?


I've followed all the steps from other similar questions, and I'm still stuck.

I need to use the function proc_pidpath in libproc.h to get the path of a BSD process by its PID. However, libproc.h is not a modular header, so I can't include it in my umbrella header:

a line of code reading "#import <libproc.h>" with the error "Include of non-modular header inside framework module"

Fair enough; now I try to include it in my module map:

framework module My_Modular_Framework {
    umbrella header "My_Modular_Framework.h"

    private header "/usr/include/libproc.h"

    export *
    module * { export * }
}

Well now I get this error-vomit where it seems like it thinks many system modules/headers are within my project:

A long list of errors like "Redeclaration of module SomeSystemModule"

I can't figure out what else to do. Like I said, I already tried following all the steps of other similar questions without any success. What can be done here? How can I use proc_pidpath? Is there another, more Swift-in-modular-framework friendly way to get a path from a process ID?

I don't want to enable "Allow Non-modular Includes In Framework Modules" because that defeats the purpose of a modular framework.


Solution

  • Since libproc.h and libproc.c are open-source (APSL 2.0) as a part of Apple's Darwin project, you can just include them (under the terms of the license, of course) in your project. Since neither imports any non-modular headers, you can compile it yourself and the compiler won't complain!