WIP: type per command #4

Draft
vinzenz wants to merge 49 commits from next into main
Showing only changes of commit 53493a5fb1 - Show all commits

View file

@ -11,9 +11,12 @@ let
{ {
rustPlatform, rustPlatform,
pkgs, pkgs,
buildType ? "release",
buildNoDefaultFeatures ? false,
cargoBuildFlags ? [ ],
}: }:
rustPlatform.buildRustPackage (finalAttrs: { rustPlatform.buildRustPackage (finalAttrs: {
inherit version; inherit version buildType cargoBuildFlags;
pname = "servicepoint-binding-c"; pname = "servicepoint-binding-c";
src = lib.filter { src = lib.filter {
@ -57,9 +60,14 @@ let
name, name,
servicepointBinding, servicepointBinding,
pkgs, pkgs,
EXTRA_CFLAGS ? "",
static ? false,
}: }:
let
staticPkgConfigParam = if static then "--static" else "";
in
pkgs.gccStdenv.mkDerivation { pkgs.gccStdenv.mkDerivation {
inherit version; inherit version EXTRA_CFLAGS;
pname = "servicepoint-c-example-${name}"; pname = "servicepoint-c-example-${name}";
nativeBuildInputs = [ pkgs.pkg-config ]; nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ buildInputs = [
@ -71,19 +79,12 @@ let
set -e set -e
set -x set -x
mkdir -p $out/bin mkdir -p $out/bin
$CC ${name}.c $CFLAGS $EXTRA_CFLAGS $(pkg-config --libs --cflags servicepoint) $(pkg-config --libs --cflags liblzma) -o $out/bin/${name} $CC ${name}.c ${if static then "-static" else ""} $CFLAGS $EXTRA_CFLAGS \
$(pkg-config --libs --cflags ${staticPkgConfigParam} servicepoint) \
$(pkg-config --libs --cflags ${staticPkgConfigParam} liblzma) \
-o $out/bin/${name}
''; '';
}; };
rustPlatform-stable = pkgs.rustPlatform;
rustPlatform-unstable = pkgs.makeRustPlatform {
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 = [ examples = [
"announce" "announce"
"brightness_tester" "brightness_tester"
@ -92,6 +93,12 @@ let
"random_stuff" "random_stuff"
"wiping_clear" "wiping_clear"
]; ];
mkAllExamples =
suffix:
pkgs.symlinkJoin {
name = "servicepoint-all-examples";
paths = builtins.map (e: selfPkgs."${e}${suffix}") examples;
};
size-cflags = [ size-cflags = [
"-Oz" "-Oz"
"-fwrapv" "-fwrapv"
@ -112,54 +119,57 @@ let
"-Wl,--gc-sections" "-Wl,--gc-sections"
"-Wl,--exclude-libs,ALL" "-Wl,--exclude-libs,ALL"
]; ];
servicepoint-stable-size-args = { stable-size-args = {
buildType = "size_optimized"; buildType = "size_optimized";
buildNoDefaultFeatures = true; buildNoDefaultFeatures = true;
}; };
servicepoint-unstable-size-args = { unstable-size-args = {
# TODO: do these override the nix flags? cargoBuildFlags = ''-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 # 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_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"]; # NIX_CFLAGS_LINK = builtins.toString ["Wl,-z,norelro" "-Wl,--hash-style=gnu" "-Wl,--gc-sections" "-Wl,--exclude-libs,ALL"];
}; };
mkAllExamples = rustPlatform-stable = pkgs.rustPlatform;
suffix: rustPlatform-nightly = pkgs.makeRustPlatform {
pkgs.symlinkJoin { inherit (fenix.minimal) cargo rustc;
name = "servicepoint-all-examples"; };
paths = builtins.map (e: selfPkgs."${e}${suffix}") examples; rustPlatform-musl-stable = pkgs.pkgsMusl.rustPlatform;
}; rustPlatform-musl-nightly = pkgs.pkgsMusl.makeRustPlatform {
in inherit (fenix.minimal) cargo rustc;
rec { };
servicepoint-binding-c-stable-release = mkServicepoint { stable-release-args = {
inherit pkgs; inherit pkgs;
rustPlatform = rustPlatform-stable; rustPlatform = rustPlatform-stable;
}; };
servicepoint-binding-c-nightly-release = mkServicepoint { nightly-release-args = {
inherit pkgs; inherit pkgs;
rustPlatform = rustPlatform-unstable; rustPlatform = rustPlatform-nightly;
}; };
servicepoint-binding-c-musl-stable-release = mkServicepoint { musl-stable-release-args = {
pkgs = pkgs.pkgsMusl; pkgs = pkgs.pkgsMusl;
rustPlatform = rustPlatform-musl-stable; rustPlatform = rustPlatform-musl-stable;
}; };
servicepoint-binding-c-musl-nightly-release = mkServicepoint { musl-nightly-release-args = {
pkgs = pkgs.pkgsMusl; pkgs = pkgs.pkgsMusl;
rustPlatform = rustPlatform-musl-unstable; rustPlatform = rustPlatform-musl-nightly;
}; };
in
rec {
servicepoint-binding-c-stable-release = mkServicepoint stable-release-args;
servicepoint-binding-c-nightly-release = mkServicepoint nightly-release-args;
servicepoint-binding-c-musl-stable-release = mkServicepoint musl-stable-release-args;
servicepoint-binding-c-musl-nightly-release = mkServicepoint musl-nightly-release-args;
servicepoint-binding-c-stable-size = servicepoint-binding-c-stable-size = mkServicepoint (stable-release-args // stable-size-args);
servicepoint-binding-c-stable-release // servicepoint-stable-size-args; servicepoint-binding-c-nightly-size = mkServicepoint (
servicepoint-binding-c-nightly-size = nightly-release-args // stable-size-args // unstable-size-args
servicepoint-binding-c-nightly-release );
// servicepoint-stable-size-args servicepoint-binding-c-musl-stable-size = mkServicepoint (
// servicepoint-unstable-size-args; musl-stable-release-args // stable-size-args
servicepoint-binding-c-musl-stable-size = );
servicepoint-binding-c-musl-stable-release // servicepoint-stable-size-args; servicepoint-binding-c-musl-nightly-size = mkServicepoint (
servicepoint-binding-c-musl-nightly-size = musl-nightly-release-args // stable-size-args // unstable-size-args
servicepoint-binding-c-musl-nightly-release );
// servicepoint-stable-size-args
// servicepoint-unstable-size-args;
# default variants # default variants
servicepoint-binding-c = servicepoint-binding-c-stable-release; servicepoint-binding-c = servicepoint-binding-c-stable-release;
@ -181,26 +191,16 @@ rec {
} }
)) ))
# construct another pakage per example, but optimized for size with unstable rust # construct another pakage per example, but optimized for size with unstable rust
// (lib.mapAttrs' // (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-size") value) (
( lib.genAttrs examples (
name: value: name:
lib.nameValuePair ("${name}-size") ( mkExample {
value inherit name pkgs;
// { servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
EXTRA_CFLAGS = builtins.toString size-cflags; EXTRA_CFLAGS = builtins.toString size-cflags;
} }
)
) )
( ))
lib.genAttrs examples (
name:
mkExample {
inherit name pkgs;
servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
}
)
)
)
# construct another pakage per example, but with musl # construct another pakage per example, but with musl
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl") value) ( // (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl") value) (
lib.genAttrs examples ( lib.genAttrs examples (
@ -220,9 +220,7 @@ rec {
inherit name; inherit name;
pkgs = pkgs.pkgsMusl; pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl; servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
} static = true;
// {
EXTRA_CFLAGS = "-static";
} }
) )
)) ))
@ -234,9 +232,8 @@ rec {
inherit name; inherit name;
pkgs = pkgs.pkgsMusl; pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl; servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
} static = true;
// { EXTRA_CFLAGS = builtins.toString size-cflags;
EXTRA_CFLAGS = "-static" + builtins.toString size-cflags;
} }
) )
)) ))