autocxx
autocxx copied to clipboard
Usage of system frameworks (macOS)?
Describe the bug Is it possible to use system frameworks on macOS? I suppose that there is a same problem while using Windows API header files on Windows.
To Reproduce Create a demo.h file within contents:
#pragma once
#include <CoreFoundation/CoreFoundation.h>
CFRunLoopRef GetCurrentLoop() { return CFRunLoopGetCurrent(); }
Error
--- stderr
src/demo.h:3:10: fatal error: 'CoreFoundation/CoreFoundation.h' file not found
src/demo.h:3:10: note: did not find header 'CoreFoundation.h' in framework 'CoreFoundation' (loaded from '/System/Library/Frameworks')
Error: × the include_cpp! macro couldn't be expanded into Rust bindings to C++:
│ Bindgen was unable to generate the initial .rs bindings for this file.
│ This may indicate a parsing problem with the C++ headers.
Expected behavior Everything is compiled.
I haven't had a change to dig into how things get passed to bindgen within the autocxx tools, but this post seems to have relevance for getting the path programmatically.
https://zameermanji.com/blog/2021/7/13/using-bindgen-with-system-frameworks-on-macos/
let mut b = autocxx_build::Builder::new("src/main.rs", &[&path])
.extra_clang_args(&["-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"])
.build()?;
b.flag_if_supported("-std=c++14")
.compile("autocxx-demo"); // arbitrary library name, pick anything
Throw this in your build script it should work.
Obviously needs to call like xcrun --sdk macosx --show-sdk-path to get the path first