From 59c99f4f5c1bc45400db2e056f47ef9175c42537 Mon Sep 17 00:00:00 2001 From: Jens Krause <47693+sectore@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:43:51 +0100 Subject: [PATCH] fix(build): statically linked binaries for linux (#55) --- .github/workflows/release.yml | 10 +++++++--- Cargo.lock | 2 +- Cargo.toml | 2 +- flake.nix | 19 +++++++++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b35082c..2282523 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,7 +31,7 @@ jobs: - os: ubuntu-latest os_target: linux binary_name: timr-tui - arch: x86_64 # `x86_64` by default + arch: x86_64 # based on target 'x86_64-unknown-linux-musl' defined by `CARGO_BUILD_TARGET` in flake.nix - os: ubuntu-latest os_target: windows binary_name: timr-tui.exe @@ -49,8 +49,12 @@ jobs: if: matrix.os_target == 'windows' run: nix build .#windows - - name: Build (linux/macos) - if: matrix.os_target != 'windows' + - name: Build (linux) + if: matrix.os_target == 'linux' + run: nix build .#linuxStatic + + - name: Build (macos) + if: matrix.os_target == 'macos' run: nix build - name: Copy artifact diff --git a/Cargo.lock b/Cargo.lock index c2a6cdc..51d56dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1191,7 +1191,7 @@ dependencies = [ [[package]] name = "timr-tui" -version = "1.0.0" +version = "1.1.0-alpha" dependencies = [ "clap", "color-eyre", diff --git a/Cargo.toml b/Cargo.toml index 4996758..b7480f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "timr-tui" -version = "1.0.0" +version = "1.1.0-alpha" description = "TUI to organize your time: Pomodoro, Countdown, Timer." edition = "2021" rust-version = "1.84.0" diff --git a/flake.nix b/flake.nix index c39560c..cfa7a43 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,7 @@ minimal.rustc minimal.cargo targets.x86_64-pc-windows-gnu.latest.rust-std + targets.x86_64-unknown-linux-musl.latest.rust-std ]; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; @@ -32,19 +33,24 @@ cargoArtifacts = craneLib.buildDepsOnly { src = craneLib.cleanCargoSource ./.; }; + strictDeps = true; doCheck = false; # skip tests during nix build }; # Native build timr = craneLib.buildPackage commonArgs; + # Linux build w/ statically linked binaries + staticLinuxBuild = craneLib.buildPackage (commonArgs + // { + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; + }); + # Windows cross-compilation build # @see https://crane.dev/examples/cross-windows.html - crossBuild = craneLib.buildPackage { - src = craneLib.cleanCargoSource ./.; - - strictDeps = true; - doCheck = false; + windowsBuild = craneLib.buildPackage { + inherit (commonArgs) src strictDeps doCheck; CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; @@ -65,7 +71,8 @@ packages = { inherit timr; default = timr; - windows = crossBuild; + linuxStatic = staticLinuxBuild; + windows = windowsBuild; }; # Development shell with all necessary tools