I’ve been working on a project using Embedded Swift in Zephyr and I built a thin wrapper around some of its C APIs. I wanted to use apinotes to import some of the enums nicely into Swift, but I can’t get the apinotes file to be picked up.
Zephyr uses GCC to compile everything and swapping to Clang seems like it’s much more trouble than it’s worth, but as far as I know Swift still uses Clang to import C headers, so apinotes should work.
My module.modulemap in the include folder defines the module SwiftZephyrShims:
module SwiftZephyrShims {
header "SwiftZephyrShims.h"
}
In the same folder I have a SwiftZephyrShims.apinotes file:
Name: SwiftZephyrShims
Tags:
- Name: gpio_flags_t
SwiftName: GPIOFlags
EnumExtensibility: closed
And my CMakeLists.txt defines the include directories and enables every setting that I found that relates to apinotes:
add_library(SwiftZephyrShims INTERFACE)
target_include_directories(SwiftZephyrShims INTERFACE
"$<TARGET_PROPERTY:app,INCLUDE_DIRECTORIES>"
include
)
file(REAL_PATH include SwiftZephyrShims_INCLUDE_DIR)
target_compile_options(SwiftZephyrShims INTERFACE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fapinotes>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fapinotes-modules>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -iapinotes-modules -Xcc ${SwiftZephyrShims_INCLUDE_DIR}>"
)
add_dependencies(SwiftZephyrShims syscall_list_h_target)
All of these flags are reflected in the compile_commands.json file for the main app target, so I’m sure that they get to the right place. Swift imports SwiftZephyrShims normally, but any modifications in the apinotes file are ignored. I can’t find any way to force clang to load an apinotes file or even a way to verify whether it loads it or not.
Is there any way to get apinotes working here or do I need to write the enum wrappers manually?