flake musl build
Some checks failed
Rust / build-gnu-apt (pull_request) Failing after 4m36s
Rust / build-size-gnu-unstable (pull_request) Failing after 56s

This commit is contained in:
Vinzenz Schroeter 2025-06-03 21:44:08 +02:00
parent 42defc7732
commit 471717a36f
3 changed files with 147 additions and 47 deletions

View file

@ -11,6 +11,7 @@ let
cargo-expand
cargo-tarpaulin
gdb
nix-output-monitor
];
in
(builtins.mapAttrs (

View file

@ -3,11 +3,22 @@
set -e
set -x
nix build .#servicepoint-binding-c
BUILD="nix build"
nix build .#servicepoint-binding-c-stable-release
nix build .#servicepoint-binding-c-nightly-release
nix build .#servicepoint-binding-c-nightly-size
$BUILD .#servicepoint-binding-c
nix build .#all-examples
nix build .#all-examples-size
$BUILD .#servicepoint-binding-c-stable-release
$BUILD .#servicepoint-binding-c-stable-size
$BUILD .#servicepoint-binding-c-nightly-release
$BUILD .#servicepoint-binding-c-nightly-size
$BUILD .#servicepoint-binding-c-musl-stable-release
$BUILD .#servicepoint-binding-c-musl-stable-size
# $BUILD .#servicepoint-binding-c-musl-nightly-release
# $BUILD .#servicepoint-binding-c-musl-nightly-size
$BUILD .#all-examples
$BUILD .#all-examples-size
$BUILD .#all-examples-musl
$BUILD .#all-examples-musl-static
$BUILD .#all-examples-musl-static-size

View file

@ -8,7 +8,10 @@
let
version = "0.15.0";
mkServicepoint =
rustPlatform:
{
rustPlatform,
pkgs,
}:
rustPlatform.buildRustPackage (finalAttrs: {
inherit version;
@ -50,7 +53,11 @@ let
'';
});
mkExample =
{ name, servicepointBinding }:
{
name,
servicepointBinding,
pkgs,
}:
pkgs.gccStdenv.mkDerivation {
inherit version;
pname = "servicepoint-c-example-${name}";
@ -64,7 +71,7 @@ let
set -e
set -x
mkdir -p $out/bin
gcc ${name}.c $(pkg-config --libs --cflags servicepoint) $(pkg-config --libs --cflags liblzma) $EXTRA_CFLAGS -o $out/bin/${name}
$CC ${name}.c $CFLAGS $EXTRA_CFLAGS $(pkg-config --libs --cflags servicepoint) $(pkg-config --libs --cflags liblzma) -o $out/bin/${name}
'';
};
rustPlatform-stable = pkgs.rustPlatform;
@ -72,6 +79,11 @@ let
cargo = fenix.minimal.cargo;
rustc = fenix.minimal.rustc;
};
rustPlatform-musl-stable = pkgs.pkgsMusl.rustPlatform;
rustPlatform-musl-unstable = pkgs.pkgsMusl.makeRustPlatform {
cargo = fenix.minimal.cargo;
rustc = fenix.minimal.rustc;
};
examples = [
"announce"
"brightness_tester"
@ -80,65 +92,102 @@ let
"random_stuff"
"wiping_clear"
];
in
rec {
servicepoint-binding-c-stable-release = mkServicepoint rustPlatform-stable;
servicepoint-binding-c-nightly-release = mkServicepoint rustPlatform-unstable;
servicepoint-binding-c-nightly-size = servicepoint-binding-c-nightly-release // {
size-cflags = [
"-Oz"
"-fwrapv"
"-fomit-frame-pointer"
"-fno-stack-protector"
"-fno-unroll-loops"
"-fno-unwind-tables"
"-fno-asynchronous-unwind-tables"
"-fmerge-all-constants"
"-fvisibility=hidden"
"-Bsymbolic"
"-fno-ident"
"-fno-exceptions"
"-ffunction-sections"
"-fdata-sections"
"-Wl,-z,norelro"
"-Wl,--hash-style=gnu"
"-Wl,--gc-sections"
"-Wl,--exclude-libs,ALL"
];
servicepoint-stable-size-args = {
buildType = "size_optimized";
buildNoDefaultFeatures = true;
};
servicepoint-unstable-size-args = {
# TODO: do these override the nix flags?
#CARGOFLAGS = ''-Zbuild-std="core,std,alloc,proc_macro,panic_abort" -Zbuild-std-features="panic_immediate_abort"'';
CARGOFLAGS = ''-Zbuild-std="core,std,alloc,proc_macro,panic_abort" -Zbuild-std-features="panic_immediate_abort"'';
# TODO: those override the nix flags
# NIX_CFLAGS_COMPILE = builtins.toString ["-Oz" "-fwrapv" "-fomit-frame-pointer" "-fno-stack-protector" "-fno-unroll-loops" "-fno-unwind-tables" "-fno-asynchronous-unwind-tables" "-fmerge-all-constants" "-fvisibility=hidden" "-Bsymbolic" "-fno-ident" "-fno-exceptions" "-ffunction-sections" "-fdata-sections"];
# NIX_CFLAGS_LINK = builtins.toString ["Wl,-z,norelro" "-Wl,--hash-style=gnu" "-Wl,--gc-sections" "-Wl,--exclude-libs,ALL"];
};
servicepoint-binding-c = servicepoint-binding-c-stable-release;
mkAllExamples =
suffix:
pkgs.symlinkJoin {
name = "servicepoint-all-examples";
paths = builtins.map (e: selfPkgs."${e}${suffix}") examples;
};
in
rec {
servicepoint-binding-c-stable-release = mkServicepoint {
inherit pkgs;
rustPlatform = rustPlatform-stable;
};
servicepoint-binding-c-nightly-release = mkServicepoint {
inherit pkgs;
rustPlatform = rustPlatform-unstable;
};
servicepoint-binding-c-musl-stable-release = mkServicepoint {
pkgs = pkgs.pkgsMusl;
rustPlatform = rustPlatform-musl-stable;
};
servicepoint-binding-c-musl-nightly-release = mkServicepoint {
pkgs = pkgs.pkgsMusl;
rustPlatform = rustPlatform-musl-unstable;
};
all-examples = pkgs.symlinkJoin {
name = "servicepoint-all-examples";
paths = builtins.map (e: selfPkgs."${e}") examples;
};
all-examples-size = pkgs.symlinkJoin {
name = "servicepoint-all-examples-size";
paths = builtins.map (e: selfPkgs."${e}-size") examples;
};
servicepoint-binding-c-stable-size =
servicepoint-binding-c-stable-release // servicepoint-stable-size-args;
servicepoint-binding-c-nightly-size =
servicepoint-binding-c-nightly-release
// servicepoint-stable-size-args
// servicepoint-unstable-size-args;
servicepoint-binding-c-musl-stable-size =
servicepoint-binding-c-musl-stable-release // servicepoint-stable-size-args;
servicepoint-binding-c-musl-nightly-size =
servicepoint-binding-c-musl-nightly-release
// servicepoint-stable-size-args
// servicepoint-unstable-size-args;
# default variants
servicepoint-binding-c = servicepoint-binding-c-stable-release;
servicepoint-binding-c-musl = servicepoint-binding-c-musl-stable-release;
all-examples = mkAllExamples "";
all-examples-size = mkAllExamples "-size";
# TODO: musl targets do not work on darwin
all-examples-musl = mkAllExamples "-musl";
all-examples-musl-static = mkAllExamples "-musl-static";
all-examples-musl-static-size = mkAllExamples "-musl-static-size";
}
# construct one package per example
// (lib.genAttrs examples (
name:
mkExample {
inherit name;
inherit name pkgs;
servicepointBinding = selfPkgs.servicepoint-binding-c;
}
))
# construct another pakage per example, but with a different name and compiler options
# construct another pakage per example, but optimized for size with unstable rust
// (lib.mapAttrs'
(
name: value:
lib.nameValuePair ("${name}-size") (
value
// {
EXTRA_CFLAGS = builtins.toString [
"-Oz"
"-fwrapv"
"-fomit-frame-pointer"
"-fno-stack-protector"
"-fno-unroll-loops"
"-fno-unwind-tables"
"-fno-asynchronous-unwind-tables"
"-fmerge-all-constants"
"-fvisibility=hidden"
"-Bsymbolic"
"-fno-ident"
"-fno-exceptions"
"-ffunction-sections"
"-fdata-sections"
"-Wl,-z,norelro"
"-Wl,--hash-style=gnu"
"-Wl,--gc-sections"
"-Wl,--exclude-libs,ALL"
];
EXTRA_CFLAGS = builtins.toString size-cflags;
}
)
)
@ -146,9 +195,48 @@ rec {
lib.genAttrs examples (
name:
mkExample {
inherit name;
inherit name pkgs;
servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
}
)
)
)
# construct another pakage per example, but with musl
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl") value) (
lib.genAttrs examples (
name:
mkExample {
inherit name;
pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
}
)
))
# construct another pakage per example, but statically linked with musl
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl-static") value) (
lib.genAttrs examples (
name:
mkExample {
inherit name;
pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
}
// {
EXTRA_CFLAGS = "-static";
}
)
))
# construct another pakage per example, but statically linked with musl and size optimized
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl-static-size") value) (
lib.genAttrs examples (
name:
mkExample {
inherit name;
pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
}
// {
EXTRA_CFLAGS = "-static" + builtins.toString size-cflags;
}
)
))