Skip to content

Commit 75cd12d

Browse files
authored
Merge pull request #60 from Detegr/flake
Add Nix flake based build
2 parents eff8479 + 13093e8 commit 75cd12d

File tree

3 files changed

+239
-12
lines changed

3 files changed

+239
-12
lines changed

flake.lock

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
description = "Neotron BMC";
3+
4+
inputs = {
5+
flake-utils.url = "github:numtide/flake-utils";
6+
rust-overlay = {
7+
url = "github:oxalica/rust-overlay";
8+
inputs = {
9+
nixpkgs.follows = "nixpkgs";
10+
flake-utils.follows = "flake-utils";
11+
};
12+
};
13+
crane = {
14+
url = "github:ipetkov/crane";
15+
inputs = {
16+
nixpkgs.follows = "nixpkgs";
17+
flake-utils.follows = "flake-utils";
18+
rust-overlay.follows = "rust-overlay";
19+
};
20+
};
21+
};
22+
23+
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }:
24+
let
25+
# List of systems this flake.nix has been tested to work with
26+
systems = [ "x86_64-linux" ];
27+
pkgsForSystem = system: nixpkgs.legacyPackages.${system}.appendOverlays [
28+
rust-overlay.overlays.default
29+
];
30+
in
31+
flake-utils.lib.eachSystem systems
32+
(system:
33+
let
34+
pkgs = pkgsForSystem system;
35+
toolchain = pkgs.rust-bin.stable.latest.default.override {
36+
targets = [ "thumbv6m-none-eabi" ];
37+
};
38+
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
39+
40+
bmc-pico = craneLib.mkCargoDerivation {
41+
pname = "neotron-bmc-pico";
42+
version = (craneLib.crateNameFromCargoToml {
43+
cargoToml = ./neotron-bmc-pico/Cargo.toml;
44+
}).version;
45+
cargoArtifacts = null;
46+
cargoVendorDir = craneLib.vendorCargoDeps { src = ./neotron-bmc-pico; };
47+
src = with pkgs.lib;
48+
let keep = suffixes: path: type: any (s: hasSuffix s path) suffixes;
49+
in
50+
cleanSourceWith {
51+
src = craneLib.path ./.;
52+
filter = path: type: any id (map (f: f path type) [
53+
craneLib.filterCargoSources
54+
(keep [
55+
".md" # neotron-bmc-protocol needs README.md
56+
".x"
57+
])
58+
]);
59+
};
60+
buildPhaseCargoCommand = ''
61+
cd neotron-bmc-pico # because .cargo/config.toml exists here
62+
cargo build --release --target=thumbv6m-none-eabi
63+
'';
64+
nativeBuildInputs = [
65+
pkgs.makeWrapper
66+
pkgs.probe-run
67+
pkgs.flip-link
68+
];
69+
installPhase = ''
70+
mkdir -p $out/bin
71+
cp target/thumbv6m-none-eabi/release/neotron-bmc-pico $out/bin/
72+
makeWrapper ${pkgs.probe-run}/bin/probe-run $out/bin/flash-neotron-bmc-pico \
73+
--set DEFMT_LOG info \
74+
--add-flags "--chip STM32F030K6Tx $out/bin/neotron-bmc-pico"
75+
'';
76+
};
77+
in rec
78+
{
79+
packages.neotron-bmc-pico = bmc-pico;
80+
defaultPackage = packages.neotron-bmc-pico;
81+
82+
defaultApp = apps.neotron-bmc-pico;
83+
apps.neotron-bmc-pico = flake-utils.lib.mkApp {
84+
drv = bmc-pico;
85+
exePath = "/bin/flash-neotron-bmc-pico";
86+
};
87+
88+
devShell = pkgs.mkShell {
89+
nativeBuildInputs = [
90+
toolchain
91+
pkgs.probe-run
92+
pkgs.flip-link
93+
];
94+
};
95+
}
96+
);
97+
}

neotron-bmc-pico/build.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ fn main() {
1717
println!("cargo:rerun-if-changed=memory.x");
1818

1919
// Generate a file containing the firmware version
20-
let version_output = std::process::Command::new("git")
20+
let mut output;
21+
if let Ok(version_output) = std::process::Command::new("git")
2122
.current_dir(env::var_os("CARGO_MANIFEST_DIR").unwrap())
2223
.args(["describe", "--tags", "--dirty"])
2324
.output()
24-
.expect("running git-describe");
25+
{
26+
println!(
27+
"Version is {:?}",
28+
std::str::from_utf8(&version_output.stdout)
29+
);
30+
println!("Error is {:?}", std::str::from_utf8(&version_output.stderr));
31+
assert!(version_output.status.success());
2532

26-
println!(
27-
"Version is {:?}",
28-
std::str::from_utf8(&version_output.stdout)
29-
);
30-
println!("Error is {:?}", std::str::from_utf8(&version_output.stderr));
31-
assert!(version_output.status.success());
32-
33-
// Remove the trailing newline
34-
let mut output = version_output.stdout;
35-
output.pop();
33+
// Remove the trailing newline
34+
output = version_output.stdout;
35+
output.pop();
36+
} else {
37+
output = String::from(env!("CARGO_PKG_VERSION")).into_bytes();
38+
}
3639

3740
if output.len() >= 32 {
3841
panic!("Version too long!");

0 commit comments

Comments
 (0)