git.delta.rocks / jrsonnet / refs/commits / 604f09da5796

difftreelog

fix only build benchmarker for x86_64-linux

oqtmzxprYaroslav Bolyukin2026-05-06parent: #3e1d397.patch.diff
in: master

3 files changed

modifiedxtask/Cargo.tomldiffbeforeafterboth
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -18,5 +18,5 @@
 xshell.workspace = true
 clap = { workspace = true, features = ["derive"] }
 
-[target.'cfg(target_os = "linux")'.dependencies]
+[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dependencies]
 nix.workspace = true
modifiedxtask/src/bench.rsdiffbeforeafterboth
--- a/xtask/src/bench.rs
+++ b/xtask/src/bench.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::cast_precision_loss)]
+
 use std::{
 	ffi::OsString,
 	mem,
modifiedxtask/src/main.rsdiffbeforeafterboth
before · xtask/src/main.rs
1use anyhow::Result;2#[cfg(not(target_os = "linux"))]3use anyhow::bail;4use clap::Parser;5use xshell::{Shell, cmd};67#[cfg(target_os = "linux")]8mod bench;9mod sourcegen;1011#[derive(Parser)]12enum Opts {13	/// Generate files for rowan parser14	Sourcegen,15	/// Profile file execution16	Profile {17		#[arg(long, default_value = "true")]18		hyperfine: bool,19		#[arg(long)]20		callgrind: bool,21		#[arg(long)]22		cachegrind: bool,23		#[arg(long, default_value = env!("TARGET_PLATFORM"))]24		target: String,25		args: Vec<String>,26	},27	/// Run all lints enforced by this repo28	Lint {29		/// Also fix found issues when possible.30		#[arg(long)]31		fix: bool,32	},33	/// Build and run test file from `bindings/c`34	TestCBindings {35		#[arg(long, default_value = env!("TARGET_PLATFORM"))]36		target: String,37		/// Which bindings file to build and run38		#[arg(long, default_value = "libjsonnet_test_file")]39		test_file: String,40		args: Vec<String>,41	},42	/// Benchmark a command: repeated runs, reports time + RSS stats (Linux only)43	Bench {44		#[arg(long, default_value_t = 10)]45		runs: u32,46		#[arg(long, default_value_t = 1)]47		warmup: u32,48		/// Show command output49		#[arg(long, short = 'q')]50		output: bool,51		#[arg(trailing_var_arg = true, required = true)]52		args: Vec<String>,53	},54}5556fn main() -> Result<()> {57	let sh = Shell::new()?;58	match Opts::parse() {59		Opts::Sourcegen => sourcegen::generate_ungrammar(),60		Opts::Profile {61			hyperfine,62			callgrind,63			cachegrind,64			args,65			target,66		} => {67			let out = sh.create_temp_dir()?;6869			cmd!(sh, "cargo build --target={target} --profile releasedebug").run()?;70			let built = format!("./target/{target}/releasedebug/jrsonnet");71			let bench_cmd = format!("{built} {}", args.join(" "));72			if hyperfine {73				cmd!(sh, "hyperfine {bench_cmd}").run()?;74			}75			if callgrind {76				let args = args.clone();77				let mut callgrind_out = out.path().to_owned();78				callgrind_out.push("callgrind.out.1");79				cmd!(sh, "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file={callgrind_out} {built} {args...}").run()?;80				cmd!(sh, "kcachegrind {callgrind_out}").run()?;81			}82			if cachegrind {83				let mut cachegrind_out = out.path().to_owned();84				cachegrind_out.push("cachegrind.out.1");85				cmd!(86					sh,87					"valgrind --tool=cachegrind --cachegrind-out-file={cachegrind_out} {built} {args...}"88				)89				.run()?;90				cmd!(sh, "kcachegrind {cachegrind_out}").run()?;91			}9293			Ok(())94		}95		Opts::Lint { fix } => {96			let fmt_check = if fix { None } else { Some("--check") };97			cmd!(sh, "cargo fmt {fmt_check...}").run()?;98			Ok(())99		}100		Opts::TestCBindings {101			target,102			test_file,103			args,104		} => {105			cmd!(106				sh,107				"cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"108			)109			.run()?;110			let built = format!("./target/{target}/release/libjsonnet.a");111			let c_bindings = "./bindings/c/";112			cmd!(sh, "cp {built} {c_bindings}").run()?;113			sh.change_dir(c_bindings);114115			// TODO: Pass target to gcc?116			cmd!(sh, "gcc -c {test_file}.c").run()?;117			cmd!(sh, "gcc -o {test_file} -lc -lm {test_file}.o libjsonnet.a").run()?;118			let sh = Shell::new()?;119120			cmd!(sh, "{c_bindings}{test_file} {args...}").run()?;121122			Ok(())123		}124		#[cfg(target_os = "linux")]125		Opts::Bench {126			runs,127			warmup,128			output,129			args,130		} => bench::bench_cmd(&args, runs, warmup, output),131	}132}
after · xtask/src/main.rs
1use anyhow::Result;2use clap::Parser;3use xshell::{Shell, cmd};45#[cfg(all(target_arch = "x86_64", target_os = "linux"))]6mod bench;7mod sourcegen;89#[derive(Parser)]10enum Opts {11	/// Generate files for rowan parser12	Sourcegen,13	/// Profile file execution14	Profile {15		#[arg(long, default_value = "true")]16		hyperfine: bool,17		#[arg(long)]18		callgrind: bool,19		#[arg(long)]20		cachegrind: bool,21		#[arg(long, default_value = env!("TARGET_PLATFORM"))]22		target: String,23		args: Vec<String>,24	},25	/// Run all lints enforced by this repo26	Lint {27		/// Also fix found issues when possible.28		#[arg(long)]29		fix: bool,30	},31	/// Build and run test file from `bindings/c`32	TestCBindings {33		#[arg(long, default_value = env!("TARGET_PLATFORM"))]34		target: String,35		/// Which bindings file to build and run36		#[arg(long, default_value = "libjsonnet_test_file")]37		test_file: String,38		args: Vec<String>,39	},40	/// Benchmark a command: repeated runs, reports time + RSS stats (Linux only)41	#[cfg(all(target_arch = "x86_64", target_os = "linux"))]42	Bench {43		#[arg(long, default_value_t = 10)]44		runs: u32,45		#[arg(long, default_value_t = 1)]46		warmup: u32,47		/// Show command output48		#[arg(long, short = 'q')]49		output: bool,50		#[arg(trailing_var_arg = true, required = true)]51		args: Vec<String>,52	},53}5455fn main() -> Result<()> {56	let sh = Shell::new()?;57	match Opts::parse() {58		Opts::Sourcegen => sourcegen::generate_ungrammar(),59		Opts::Profile {60			hyperfine,61			callgrind,62			cachegrind,63			args,64			target,65		} => {66			let out = sh.create_temp_dir()?;6768			cmd!(sh, "cargo build --target={target} --profile releasedebug").run()?;69			let built = format!("./target/{target}/releasedebug/jrsonnet");70			let bench_cmd = format!("{built} {}", args.join(" "));71			if hyperfine {72				cmd!(sh, "hyperfine {bench_cmd}").run()?;73			}74			if callgrind {75				let args = args.clone();76				let mut callgrind_out = out.path().to_owned();77				callgrind_out.push("callgrind.out.1");78				cmd!(sh, "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file={callgrind_out} {built} {args...}").run()?;79				cmd!(sh, "kcachegrind {callgrind_out}").run()?;80			}81			if cachegrind {82				let mut cachegrind_out = out.path().to_owned();83				cachegrind_out.push("cachegrind.out.1");84				cmd!(85					sh,86					"valgrind --tool=cachegrind --cachegrind-out-file={cachegrind_out} {built} {args...}"87				)88				.run()?;89				cmd!(sh, "kcachegrind {cachegrind_out}").run()?;90			}9192			Ok(())93		}94		Opts::Lint { fix } => {95			let fmt_check = if fix { None } else { Some("--check") };96			cmd!(sh, "cargo fmt {fmt_check...}").run()?;97			Ok(())98		}99		Opts::TestCBindings {100			target,101			test_file,102			args,103		} => {104			cmd!(105				sh,106				"cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"107			)108			.run()?;109			let built = format!("./target/{target}/release/libjsonnet.a");110			let c_bindings = "./bindings/c/";111			cmd!(sh, "cp {built} {c_bindings}").run()?;112			sh.change_dir(c_bindings);113114			// TODO: Pass target to gcc?115			cmd!(sh, "gcc -c {test_file}.c").run()?;116			cmd!(sh, "gcc -o {test_file} -lc -lm {test_file}.o libjsonnet.a").run()?;117			let sh = Shell::new()?;118119			cmd!(sh, "{c_bindings}{test_file} {args...}").run()?;120121			Ok(())122		}123		#[cfg(all(target_arch = "x86_64", target_os = "linux"))]124		Opts::Bench {125			runs,126			warmup,127			output,128			args,129		} => bench::bench_cmd(&args, runs, warmup, output),130	}131}