From f5996924514c908c00b91e9fc78cb6d99f0fa3f3 Mon Sep 17 00:00:00 2001 From: Jenna Fligor Date: Wed, 10 Jul 2024 18:23:21 -0500 Subject: [PATCH] build probe cli with static linking building the probe cli with `cargo build` inside the devShell will still produce a dynamically linked binary, but building with `nix build .#probe-cli` should produce a statically linked binary --- probe_src/probe_frontend/flake.lock | 41 ++++++++++++++++++++++------- probe_src/probe_frontend/flake.nix | 38 +++++++++++++++++++++----- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/probe_src/probe_frontend/flake.lock b/probe_src/probe_frontend/flake.lock index fd766282..3594030f 100644 --- a/probe_src/probe_frontend/flake.lock +++ b/probe_src/probe_frontend/flake.lock @@ -3,11 +3,11 @@ "advisory-db": { "flake": false, "locked": { - "lastModified": 1719411196, - "narHash": "sha256-EdryZFXPjkK2F2J1re/bOl2oezKAB7dpFNi9mLUygmI=", + "lastModified": 1720572893, + "narHash": "sha256-EQfU1yMnebn7LoJNjjsQimyuWwz+2YzazqUZu8aX/r4=", "owner": "rustsec", "repo": "advisory-db", - "rev": "34f191da603f67b491a2e12af0b93c9c794ae1d1", + "rev": "97a2dc75838f19a5fd63dc3f8e3f57e0c4c8cfe6", "type": "github" }, "original": { @@ -23,11 +23,11 @@ ] }, "locked": { - "lastModified": 1719249093, - "narHash": "sha256-0q1haa3sw6GbmJ+WhogMnducZGjEaCa/iR6hF2vq80I=", + "lastModified": 1720546058, + "narHash": "sha256-iU2yVaPIZm5vMGdlT0+57vdB/aPq/V5oZFBRwYw+HBM=", "owner": "ipetkov", "repo": "crane", - "rev": "9791c77eb7e98b8d8ac5b0305d47282f994411ca", + "rev": "2d83156f23c43598cf44e152c33a59d3892f8b29", "type": "github" }, "original": { @@ -56,11 +56,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1719379843, - "narHash": "sha256-u+D+IOAMMl70+CJ9NKB+RMrASjInuIWMHzjLWQjPZ6c=", + "lastModified": 1720594544, + "narHash": "sha256-w6dlBUQYvS65f0Z33TvkcAj7ITr4NFqhF5ywss5T5bU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b3f3c1b13fb08f3828442ee86630362e81136bbc", + "rev": "aa9461550594533c29866d42f861b6ff079a7fb6", "type": "github" }, "original": { @@ -75,7 +75,28 @@ "advisory-db": "advisory-db", "crane": "crane", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720577957, + "narHash": "sha256-RZuzLdB/8FaXaSzEoWLg3au/mtbuH7MGn2LmXUKT62g=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a434177dfcc53bf8f1f348a3c39bfb336d760286", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } }, "systems": { diff --git a/probe_src/probe_frontend/flake.nix b/probe_src/probe_frontend/flake.nix index 55c8d114..d58fb262 100644 --- a/probe_src/probe_frontend/flake.nix +++ b/probe_src/probe_frontend/flake.nix @@ -15,6 +15,11 @@ url = "github:rustsec/advisory-db"; flake = false; }; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; # TODO: cleanup derivations and make more usable: @@ -27,13 +32,28 @@ crane, flake-utils, advisory-db, + rust-overlay, ... - }: - flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; - # inherit (pkgs) lib; + }: let + systems = { + # "nix system" = "rust target"; + "x86_64-linux" = "x86_64-unknown-linux-musl"; + "i686-linux" = "i686-unknown-linux-musl"; + "aarch64-linux" = "aarch64-unknown-linux-musl"; + "armv7l-linux" = "armv7-unknown-linux-musleabi"; + }; + in + flake-utils.lib.eachSystem (builtins.attrNames systems) (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + + craneLib = (crane.mkLib pkgs).overrideToolchain (p: + p.rust-bin.stable.latest.default.override { + targets = [systems.${system}]; + }); - craneLib = crane.mkLib pkgs; src = ./.; # Common arguments can be set here to avoid repeating them later @@ -49,8 +69,12 @@ # pygen needs to know where to write the python file postUnpack = '' - export PYGEN_OUTFILE="$(realpath ./python)" + mkdir -p ./python + export PYGEN_OUTFILE="$(realpath ./python/ops.py)" ''; + + CARGO_BUILD_TARGET = "${systems.${system}}"; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; }; # Build *just* the cargo dependencies (of the entire workspace), @@ -62,7 +86,7 @@ individualCrateArgs = commonArgs // { - inherit cargoArtifacts; + # inherit cargoArtifacts; inherit (craneLib.crateNameFromCargoToml {inherit src;}) version; # disable tests since we'll run them all via cargo-nextest doCheck = false;