From ce80c5e23b22b4afb862ecf8ead5d45e7d518862 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Mon, 15 May 2023 22:58:40 +0200 Subject: [PATCH] Build release as a static binary --- .gitignore | 1 + flake.nix | 11 +++++++++-- rust-toolchain.toml | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c8cc50d..fc5ecd1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target .cargo +/result diff --git a/flake.nix b/flake.nix index 474b726..32a8b45 100644 --- a/flake.nix +++ b/flake.nix @@ -25,10 +25,17 @@ in { - defaultPackage = naersk-lib.buildPackage ./.; - devShell = with pkgs; mkShell { + defaultPackage = naersk-lib.buildPackage { + src = ./.; + doCheck = false; + nativeBuildInputs = [ pkgs.pkgsStatic.stdenv.cc ]; + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; + }; + devShell = pkgs.mkShell { nativeBuildInputs = [ toolchain + pkgs.glibc.static ]; shellHook = '' source $(pwd)/.env.dev diff --git a/rust-toolchain.toml b/rust-toolchain.toml index ce8c107..4b25b8b 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,4 @@ [toolchain] channel = "nightly-2023-05-08" components = [ "rustfmt", "rustc-dev", "clippy", "cargo" ] +targets = [ "x86_64-unknown-linux-musl" ]