Skip to content

Commit

Permalink
feat(xtask): auto-target
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Jun 18, 2024
1 parent 934a80c commit 1086a51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "xtask"
version = "0.1.0"
edition = "2021"
publish = false
build = "build.rs"

[lints]
workspace = true
Expand Down
7 changes: 7 additions & 0 deletions xtask/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
println!(
"cargo:rustc-env=TARGET_PLATFORM={}",
&std::env::var("TARGET").unwrap()
);
println!("cargo:rerun-if-changed-env=TARGET");
}
15 changes: 11 additions & 4 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum Opts {
callgrind: bool,
#[arg(long)]
cachegrind: bool,
#[arg(long, default_value = "x86_64-unknown-linux-gnu")]
#[arg(long, default_value = env!("TARGET_PLATFORM"))]
target: String,
args: Vec<String>,
},
Expand All @@ -26,9 +26,13 @@ enum Opts {
#[arg(long)]
fix: bool,
},
/// Build and run test file from `bindings/c`
TestCBindings {
#[arg(long, default_value = "x86_64-unknown-linux-gnu")]
#[arg(long, default_value = env!("TARGET_PLATFORM"))]
target: String,
/// Which bindings file to build and run
#[arg(long, default_value = "libjsonnet_test_file")]
test_file: String,
args: Vec<String>,
},
}
Expand Down Expand Up @@ -78,15 +82,18 @@ fn main() -> Result<()> {
cmd!(sh, "cargo fmt {fmt_check...}").run()?;
Ok(())
}
Opts::TestCBindings { target, args } => {
Opts::TestCBindings {
target,
test_file,
args,
} => {
cmd!(
sh,
"cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"
)
.run()?;
let built = format!("./target/{target}/release/libjsonnet.a");
let c_bindings = "./bindings/c/";
let test_file = "libjsonnet_test_file";
cmd!(sh, "cp {built} {c_bindings}").run()?;
sh.change_dir(c_bindings);

Expand Down

0 comments on commit 1086a51

Please sign in to comment.