fn build(sdk_path: Option<&str>, target: &str) { // Generate one large set of bindings for all frameworks. // // We do this rather than generating a module per framework as some frameworks depend on other // frameworks and in turn share types. To ensure all types are compatible across each // framework, we feed all headers to bindgen at once. // // Only link to each framework and include their headers if their features are enabled and they // are available on the target os.
use std::env; use std::path::PathBuf;
letmut headers: Vec<&'static str> = vec![];
#[cfg(feature = "audio_unit")]
{ // Since iOS 10.0 and macOS 10.12, all the functionality in AudioUnit // moved to AudioToolbox, and the AudioUnit headers have been simple // wrappers ever since. if target.contains("apple-ios") { // On iOS, the AudioUnit framework does not have (and never had) an // actual dylib to link to, it is just a few header files. // The AudioToolbox framework contains the symbols instead.
println!("cargo:rustc-link-lib=framework=AudioToolbox");
} else { // On macOS, the symbols are present in the AudioToolbox framework, // but only on macOS 10.12 and above. // // However, unlike on iOS, the AudioUnit framework on macOS // contains a dylib with the desired symbols, that we can link to // (in later versions just re-exports from AudioToolbox).
println!("cargo:rustc-link-lib=framework=AudioUnit");
}
headers.push("AudioUnit/AudioUnit.h");
}
println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS"); // Get the cargo out directory. let out_dir = PathBuf::from(env::var("OUT_DIR").expect("env variable OUT_DIR not found"));
// Begin building the bindgen params. letmut builder = bindgen::Builder::default();
// See https://github.com/rust-lang/rust-bindgen/issues/1211 // Technically according to the llvm mailing list, the argument to clang here should be // -arch arm64 but it looks cleaner to just change the target. let target = if target == "aarch64-apple-ios" { "arm64-apple-ios"
} elseif target == "aarch64-apple-darwin" { "arm64-apple-darwin"
} else {
target
};
builder = builder.size_t_is_usize(true);
iflet Some(sdk_path) = sdk_path {
builder = builder.clang_args(&["-isysroot", sdk_path]);
} if target.contains("apple-ios") { // time.h as has a variable called timezone that conflicts with some of the objective-c // calls from NSCalendar.h in the Foundation framework. This removes that one variable.
builder = builder.blocklist_item("timezone");
builder = builder.blocklist_item("objc_object");
}
// bindgen produces alignment tests that cause undefined behavior in some cases. // This seems to happen across all apple target tripples :/. // https://github.com/rust-lang/rust-bindgen/issues/1651
builder = builder.layout_tests(false);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.