Compare commits

..

2 Commits

Author SHA1 Message Date
Nathan McCarty 7d9b2d1818
Add a test crate 2023-05-13 15:15:46 -04:00
Nathan McCarty d05b9e331e
Add generator for single crate flake 2023-05-13 15:11:02 -04:00
10 changed files with 44 additions and 51 deletions

2
.gitignore vendored
View File

@ -3,5 +3,3 @@
*.log *.log
tmp/ tmp/
result result
result-doc
target

View File

@ -24,7 +24,7 @@
with builtins; with builtins;
let let
sources = fromJSON (readFile ./sources/sources.json); sources = fromJSON (readFile ./sources/sources.json);
rustPackageNames = attrNames sources ++ [ "cargo-release" "cargo-deny" ]; rustPackageNames = attrValues sources;
# Build the rust packages we'll be using # Build the rust packages we'll be using
in (utils.lib.eachDefaultSystem (system: { in (utils.lib.eachDefaultSystem (system: {
packages = let packages = let
@ -39,24 +39,18 @@
rustc = rust; rustc = rust;
cargo = rust; cargo = rust;
}; };
in (mapAttrs (name: source: in mapAttrs (name: source:
naersk-lib.buildPackage { naersk-lib.buildPackage {
pname = source.pname; pname = source.pname;
src = pkgs.fetchCrate source; src = pkgs.fetchCrate source;
buildInputs = with pkgs; [ pkg-config openssl ]; }) sources;
}) sources) //
# Packages that naersk has trouble building due to https://github.com/nix-community/naersk/issues/263
{
cargo-release = pkgs.cargo-release;
cargo-deny = pkgs.cargo-deny;
};
})) // })) //
# Now provide our builder functions # Now provide our builder functions
{ {
# Build a rust flake with a single crate # Build a rust flake with a single crate
single = { src, crateName, sharedDeps ? (system: [ ]) single = { src, crateName, sharedDeps ? (system: [ ])
, sharedNativeDeps ? (system: [ ]) }: , sharedNativeDeps ? (system: [ ]) }:
utils.lib.eachDefaultSystem (system: utils.lib.eachDefaultsystem (system:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
@ -161,7 +155,7 @@
# Development environments # Development environments
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
inputsFrom = builtins.attrValues packages; inputsFrom = builtins.attrValues packages.${system};
buildInputs = [ rust ] ++ devBase ++ (sharedDeps system) buildInputs = [ rust ] ++ devBase ++ (sharedDeps system)
++ (sharedNativeDeps system); ++ (sharedNativeDeps system);
}; };

View File

@ -1,4 +1,6 @@
cargo-llvm-cov cargo-llvm-cov
cargo-nextest cargo-nextest
cargo-release
cargo-udeps cargo-udeps
cargo-audit cargo-audit
cargo-deny

View File

@ -4,6 +4,11 @@
"pname": "cargo-audit", "pname": "cargo-audit",
"version": "0.17.6" "version": "0.17.6"
}, },
"cargo-deny": {
"hash": "sha256-/2HClc4rzQvvbmWXOotZuC9MEPPnPZKWCOVC2AadtG4=",
"pname": "cargo-deny",
"version": "0.13.9"
},
"cargo-llvm-cov": { "cargo-llvm-cov": {
"hash": "sha256-5xHDjNFQDmi+SnhxfoCxoBdCqHpZEk/87r2sBKsT+W4=", "hash": "sha256-5xHDjNFQDmi+SnhxfoCxoBdCqHpZEk/87r2sBKsT+W4=",
"pname": "cargo-llvm-cov", "pname": "cargo-llvm-cov",
@ -14,6 +19,11 @@
"pname": "cargo-nextest", "pname": "cargo-nextest",
"version": "0.9.52" "version": "0.9.52"
}, },
"cargo-release": {
"hash": "sha256-tmyIQMjKs37ZVqG/WV4Qe99Jc+bzneTmEMrvxV1Gnsc=",
"pname": "cargo-release",
"version": "0.24.10"
},
"cargo-udeps": { "cargo-udeps": {
"hash": "sha256-jvEhE/fngzEzRinA4iZYJbBfcl2CGbTwQB52h5laVf8=", "hash": "sha256-jvEhE/fngzEzRinA4iZYJbBfcl2CGbTwQB52h5laVf8=",
"pname": "cargo-udeps", "pname": "cargo-udeps",

View File

@ -1 +0,0 @@
use flake

7
test-crate/Cargo.lock generated
View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "test-crate"
version = "0.1.0"

View File

@ -1,26 +0,0 @@
#!/usr/bin/env bash
###
## This script replicates the same steps as ci, except for cargo audit
###
# Turn on the guard rails
set -exuo pipefail
CRATE="test-crate"
## TODO use subshell magic to make a nice interface here
# Lint the formatting
nix build .#lints.format.$CRATE -L
# Audit it
nix develop -c cargo audit
# Run clippy
nix build .#lints.clippy.$CRATE -L
# Build it
nix build .#$CRATE -L
# Test it
nix develop -c cargo nextest run
nix develop -c cargo test --doc
# Document it
nix build .#docs.$CRATE.doc -L

25
test-crate/flake.lock Normal file
View File

@ -0,0 +1,25 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1683777345,
"narHash": "sha256-V2p/A4RpEGqEZussOnHYMU6XglxBJGCODdzoyvcwig8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "635a306fc8ede2e34cb3dd0d6d0a5d49362150ed",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View File

@ -1,10 +1,10 @@
{ {
inputs = { rust = { url = "./.."; }; }; inputs = { rust = { url = ./..; }; };
description = "Simple Test Package"; description = "Simple Test Package";
outputs = { self, nixpkgs, rust }: outputs = { self, nixpkgs, rust }:
rust.single { rust.single {
crateName = "test-crate"; name = "test-crate";
src = ./.; src = ./.;
}; };
} }

View File

@ -1,2 +0,0 @@
/// Doc comment
pub fn thing() {}