0

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.

Ky -
  • 30,724
  • 51
  • 192
  • 308

1 Answers1

1

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!

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • Thank you for this point! I am trying to `cp libproc.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include` on my MacBook Pro. Unfortunately, the system said `cp: ./libproc.h: Operation not permitted`. It seems that Apple does not allow us to change an official SDK. – cxwangyi Dec 06 '22 at 22:35
  • This project shows how you can make your own swift LibProc from the macos-provided libproc.h: https://github.com/themittenmac/TrueTree/tree/master/Src/ProcLib – bukzor Jan 03 '23 at 18:30
  • @cxwangyi you're trying to copy a file into the `Xcode.app` bundle, but that bundle is read-only. To apply my answer to your project, you'd want to copy it into your project instead – Ky - Jan 06 '23 at 20:32