-
Notifications
You must be signed in to change notification settings - Fork 38
/
flake.nix
111 lines (102 loc) · 3.9 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
description = "The core crate for Drone, an Embedded Operating System";
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-22.05";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, utils, nixpkgs, fenix }:
utils.lib.eachDefaultSystem (system:
let
rustChannel = {
channel = "nightly";
date = "2022-11-12";
sha256 = "NZrKSshDgITZuDSffP89NpZl/pQlblc7arXatkV+O9A=";
};
pkgs = nixpkgs.legacyPackages.${system};
rustToolchain = with fenix.packages.${system}; combine
(with toolchainOf rustChannel; [
rustc
cargo
clippy
rustfmt
rust-src
]);
rustAnalyzer = fenix.packages.${system}.rust-analyzer;
cargoRdme = (
pkgs.rustPlatform.buildRustPackage rec {
name = "cargo-rdme";
src = pkgs.fetchFromGitHub {
owner = "orium";
repo = name;
rev = "v0.7.3";
sha256 = "qzit/uYkyWiOqpO5sHYo2hKJvOhovcO+oVbq/Bo2HsI=";
};
cargoSha256 = "lbyLVmSLNt4mt6hQbJnCuNL1Y1/2E/81sVpLYOkv7w8=";
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ];
doCheck = false;
});
checkAll = pkgs.writeShellScriptBin "check-all" ''
set -ex
cargo rdme --check
cargo fmt --all --check
cargo clippy --workspace -- --deny warnings
cargo clippy --workspace --features atomics -- --deny warnings
cargo test --workspace --exclude drone-core
cargo test --package drone-core --features host
cargo test --package drone-core --features host,atomics
RUSTFLAGS='--cfg loom' cargo test --package drone-core --features host,atomics --release loom
RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --workspace --features atomics
'';
updateVersions = pkgs.writeShellScriptBin "update-versions" ''
sed -i "s/\(api\.drone-os\.com\/drone-core\/\)[0-9]\+\(\.[0-9]\+\)\+/\1$(echo $1 | sed 's/\(.*\)\.[0-9]\+/\1/')/" \
Cargo.toml macros/Cargo.toml macros-core/Cargo.toml src/lib.rs
sed -i "/\[.*\]/h;/version = \".*\"/{x;s/\[workspace.package\]/version = \"$1\"/;t;x}" \
Cargo.toml
sed -i "/\[.*\]/h;/version = \"=.*\"/{x;s/\[.*drone-.*\]/version = \"=$1\"/;t;x}" \
Cargo.toml
sed -i "/\[.*\]/h;/version = \".*\"/{x;s/\[.*drone-\(stream\|config\)\]/version = \"$2\"/;t;x}" \
Cargo.toml
sed -i "s/\(drone-core.*\)version = \"[^\"]\+\"/\1version = \"$1\"/" \
src/lib.rs
'';
publishCrates = pkgs.writeShellScriptBin "publish-crates" ''
cd macros-core && cargo publish
sleep 30
cd macros && cargo publish
sleep 30
cargo publish
'';
publishDocs = pkgs.writeShellScriptBin "publish-docs" ''
dir=$(sed -n 's/.*api\.drone-os\.com\/\(.*\/.*\)\/.*\/"/\1/;T;p' Cargo.toml) \
&& rm -rf ../drone-api/$dir \
&& cp -rT target/doc ../drone-api/$dir \
&& echo '<!DOCTYPE html><meta http-equiv="refresh" content="0; URL=./drone_core">' > ../drone-api/$dir/index.html \
&& cd ../drone-api && git add $dir && git commit -m "Docs for $dir"
'';
shell = pkgs.mkShell {
name = "native";
nativeBuildInputs = [
rustToolchain
rustAnalyzer
cargoRdme
checkAll
updateVersions
publishCrates
publishDocs
];
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
in
{
devShells = {
native = shell;
default = shell;
};
}
);
}