diff --git a/build.rs b/build.rs index cdc86f9f..f30e753b 100644 --- a/build.rs +++ b/build.rs @@ -22,7 +22,7 @@ fn main() { let bindings = File::create(Path::new(&out_dir).join("bindings.rs")).unwrap(); let sink = BufWriter::new(bindings); - if let Err(err) = generate(Path::new(&vst3_sdk_dir), sink) { + if let Err(err) = generate(Path::new(&vst3_sdk_dir), None, sink) { eprintln!("{}", err); process::exit(1); } diff --git a/com-scrape/src/generator.rs b/com-scrape/src/generator.rs index 3a323f29..7961ce1d 100644 --- a/com-scrape/src/generator.rs +++ b/com-scrape/src/generator.rs @@ -24,6 +24,7 @@ fn rust_to_clang_target(rust_target: &str) -> String { /// Builder struct for configuring and generating bindings. pub struct Generator { pub(crate) include_paths: Vec, + pub(crate) target: Option, pub(crate) skip_types: HashSet, pub(crate) skip_interface_traits: HashSet, pub(crate) constant_parser: Option Option>>, @@ -37,6 +38,7 @@ impl Default for Generator { fn default() -> Generator { Generator { include_paths: Vec::new(), + target: None, skip_types: HashSet::new(), skip_interface_traits: HashSet::new(), constant_parser: None, @@ -55,6 +57,12 @@ impl Generator { self } + /// Specify the target triple for which bindings should be generated. + pub fn target>(mut self, target: T) -> Self { + self.target = Some(target.as_ref().to_string()); + self + } + /// Do not generate bindings for `type_`. pub fn skip_type>(mut self, type_: T) -> Self { self.skip_types.insert(type_.as_ref().to_string()); @@ -145,7 +153,9 @@ impl Generator { clang_sys::load()?; } - let rust_target = if let Ok(target) = env::var("TARGET") { + let rust_target = if let Some(target) = &self.target { + Cow::from(target) + } else if let Ok(target) = env::var("TARGET") { Cow::from(target) } else { Cow::from(HOST_TARGET) diff --git a/vst3-bindgen/src/lib.rs b/vst3-bindgen/src/lib.rs index 4f99e57d..73f658d9 100644 --- a/vst3-bindgen/src/lib.rs +++ b/vst3-bindgen/src/lib.rs @@ -46,7 +46,11 @@ fn parse_iid(tokens: &[String]) -> Option { } /// Generates Rust bindings given a path to the VST 3 SDK. -pub fn generate(sdk_dir: &Path, mut sink: impl Write) -> Result<(), Box> { +pub fn generate( + sdk_dir: &Path, + target: Option<&str>, + mut sink: impl Write, +) -> Result<(), Box> { let pluginterfaces_path = sdk_dir.join("pluginterfaces"); let headers = find_headers(&pluginterfaces_path)?; @@ -59,7 +63,7 @@ pub fn generate(sdk_dir: &Path, mut sink: impl Write) -> Result<(), Box Result<(), Box Result<(), Box