Skip to content

Commit ca50bd2

Browse files
committed
feat(xtask): auto-target
1 parent 9e17876 commit ca50bd2

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

xtask/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "xtask"
33
version = "0.1.0"
44
edition = "2021"
55
publish = false
6+
build = "build.rs"
67

78
[lints]
89
workspace = true

xtask/build.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
println!(
3+
"cargo:rustc-env=TARGET_PLATFORM={}",
4+
&std::env::var("TARGET").unwrap()
5+
);
6+
println!("cargo:rerun-if-changed-env=TARGET");
7+
}

xtask/src/main.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum Opts {
1616
callgrind: bool,
1717
#[arg(long)]
1818
cachegrind: bool,
19-
#[arg(long, default_value = "x86_64-unknown-linux-gnu")]
19+
#[arg(long, default_value = env!("TARGET_PLATFORM"))]
2020
target: String,
2121
args: Vec<String>,
2222
},
@@ -26,9 +26,13 @@ enum Opts {
2626
#[arg(long)]
2727
fix: bool,
2828
},
29+
/// Build and run test file from `bindings/c`
2930
TestCBindings {
30-
#[arg(long, default_value = "x86_64-unknown-linux-gnu")]
31+
#[arg(long, default_value = env!("TARGET_PLATFORM"))]
3132
target: String,
33+
/// Which bindings file to build and run
34+
#[arg(long, default_value = "libjsonnet_test_file")]
35+
test_file: String,
3236
args: Vec<String>,
3337
},
3438
}
@@ -78,15 +82,18 @@ fn main() -> Result<()> {
7882
cmd!(sh, "cargo fmt {fmt_check...}").run()?;
7983
Ok(())
8084
}
81-
Opts::TestCBindings { target, args } => {
85+
Opts::TestCBindings {
86+
target,
87+
test_file,
88+
args,
89+
} => {
8290
cmd!(
8391
sh,
8492
"cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"
8593
)
8694
.run()?;
8795
let built = format!("./target/{target}/release/libjsonnet.a");
8896
let c_bindings = "./bindings/c/";
89-
let test_file = "libjsonnet_test_file";
9097
cmd!(sh, "cp {built} {c_bindings}").run()?;
9198
sh.change_dir(c_bindings);
9299

0 commit comments

Comments
 (0)