autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

Usage of system frameworks (macOS)?

Open chirok11 opened this issue 2 years ago • 4 comments

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.

chirok11 avatar Dec 05 '23 19:12 chirok11

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/

DDRBoxman avatar Feb 05 '24 06:02 DDRBoxman

    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.

DDRBoxman avatar Feb 06 '24 00:02 DDRBoxman

Obviously needs to call like xcrun --sdk macosx --show-sdk-path to get the path first

DDRBoxman avatar Feb 06 '24 00:02 DDRBoxman