1
0
Fork 0

flake.nix: build package with naersk

This commit is contained in:
Astro 2024-02-23 15:01:33 +01:00
parent 30052f54ab
commit 1d150c310a
5 changed files with 74 additions and 11 deletions

2
Cargo.lock generated
View File

@ -439,6 +439,8 @@ dependencies = [
[[package]]
name = "stm32f1xx-hal"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30845662b9ce46a2ec04da97666a2b32458bee5032bb0452d0caf1536a96a542"
dependencies = [
"bitflags",
"bxcan",

View File

@ -20,6 +20,5 @@ embedded-midi = "0.1.2"
# hardware abstraction layer
[dependencies.stm32f1xx-hal]
path = "../stm32f1xx-hal"
#version = "0.10.0"
version = "0.10.0"
features = [ "rt", "stm32f103", "medium" ]

18
build.rs Normal file
View File

@ -0,0 +1,18 @@
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=memory.x");
}

View File

@ -18,7 +18,38 @@
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1698420672,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
"owner": "nix-community",
"repo": "naersk",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1708440434,
"narHash": "sha256-XY+B9mbhL/i+Q6fP6gBQ6P76rv9rWtpjQiUJ+DGtaUg=",
"path": "/nix/store/bjjfp9f2342bim734yyy498gvwxi301i-source",
"rev": "526d051b128b82ae045a70e5ff1adf8e6dafa560",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1699099776,
"narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=",
@ -34,7 +65,7 @@
"type": "github"
}
},
"nixpkgs_2": {
"nixpkgs_3": {
"locked": {
"lastModified": 1681358109,
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
@ -52,7 +83,8 @@
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"naersk": "naersk",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay",
"utils": "utils"
}
@ -60,7 +92,7 @@
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1699323235,

View File

@ -5,10 +5,11 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
naersk.url = "github:nix-community/naersk";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils, rust-overlay }:
outputs = { self, nixpkgs, utils, rust-overlay, naersk }:
let
name = "stm32-rust-nixos-template";
in
@ -44,17 +45,28 @@
--add-flags "${pkgs.lib.escapeShellArgs openOcdFlags}"
'';
};
rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
naersk' = pkgs.callPackage naersk {
cargo = rustToolchain;
rustc = rustToolchain;
};
in
rec {
devShells.default = with pkgs; mkShell {
nativeBuildInputs = [
(rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
cargo-binutils
gdb
openocd
openocd-f1
rustToolchain
cargo-binutils
gdb
openocd
openocd-f1
];
};
packages.blackknobs = naersk'.buildPackage {
src = ./.;
};
checks = packages;
}
);
}