examples work as packages in flake
This commit is contained in:
parent
7b6b4f7e5b
commit
d98aec63b0
|
@ -4,47 +4,55 @@
|
||||||
selfPkgs,
|
selfPkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
defaultAdditionalPkgs = with pkgs; [
|
||||||
|
rustfmt
|
||||||
|
clippy
|
||||||
|
cargo-expand
|
||||||
|
cargo-tarpaulin
|
||||||
|
gdb
|
||||||
|
];
|
||||||
|
in
|
||||||
(builtins.mapAttrs (
|
(builtins.mapAttrs (
|
||||||
packageName: package:
|
packageName: package:
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
inputsFrom = [ package ];
|
inputsFrom = [ package ];
|
||||||
packages = with pkgs; [
|
packages = defaultAdditionalPkgs;
|
||||||
rustfmt
|
|
||||||
clippy
|
|
||||||
cargo-expand
|
|
||||||
cargo-tarpaulin
|
|
||||||
gdb
|
|
||||||
];
|
|
||||||
|
|
||||||
RUST_BACKTRACE = 1;
|
RUST_BACKTRACE = 1;
|
||||||
RUST_LOG = "all";
|
RUST_LOG = "all";
|
||||||
}
|
}
|
||||||
) selfPkgs)
|
) selfPkgs)
|
||||||
// {
|
// {
|
||||||
test = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
packages = with pkgs; [
|
inputsFrom = [
|
||||||
(pkgs.symlinkJoin {
|
selfPkgs.servicepoint-binding-c
|
||||||
name = "rust-toolchain";
|
selfPkgs.announce
|
||||||
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
|
|
||||||
];
|
];
|
||||||
|
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}";
|
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
|
||||||
};
|
};
|
||||||
|
|
16
flake.lock
16
flake.lock
|
@ -21,6 +21,21 @@
|
||||||
"type": "github"
|
"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": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1748302896,
|
"lastModified": 1748302896,
|
||||||
|
@ -40,6 +55,7 @@
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"fenix": "fenix",
|
"fenix": "fenix",
|
||||||
|
"nix-filter": "nix-filter",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
||||||
|
nix-filter.url = "github:numtide/nix-filter";
|
||||||
fenix = {
|
fenix = {
|
||||||
url = "github:nix-community/fenix";
|
url = "github:nix-community/fenix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
fenix,
|
fenix,
|
||||||
|
nix-filter
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
supported-systems = [
|
supported-systems = [
|
||||||
|
@ -29,7 +31,7 @@
|
||||||
f rec {
|
f rec {
|
||||||
inherit system self;
|
inherit system self;
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib // nix-filter.lib;
|
||||||
fenix = inputs.fenix.packages.${system};
|
fenix = inputs.fenix.packages.${system};
|
||||||
selfPkgs = self.packages.${system};
|
selfPkgs = self.packages.${system};
|
||||||
}
|
}
|
||||||
|
|
60
packages.nix
60
packages.nix
|
@ -2,20 +2,31 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
fenix,
|
fenix,
|
||||||
|
selfPkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
mkServicepointBindingC =
|
version = "0.15.0";
|
||||||
|
mkServicepoint =
|
||||||
{
|
{
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
buildType,
|
buildType,
|
||||||
}:
|
}:
|
||||||
rustPlatform.buildRustPackage (finalAttrs: {
|
rustPlatform.buildRustPackage (finalAttrs: {
|
||||||
inherit buildType;
|
inherit buildType version;
|
||||||
|
|
||||||
pname = "servicepoint-binding-c";
|
pname = "servicepoint-binding-c";
|
||||||
version = "0.15.0";
|
src = lib.filter {
|
||||||
src = ./.;
|
root = ./.;
|
||||||
|
include = [
|
||||||
|
./Cargo.lock
|
||||||
|
./Cargo.toml
|
||||||
|
./src
|
||||||
|
./build.rs
|
||||||
|
./LICENSE
|
||||||
|
./cbindgen.toml
|
||||||
|
];
|
||||||
|
};
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
meta = {
|
meta = {
|
||||||
description = "C bindings for the servicepoint crate.";
|
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
|
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-stable = pkgs.rustPlatform;
|
||||||
rustPlatform-unstable = pkgs.makeRustPlatform {
|
rustPlatform-unstable = pkgs.makeRustPlatform {
|
||||||
cargo = fenix.minimal.cargo;
|
cargo = fenix.minimal.cargo;
|
||||||
rustc = fenix.minimal.rustc;
|
rustc = fenix.minimal.rustc;
|
||||||
};
|
};
|
||||||
|
examples = [
|
||||||
|
"announce"
|
||||||
|
"brightness_tester"
|
||||||
|
"header_logger"
|
||||||
|
"moving_line"
|
||||||
|
"random_stuff"
|
||||||
|
"wiping_clear"
|
||||||
|
];
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
servicepoint-binding-c-release = mkServicepointBindingC {
|
servicepoint-binding-c-release = mkServicepoint {
|
||||||
buildType = "release";
|
buildType = "release";
|
||||||
rustPlatform = rustPlatform-stable;
|
rustPlatform = rustPlatform-stable;
|
||||||
};
|
};
|
||||||
servicepoint-binding-c-size-optimized = mkServicepointBindingC {
|
servicepoint-binding-c-size-optimized = mkServicepoint {
|
||||||
buildType = "size_optimized";
|
buildType = "size_optimized";
|
||||||
rustPlatform = rustPlatform-unstable;
|
rustPlatform = rustPlatform-unstable;
|
||||||
};
|
};
|
||||||
servicepoint-binding-c = servicepoint-binding-c-release;
|
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;
|
||||||
|
}
|
||||||
|
))
|
||||||
|
|
Loading…
Reference in a new issue