Skip to content

Commit

Permalink
command-line interface for vst3-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Feb 4, 2024
1 parent 632b49d commit fd36480
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ members = [
"com-scrape",
"com-scrape-types",
"vst3-bindgen",
"vst3-bindgen-cli",
]
16 changes: 16 additions & 0 deletions vst3-bindgen-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "vst3-bindgen-cli"
version = "0.1.0"
authors = ["Micah Johnston <[email protected]>"]
edition = "2021"
description = "Binding generator for the VST 3 API"
repository = "https://github.com/coupler-rs/vst3-rs"
license = "MIT OR Apache-2.0"

[[bin]]
path = "src/main.rs"
name = "vst3-bindgen"

[dependencies]
vst3-bindgen = { path = "../vst3-bindgen", version = "0.2.1" }
clap = { version = "3.1.17", features = ["derive", "cargo"] }
43 changes: 43 additions & 0 deletions vst3-bindgen-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::path::PathBuf;

use std::error::Error;
use std::fs::File;
use std::io::{stdout, BufWriter, Write};
use std::process;

use clap::Parser;
use vst3_bindgen::generate;

#[derive(Parser)]
struct Vst3Bindgen {
sdk_dir: PathBuf,

#[clap(long, value_name = "TRIPLE")]
target: Option<String>,

#[clap(long, short, value_name = "OUTPUT")]
output: Option<String>,
}

fn vst3_bindgen(cmd: &Vst3Bindgen) -> Result<(), Box<dyn Error>> {
let mut bindings = Vec::new();

generate(&cmd.sdk_dir, cmd.target.as_deref(), &mut bindings)?;

if let Some(output) = &cmd.output {
let file = File::create(output)?;
BufWriter::new(file).write_all(&bindings)?;
} else {
BufWriter::new(stdout()).write_all(&bindings)?;
};

Ok(())
}

fn main() {
let cmd = Vst3Bindgen::parse();
if let Err(err) = vst3_bindgen(&cmd) {
eprintln!("error: {}", err);
process::exit(1);
}
}

0 comments on commit fd36480

Please sign in to comment.