flake musl build
This commit is contained in:
parent
42defc7732
commit
471717a36f
|
@ -11,6 +11,7 @@ let
|
||||||
cargo-expand
|
cargo-expand
|
||||||
cargo-tarpaulin
|
cargo-tarpaulin
|
||||||
gdb
|
gdb
|
||||||
|
nix-output-monitor
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
(builtins.mapAttrs (
|
(builtins.mapAttrs (
|
||||||
|
|
|
@ -3,11 +3,22 @@
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
nix build .#servicepoint-binding-c
|
BUILD="nix build"
|
||||||
|
|
||||||
nix build .#servicepoint-binding-c-stable-release
|
$BUILD .#servicepoint-binding-c
|
||||||
nix build .#servicepoint-binding-c-nightly-release
|
|
||||||
nix build .#servicepoint-binding-c-nightly-size
|
|
||||||
|
|
||||||
nix build .#all-examples
|
$BUILD .#servicepoint-binding-c-stable-release
|
||||||
nix build .#all-examples-size
|
$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
|
||||||
|
|
170
packages.nix
170
packages.nix
|
@ -8,7 +8,10 @@
|
||||||
let
|
let
|
||||||
version = "0.15.0";
|
version = "0.15.0";
|
||||||
mkServicepoint =
|
mkServicepoint =
|
||||||
rustPlatform:
|
{
|
||||||
|
rustPlatform,
|
||||||
|
pkgs,
|
||||||
|
}:
|
||||||
rustPlatform.buildRustPackage (finalAttrs: {
|
rustPlatform.buildRustPackage (finalAttrs: {
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
|
@ -50,7 +53,11 @@ let
|
||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
mkExample =
|
mkExample =
|
||||||
{ name, servicepointBinding }:
|
{
|
||||||
|
name,
|
||||||
|
servicepointBinding,
|
||||||
|
pkgs,
|
||||||
|
}:
|
||||||
pkgs.gccStdenv.mkDerivation {
|
pkgs.gccStdenv.mkDerivation {
|
||||||
inherit version;
|
inherit version;
|
||||||
pname = "servicepoint-c-example-${name}";
|
pname = "servicepoint-c-example-${name}";
|
||||||
|
@ -64,7 +71,7 @@ let
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
mkdir -p $out/bin
|
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;
|
rustPlatform-stable = pkgs.rustPlatform;
|
||||||
|
@ -72,6 +79,11 @@ let
|
||||||
cargo = fenix.minimal.cargo;
|
cargo = fenix.minimal.cargo;
|
||||||
rustc = fenix.minimal.rustc;
|
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"
|
||||||
|
@ -80,65 +92,102 @@ let
|
||||||
"random_stuff"
|
"random_stuff"
|
||||||
"wiping_clear"
|
"wiping_clear"
|
||||||
];
|
];
|
||||||
in
|
size-cflags = [
|
||||||
rec {
|
"-Oz"
|
||||||
servicepoint-binding-c-stable-release = mkServicepoint rustPlatform-stable;
|
"-fwrapv"
|
||||||
servicepoint-binding-c-nightly-release = mkServicepoint rustPlatform-unstable;
|
"-fomit-frame-pointer"
|
||||||
servicepoint-binding-c-nightly-size = servicepoint-binding-c-nightly-release // {
|
"-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";
|
buildType = "size_optimized";
|
||||||
buildNoDefaultFeatures = true;
|
buildNoDefaultFeatures = true;
|
||||||
|
};
|
||||||
|
servicepoint-unstable-size-args = {
|
||||||
# TODO: do these override the nix flags?
|
# 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
|
# 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"];
|
||||||
};
|
};
|
||||||
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 {
|
servicepoint-binding-c-stable-size =
|
||||||
name = "servicepoint-all-examples";
|
servicepoint-binding-c-stable-release // servicepoint-stable-size-args;
|
||||||
paths = builtins.map (e: selfPkgs."${e}") examples;
|
servicepoint-binding-c-nightly-size =
|
||||||
};
|
servicepoint-binding-c-nightly-release
|
||||||
all-examples-size = pkgs.symlinkJoin {
|
// servicepoint-stable-size-args
|
||||||
name = "servicepoint-all-examples-size";
|
// servicepoint-unstable-size-args;
|
||||||
paths = builtins.map (e: selfPkgs."${e}-size") examples;
|
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
|
# construct one package per example
|
||||||
// (lib.genAttrs examples (
|
// (lib.genAttrs examples (
|
||||||
name:
|
name:
|
||||||
mkExample {
|
mkExample {
|
||||||
inherit name;
|
inherit name pkgs;
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c;
|
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'
|
// (lib.mapAttrs'
|
||||||
(
|
(
|
||||||
name: value:
|
name: value:
|
||||||
lib.nameValuePair ("${name}-size") (
|
lib.nameValuePair ("${name}-size") (
|
||||||
value
|
value
|
||||||
// {
|
// {
|
||||||
EXTRA_CFLAGS = builtins.toString [
|
EXTRA_CFLAGS = builtins.toString 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"
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -146,9 +195,48 @@ rec {
|
||||||
lib.genAttrs examples (
|
lib.genAttrs examples (
|
||||||
name:
|
name:
|
||||||
mkExample {
|
mkExample {
|
||||||
inherit name;
|
inherit name pkgs;
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
|
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;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
Loading…
Reference in a new issue