LLVM Discussion Forums

Libtooling with -fmodules error

I have a libtooling tool named ‘ExportAST’ which used to export the declaration information of the specified header file.
I almost did. When I was debugging an objective-c module. I got a problem.

can you help me?

There is a problem with libtooling that has been bothering me,
A specified header file named BBPAppDelegate.h to be exported:

`
/ / BBPAppDelegate.h
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@ import ObjectiveC.runtime;
@ import ObjectiveC.message;
NS_ASSUME_NONNULL_BEGIN

@interface BBPAppDelegate : NSObject<UIApplicationDelegate, UNUserNotificationCenterDelegate>
@end

NS_ASSUME_NONNULL_END

`

execute cmd:

    $ ./ExportAST BBPAppDelegate.h -- -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include -x objective-c -fobjc-arc -fmodules

Then got the Errors:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/module.modulemap:118:11: error: header 'stdarg.h' not found header "stdarg.h" // note: supplied by the compiler ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16:10: note: submodule of top-level module 'Darwin' implicitly imported here #include <sys/types.h> ...** many error **...

To Execute after remove the option ‘-fmodules’:

    $ . / ExportAST BBPAppDelegate. H -- -- - isysroot/Applications/Xcode. The app/Contents/Developer/Platforms/iPhoneSimulator platform/Developer/SDKs/iPhoneSimulator13.2 SDK - isystem / Applications/Xcode. App/Contents/Developer/Toolchains/XcodeDefault xctoolchain/usr/lib/clang 11.0.0 / include - x objective - c - fobjc - arc

Error still reported:
../BBPAppDelegate.h:13:1: error: use of '@import' when modules are disabled @import ObjectiveC.runtime; ^ ../BBPAppDelegate.h:14:1: error: use of '@import' when modules are disabled @import ObjectiveC.message;

When test with libclang:

There is no error when using a libclang tool which linkd libclang.dynlib by Apple produced(/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib).

However, it’s also failed when using a libclang tool which linkd libclang.dynlib by my compilation(/volume/ExtDisk/llvm-project-apple/lib/libclang.dylib), regardless of whether -fmoudles were added or not.
BBPAppDelegate. H :13:1: fatal error: could not build module 'UIKit'

So I think it’s what cmake parameters added by Apple when compiling and generating llvm-project of Xcode, Using the apple llvm-project

I compile the llvm-project with the paramters:

    $ cmake ../llvm-project-apple/llvm  -DCMAKE_BUILD_TYPE:STRING=Release -DLLVM_ENABLE_RTTI:BOOL=ON -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;libunwind;compiler-rt"
    $ make j4

Use llvm:https://github.com/llvm-mirror/llvm.git
    $ cmake ../llvm-project-apple/llvm  -DCMAKE_BUILD_TYPE:STRING=Release -DLLVM_ENABLE_RTTI:BOOL=ON
    $ make j4

Both versions of clang are compiled with the same result
To support objective-c modules (@import objective-c. Runtime) which parameters should I use for cmake llvm-project?

Any Suggestions would be greatly appreciated!

Related information:
OS:Mac OS 10.15.1
llvm-project: llvm-mirror/llvm.git
branch:release_90
llvm-project-apple: apple/llvm-project.git
branch:apple/stable/20191106
Xcode: Xcode 11.2.1(Apple clang version 11.0.0 (clang-1100.0.33.12))
cmake version: cmake version 3.14.5
make version: GNU Make 3.81