Where are the system-wide Objective-C modules defined in macOS?

Viewed 14

I was interested to inspect globally available modulemaps of Objective-C language under macOS and was wondering if it's possible to add one myself. Is there a way to know where a particular module (e.g. Foundation) is located?

@import Foundation; // Where this comes from?

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, world!");
    }
    return 0;
}
1 Answers

Almost all modules are embedded to the corresponding frameworks in the system. For the latest version of macOS at the time of writing (macOS Monterey 12.6 (21G115)) the frameworks can be found under this directory:

/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks

E.g. Foundation modulemap is located at the path /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Foundation.framework/Versions/C/Modules/module.modulemap and looks like this:

framework module Foundation [extern_c] [system] {
    umbrella header "Foundation.h"
    
    export *
    module * {
        export *
    }
    
    
    explicit module NSDebug {
        header "NSDebug.h"
        export *
    }
    
    // Use NSItemProvider.h
    exclude header "NSItemProviderReadingWriting.h"
}

The dependencies which were not part of any framework (e.g. libobjc), however, also have modulemaps defined and available under different directory:

/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
Related