From ab2095c815247cd7827baa7659e483cc259303de Mon Sep 17 00:00:00 2001 From: figsoda Date: Sun, 21 May 2023 11:52:19 -0400 Subject: [PATCH] cargo-benchcmp: init at 0.4.4 https://github.com/BurntSushi/cargo-benchcmp --- .../tools/rust/cargo-benchcmp/default.nix | 41 +++++++++++++++++++ .../cargo-benchcmp/fix-test-binary-path.patch | 30 ++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 3 files changed, 72 insertions(+) create mode 100644 pkgs/development/tools/rust/cargo-benchcmp/default.nix create mode 100644 pkgs/development/tools/rust/cargo-benchcmp/fix-test-binary-path.patch diff --git a/pkgs/development/tools/rust/cargo-benchcmp/default.nix b/pkgs/development/tools/rust/cargo-benchcmp/default.nix new file mode 100644 index 000000000000..4aa3c411f12e --- /dev/null +++ b/pkgs/development/tools/rust/cargo-benchcmp/default.nix @@ -0,0 +1,41 @@ +{ lib +, rustPlatform +, fetchFromGitHub +, substituteAll +, rust +, stdenv +}: + +rustPlatform.buildRustPackage rec { + pname = "cargo-benchcmp"; + version = "0.4.4"; + + src = fetchFromGitHub { + owner = "BurntSushi"; + repo = "cargo-benchcmp"; + rev = version; + hash = "sha256-pg3/VUC1DQ7GbSQDfVZ0WNisXvzXy0O0pr2ik2ar2h0="; + }; + + cargoHash = "sha256-vxy9Ym3Twx034I1E5fWNnbP1ttfLolMbO1IgRiPfhRw="; + + patches = [ + # patch the binary path so tests can find the binary when `--target` is present + (substituteAll { + src = ./fix-test-binary-path.patch; + shortTarget = rust.toRustTarget stdenv.hostPlatform; + }) + ]; + + checkFlags = [ + # thread 'different_input_colored' panicked at 'assertion failed: `(left == right)` + "--skip=different_input_colored" + ]; + + meta = with lib; { + description = "A small utility to compare Rust micro-benchmarks"; + homepage = "https://github.com/BurntSushi/cargo-benchcmp"; + license = with licenses; [ mit unlicense ]; + maintainers = with maintainers; [ figsoda ]; + }; +} diff --git a/pkgs/development/tools/rust/cargo-benchcmp/fix-test-binary-path.patch b/pkgs/development/tools/rust/cargo-benchcmp/fix-test-binary-path.patch new file mode 100644 index 000000000000..f4643e670ce6 --- /dev/null +++ b/pkgs/development/tools/rust/cargo-benchcmp/fix-test-binary-path.patch @@ -0,0 +1,30 @@ +--- a/tests/integration.rs ++++ b/tests/integration.rs +@@ -16,20 +16,13 @@ impl CommandUnderTest { + fn new() -> CommandUnderTest { + // To find the directory where the built binary is, we walk up the directory tree of the test binary until the + // parent is "target/". +- let mut binary_path = env::current_exe().expect("need current binary path to find binary to test"); +- loop { +- { +- let parent = binary_path.parent(); +- if parent.is_none() { +- panic!("Failed to locate binary path from original path: {:?}", env::current_exe()); +- } +- let parent = parent.unwrap(); +- if parent.is_dir() && parent.file_name().unwrap() == "target" { +- break; +- } +- } +- binary_path.pop(); +- } ++ let mut binary_path = PathBuf::from( ++ env::current_dir() ++ .unwrap() ++ .join("target") ++ .join("@shortTarget@") ++ .join(env!("cargoBuildType")), ++ ); + + binary_path.push( + if cfg!(target_os = "windows") { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2467c74d2213..b1bc3ad266ee 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16273,6 +16273,7 @@ with pkgs; cargo-audit = callPackage ../development/tools/rust/cargo-audit { inherit (darwin.apple_sdk.frameworks) Security; }; + cargo-benchcmp = callPackage ../development/tools/rust/cargo-benchcmp { }; cargo-binstall = callPackage ../development/tools/rust/cargo-binstall { }; cargo-bisect-rustc = callPackage ../development/tools/rust/cargo-bisect-rustc { inherit (darwin.apple_sdk.frameworks) Security;