From 725658648f8f2296c0e3d20e9cdc2b46399ac3cd Mon Sep 17 00:00:00 2001 From: oxalica Date: Mon, 17 Oct 2022 17:34:50 +0800 Subject: [PATCH 1/2] cargo-show-asm: init at 0.1.24 --- .../tools/rust/cargo-show-asm/default.nix | 44 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 3 ++ 2 files changed, 47 insertions(+) create mode 100644 pkgs/development/tools/rust/cargo-show-asm/default.nix diff --git a/pkgs/development/tools/rust/cargo-show-asm/default.nix b/pkgs/development/tools/rust/cargo-show-asm/default.nix new file mode 100644 index 000000000000..423a2a60988e --- /dev/null +++ b/pkgs/development/tools/rust/cargo-show-asm/default.nix @@ -0,0 +1,44 @@ +{ lib +, stdenv +, fetchFromGitHub +, rustPlatform +, pkg-config +, installShellFiles +, openssl +, nix-update-script +}: +rustPlatform.buildRustPackage rec { + pname = "cargo-asm"; + version = "0.1.24"; + + src = fetchFromGitHub { + owner = "pacak"; + repo = "cargo-show-asm"; + rev = version; + hash = "sha256-ahkKUtg5M88qddzEwYxPecDtBofGfPVxKuYKgmsbWYc="; + }; + + cargoHash = "sha256-S7OpHNjiTfQg7aPmHEx6Q/OV5QA9pB29F3MTIeiLAXg="; + + nativeBuildInputs = [ pkg-config installShellFiles ]; + buildInputs = [ openssl ]; + + postInstall = '' + installShellCompletion --cmd foobar \ + --bash <($out/bin/cargo-asm --bpaf-complete-style-bash) \ + --fish <($out/bin/cargo-asm --bpaf-complete-style-fish) \ + --zsh <($out/bin/cargo-asm --bpaf-complete-style-zsh ) + ''; + + passthru.updateScript = nix-update-script { + attrPath = pname; + }; + + meta = with lib; { + description = "Cargo subcommand showing the assembly, LLVM-IR and MIR generated for Rust code"; + homepage = "https://github.com/pacak/cargo-show-asm"; + license = with licenses; [ asl20 mit ]; + maintainers = with maintainers; [ oxalica ]; + broken = stdenv.isDarwin; # FIXME: Seems to have issue compiling bundled curl. + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 79ff38eb4bb0..e457bc19d40f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14896,6 +14896,9 @@ with pkgs; cargo-semver-checks = callPackage ../development/tools/rust/cargo-semver-checks { inherit (darwin.apple_sdk.frameworks) Security; }; + + cargo-show-asm = callPackage ../development/tools/rust/cargo-show-asm { }; + cargo-sort = callPackage ../development/tools/rust/cargo-sort { }; cargo-spellcheck = callPackage ../development/tools/rust/cargo-spellcheck { inherit (darwin.apple_sdk.frameworks) Security; From 22659c50cf1cebd25c4ebf8f373785767d786377 Mon Sep 17 00:00:00 2001 From: oxalica Date: Mon, 17 Oct 2022 18:00:35 +0800 Subject: [PATCH 2/2] cargo-show-asm: add tests --- .../tools/rust/cargo-show-asm/default.nix | 10 ++++++++-- .../rust/cargo-show-asm/test-basic-x86_64.nix | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/tools/rust/cargo-show-asm/test-basic-x86_64.nix diff --git a/pkgs/development/tools/rust/cargo-show-asm/default.nix b/pkgs/development/tools/rust/cargo-show-asm/default.nix index 423a2a60988e..094753f955ca 100644 --- a/pkgs/development/tools/rust/cargo-show-asm/default.nix +++ b/pkgs/development/tools/rust/cargo-show-asm/default.nix @@ -6,6 +6,7 @@ , installShellFiles , openssl , nix-update-script +, callPackage }: rustPlatform.buildRustPackage rec { pname = "cargo-asm"; @@ -30,8 +31,13 @@ rustPlatform.buildRustPackage rec { --zsh <($out/bin/cargo-asm --bpaf-complete-style-zsh ) ''; - passthru.updateScript = nix-update-script { - attrPath = pname; + passthru = { + updateScript = nix-update-script { + attrPath = pname; + }; + tests = lib.optionalAttrs stdenv.hostPlatform.isx86_64 { + test-basic-x86_64 = callPackage ./test-basic-x86_64.nix { }; + }; }; meta = with lib; { diff --git a/pkgs/development/tools/rust/cargo-show-asm/test-basic-x86_64.nix b/pkgs/development/tools/rust/cargo-show-asm/test-basic-x86_64.nix new file mode 100644 index 000000000000..c0dd8b421b0a --- /dev/null +++ b/pkgs/development/tools/rust/cargo-show-asm/test-basic-x86_64.nix @@ -0,0 +1,18 @@ +{ runCommand, cargo, rustc, cargo-show-asm }: +runCommand "test-basic" { + nativeBuildInputs = [ cargo rustc cargo-show-asm ]; +} '' + mkdir -p src + cat >Cargo.toml <src/lib.rs < u32 { a + b } +EOF + + [[ "$(cargo asm add::add | tee /dev/stderr)" == *"lea eax, "* ]] + [[ "$(cargo asm --mir add | tee /dev/stderr)" == *"= Add("* ]] + touch $out +''