fix(build): statically linked binaries for linux (#55)

This commit is contained in:
Jens Krause 2025-01-22 09:43:51 +01:00 committed by GitHub
parent 6d2bf5ac09
commit 59c99f4f5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 11 deletions

View File

@ -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

2
Cargo.lock generated
View File

@ -1191,7 +1191,7 @@ dependencies = [
[[package]]
name = "timr-tui"
version = "1.0.0"
version = "1.1.0-alpha"
dependencies = [
"clap",
"color-eyre",

View File

@ -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"

View File

@ -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