examples work as packages in flake
All checks were successful
Rust / build-gnu-apt (pull_request) Successful in 5m23s
Rust / build-size-gnu-unstable (pull_request) Successful in 1m14s

This commit is contained in:
Vinzenz Schroeter 2025-06-02 17:22:38 +02:00
parent 7b6b4f7e5b
commit d98aec63b0
4 changed files with 112 additions and 38 deletions

View file

@ -4,47 +4,55 @@
selfPkgs,
...
}:
let
defaultAdditionalPkgs = with pkgs; [
rustfmt
clippy
cargo-expand
cargo-tarpaulin
gdb
];
in
(builtins.mapAttrs (
packageName: package:
pkgs.mkShell {
inputsFrom = [ package ];
packages = with pkgs; [
rustfmt
clippy
cargo-expand
cargo-tarpaulin
gdb
];
packages = defaultAdditionalPkgs;
RUST_BACKTRACE = 1;
RUST_LOG = "all";
}
) selfPkgs)
// {
test = pkgs.mkShell {
packages = with pkgs; [
(pkgs.symlinkJoin {
name = "rust-toolchain";
paths = with pkgs; [
rustc
cargo
rustPlatform.rustcSrc
rustPlatform.rustLibSrc
rustfmt
clippy
cargo-expand
cargo-tarpaulin
];
})
gcc
gnumake
xe
libgcc
libunwind
pkgsStatic.gcc
pkgsStatic.libgcc
pkgsStatic.musl
default = pkgs.mkShell {
inputsFrom = [
selfPkgs.servicepoint-binding-c
selfPkgs.announce
];
packages =
defaultAdditionalPkgs
++ (with pkgs; [
(pkgs.symlinkJoin {
name = "rust-toolchain";
paths = with pkgs; [
rustc
cargo
rustPlatform.rustcSrc
rustPlatform.rustLibSrc
rustfmt
clippy
cargo-expand
cargo-tarpaulin
];
})
gcc
gnumake
xe
libgcc
libunwind
pkgsStatic.gcc
pkgsStatic.libgcc
pkgsStatic.musl
]);
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};

View file

@ -21,6 +21,21 @@
"type": "github"
}
},
"nix-filter": {
"locked": {
"lastModified": 1731533336,
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-filter",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1748302896,
@ -40,6 +55,7 @@
"root": {
"inputs": {
"fenix": "fenix",
"nix-filter": "nix-filter",
"nixpkgs": "nixpkgs"
}
},

View file

@ -3,6 +3,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
nix-filter.url = "github:numtide/nix-filter";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
@ -14,6 +15,7 @@
self,
nixpkgs,
fenix,
nix-filter
}:
let
supported-systems = [
@ -29,7 +31,7 @@
f rec {
inherit system self;
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
lib = pkgs.lib // nix-filter.lib;
fenix = inputs.fenix.packages.${system};
selfPkgs = self.packages.${system};
}

View file

@ -2,20 +2,31 @@
pkgs,
lib,
fenix,
selfPkgs,
...
}:
let
mkServicepointBindingC =
version = "0.15.0";
mkServicepoint =
{
rustPlatform,
buildType,
}:
rustPlatform.buildRustPackage (finalAttrs: {
inherit buildType;
inherit buildType version;
pname = "servicepoint-binding-c";
version = "0.15.0";
src = ./.;
src = lib.filter {
root = ./.;
include = [
./Cargo.lock
./Cargo.toml
./src
./build.rs
./LICENSE
./cbindgen.toml
];
};
cargoLock.lockFile = ./Cargo.lock;
meta = {
description = "C bindings for the servicepoint crate.";
@ -40,20 +51,57 @@ let
sed "s:\$out:$out:g" ${./servicepoint.pc.in} | sed "s:\$version:$version:g" > $out/lib/pkgconfig/servicepoint.pc
'';
});
mkExample =
{ name, servicepointBinding }:
pkgs.stdenv.mkDerivation {
inherit version;
pname = "servicepoint-c-example-${name}";
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = [ servicepointBinding ];
src = ./example/src;
#dontUnpack = true;
buildPhase = ''
mkdir -p $out/bin
gcc ${name}.c $(pkg-config --libs servicepoint --cflags) -o $out/bin/${name}
'';
};
rustPlatform-stable = pkgs.rustPlatform;
rustPlatform-unstable = pkgs.makeRustPlatform {
cargo = fenix.minimal.cargo;
rustc = fenix.minimal.rustc;
};
examples = [
"announce"
"brightness_tester"
"header_logger"
"moving_line"
"random_stuff"
"wiping_clear"
];
in
rec {
servicepoint-binding-c-release = mkServicepointBindingC {
servicepoint-binding-c-release = mkServicepoint {
buildType = "release";
rustPlatform = rustPlatform-stable;
};
servicepoint-binding-c-size-optimized = mkServicepointBindingC {
servicepoint-binding-c-size-optimized = mkServicepoint {
buildType = "size_optimized";
rustPlatform = rustPlatform-unstable;
};
servicepoint-binding-c = servicepoint-binding-c-release;
all-examples = pkgs.symlinkJoin {
name = "servicepoint-all-examples";
paths = builtins.map (e: selfPkgs.${e}) examples;
};
}
// (lib.genAttrs examples (
name:
mkExample {
inherit name;
servicepointBinding = selfPkgs.servicepoint-binding-c;
}
))