Skip to content

Commit

Permalink
build probe cli with static linking
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ex-32 committed Jul 10, 2024
1 parent 0fc3b1c commit f599692
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
41 changes: 31 additions & 10 deletions probe_src/probe_frontend/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions probe_src/probe_frontend/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -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;
Expand Down

0 comments on commit f599692

Please sign in to comment.