From 7a11ea8c618f6bf9a549b4f5327c070b21558178 Mon Sep 17 00:00:00 2001 From: Sergio Rojas <48057303+hisergiorojas@users.noreply.github.com> Date: Tue, 22 Mar 2022 13:14:08 +0000 Subject: [PATCH 1/2] add rust build bindings --- Cargo.toml | 3 +++ build.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ wrapper.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 build.rs create mode 100644 wrapper.h diff --git a/Cargo.toml b/Cargo.toml index c57c61b..ebff342 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [dependencies] libc = "0.2" + +[build-dependencies] +bindgen = "0.59.2" \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ffc3709 --- /dev/null +++ b/build.rs @@ -0,0 +1,54 @@ +extern crate bindgen; + +use std::path::PathBuf; +use std::{env, path::Path}; +use std::process::Command; + +fn main() { + + let opentimeline_dir = + env::var("OPENTIMELINE_DIR").expect("'OPENTIMELINE_DIR' envvar is not defined"); + let opentimeline_lib_path = Path::new(&opentimeline_dir).join("lib"); + let opentimeline_include_path = + Path::new(&opentimeline_dir).join("include").join("opentimelineio"); + + let copentime_dir = + env::var("COPENTIME_DIR").expect("'COPENTIME_DIR' envvar is not defined"); + let copentime_lib_path = Path::new(&copentime_dir).join("lib"); + let copentime_include_path = + Path::new(&copentime_dir).join("include").join("copentime"); + + let copentimeline_dir = + env::var("COPENTIMELINE_DIR").expect("'COPENTIMELINE_DIR' envvar is not defined"); + let copentimeline_lib_path = Path::new(&copentimeline_dir).join("lib"); + let copentimeline_include_path = + Path::new(&copentimeline_dir).join("include").join("copentimelineio"); + + println!("cargo:rerun-if-changed=build.rs"); + + println!("cargo:rustc-link-search=native={}", opentimeline_include_path.display()); // the "-L" flag + println!("cargo:rustc-link-lib={}/opentimelineio", opentimeline_lib_path.display()); // the "-l" flag + + println!("cargo:rustc-link-search=native={}", copentime_include_path.display()); + println!("cargo:rustc-link-lib={}/copentime", copentime_lib_path.display()); + + println!("cargo:rustc-link-search=native={}", copentimeline_include_path.display()); + println!("cargo:rustc-link-lib={}/copentimelineio", copentimeline_lib_path.display()); + + let bindings = bindgen::Builder::default() + .header("wrapper.h") + .allowlist_function("*") + .allowlist_type("*") + .allowlist_var("*") + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings"); + + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/wrapper.h b/wrapper.h new file mode 100644 index 0000000..b62f4c3 --- /dev/null +++ b/wrapper.h @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include From fba05bdd6076b02b686fb7e81c3acafb2d7e35b4 Mon Sep 17 00:00:00 2001 From: Sergio Rojas <48057303+hisergiorojas@users.noreply.github.com> Date: Tue, 22 Mar 2022 15:49:38 +0000 Subject: [PATCH 2/2] refactor build to search for opentimeline, copentimeline, copentime lib --- build.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index ffc3709..a199270 100644 --- a/build.rs +++ b/build.rs @@ -26,14 +26,14 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rustc-link-search=native={}", opentimeline_include_path.display()); // the "-L" flag - println!("cargo:rustc-link-lib={}/opentimelineio", opentimeline_lib_path.display()); // the "-l" flag + println!("cargo:rustc-link-search=native={}", opentimeline_lib_path.display()); // the "-L" flag + println!("cargo:rustc-link-lib=dylib=opentimelineio"); // the "-l" flag - println!("cargo:rustc-link-search=native={}", copentime_include_path.display()); - println!("cargo:rustc-link-lib={}/copentime", copentime_lib_path.display()); + println!("cargo:rustc-link-search=native={}", copentime_lib_path.display()); + println!("cargo:rustc-link-lib=static=copentime"); - println!("cargo:rustc-link-search=native={}", copentimeline_include_path.display()); - println!("cargo:rustc-link-lib={}/copentimelineio", copentimeline_lib_path.display()); + println!("cargo:rustc-link-search=native={}", copentimeline_lib_path.display()); + println!("cargo:rustc-link-lib=static=copentimelineio"); let bindings = bindgen::Builder::default() .header("wrapper.h")