WIP: type per command #4

Draft
vinzenz wants to merge 49 commits from next into main
2 changed files with 52 additions and 36 deletions
Showing only changes of commit db94fecbb3 - Show all commits

View file

@ -3,22 +3,24 @@
set -e
set -x
BUILD="nix build"
BUILD="nix build -L"
$BUILD .#servicepoint-binding-c
$BUILD .#servicepoint-binding-c -o result
$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-stable-release -o result-stable-release
$BUILD .#servicepoint-binding-c-stable-size -o result-stable-size
$BUILD .#servicepoint-binding-c-nightly-release -o result-nightly-release
$BUILD .#servicepoint-binding-c-nightly-size -o result-nightly-size
$BUILD .#servicepoint-binding-c-musl-stable-release -o result-musl-release
$BUILD .#servicepoint-binding-c-musl-stable-size -o result-musl-size
$BUILD .#servicepoint-binding-c-musl-stable-release
$BUILD .#servicepoint-binding-c-musl-stable-size
# do not work yet:
# $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
$BUILD .#all-examples -o result-examples
$BUILD .#all-examples-size -o result-examples-size
$BUILD .#all-examples-nightly-size -o result-nightly-size
$BUILD .#all-examples-musl -o result-examples-musl
$BUILD .#all-examples-musl-static -o result-examples-musl-static
$BUILD .#all-examples-musl-static-size -o result-examples-musl-static-size

View file

@ -14,6 +14,7 @@ let
buildType ? "release",
buildNoDefaultFeatures ? false,
cargoBuildFlags ? [ ],
nativeBuildInputs ? []
}:
rustPlatform.buildRustPackage (finalAttrs: {
inherit version buildType cargoBuildFlags;
@ -38,7 +39,7 @@ let
license = lib.licenses.gpl3Plus;
pkgConfigModules = [ "servicepoint" ];
};
nativeBuildInputs = [ pkgs.pkg-config ];
nativeBuildInputs = [ pkgs.pkg-config ] ++ nativeBuildInputs;
buildInputs = [ pkgs.xz ];
preBuild = ''
@ -119,24 +120,10 @@ let
"-Wl,--gc-sections"
"-Wl,--exclude-libs,ALL"
];
stable-size-args = {
buildType = "size_optimized";
buildNoDefaultFeatures = true;
};
unstable-size-args = {
cargoBuildFlags = ''-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"];
};
rustPlatform-stable = pkgs.rustPlatform;
rustPlatform-nightly = pkgs.makeRustPlatform {
inherit (fenix.minimal) cargo rustc;
};
rustPlatform-nightly = pkgs.makeRustPlatform fenix.complete;
rustPlatform-musl-stable = pkgs.pkgsMusl.rustPlatform;
rustPlatform-musl-nightly = pkgs.pkgsMusl.makeRustPlatform {
inherit (fenix.minimal) cargo rustc;
};
rustPlatform-musl-nightly = pkgs.pkgsMusl.makeRustPlatform fenix.complete;
stable-release-args = {
inherit pkgs;
rustPlatform = rustPlatform-stable;
@ -153,6 +140,21 @@ let
pkgs = pkgs.pkgsMusl;
rustPlatform = rustPlatform-musl-nightly;
};
stable-size-args = {
buildType = "size_optimized";
buildNoDefaultFeatures = true;
};
nightly-size-args = {
cargoBuildFlags = [
"-Zbuild-std=core,std,alloc,proc_macro,panic_abort"
"-Zbuild-std-features=panic_immediate_abort"
];
# TODO: remove hard-coded target
nativeBuildInputs = [fenix.targets."x86_64-unknown-linux-gnu".latest.rust-std];
# 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"];
};
in
rec {
servicepoint-binding-c-stable-release = mkServicepoint stable-release-args;
@ -162,13 +164,13 @@ rec {
servicepoint-binding-c-stable-size = mkServicepoint (stable-release-args // stable-size-args);
servicepoint-binding-c-nightly-size = mkServicepoint (
nightly-release-args // stable-size-args // unstable-size-args
nightly-release-args // stable-size-args // nightly-size-args
);
servicepoint-binding-c-musl-stable-size = mkServicepoint (
musl-stable-release-args // stable-size-args
);
servicepoint-binding-c-musl-nightly-size = mkServicepoint (
musl-nightly-release-args // stable-size-args // unstable-size-args
musl-nightly-release-args // stable-size-args // nightly-size-args
);
# default variants
@ -177,6 +179,7 @@ rec {
all-examples = mkAllExamples "";
all-examples-size = mkAllExamples "-size";
all-examples-nightly-size = mkAllExamples "-nightly-size";
# TODO: musl targets do not work on darwin
all-examples-musl = mkAllExamples "-musl";
all-examples-musl-static = mkAllExamples "-musl-static";
@ -190,8 +193,19 @@ rec {
servicepointBinding = selfPkgs.servicepoint-binding-c;
}
))
# construct another pakage per example, but optimized for size with unstable rust
# construct another pakage per example, but optimized for size with stable rust
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-size") value) (
lib.genAttrs examples (
name:
mkExample {
inherit name pkgs;
servicepointBinding = selfPkgs.servicepoint-binding-c-stable-size;
EXTRA_CFLAGS = builtins.toString size-cflags;
}
)
))
# construct another pakage per example, but optimized for size with unstable rust
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-unstable-size") value) (
lib.genAttrs examples (
name:
mkExample {
@ -208,7 +222,7 @@ rec {
mkExample {
inherit name;
pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl-stable-release;
}
)
))
@ -219,7 +233,7 @@ rec {
mkExample {
inherit name;
pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl-stable-release;
static = true;
}
)
@ -231,7 +245,7 @@ rec {
mkExample {
inherit name;
pkgs = pkgs.pkgsMusl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
servicepointBinding = selfPkgs.servicepoint-binding-c-musl-stable-size;
static = true;
EXTRA_CFLAGS = builtins.toString size-cflags;
}