Browse Source

build firmware with Nix

pull/1/head
parent
commit
d2391e0aa1
  1. 2
      derivations.nix
  2. 2
      firmware/.cargo/config
  3. 21
      firmware/default.nix
  4. 9
      shell-firmware.nix

2
derivations.nix

@ -17,4 +17,6 @@ rec {
binutils-riscv = pkgs.callPackage ./compilers/binutils.nix { platform = "riscv32"; };
rust-riscv32imc-crates = pkgs.callPackage ./compilers/rust-riscv32imc-crates.nix { };
helloworld = pkgs.callPackage ./firmware { inherit rust-riscv32imc-crates binutils-riscv; };
}

2
firmware/.cargo/config

@ -1,2 +0,0 @@
[build]
target = "riscv32imc-unknown-none-elf"

21
firmware/default.nix

@ -0,0 +1,21 @@
{ rustPlatform, rust-riscv32imc-crates, binutils-riscv }:
rustPlatform.buildRustPackage rec {
name = "helloworld";
version = "0.0.0";
src = ./.;
cargoSha256 = "1j8ipk7mwf6jqjnddpvkdydhgl7lfddxkv6p1vhzlfhqlf8am42j";
buildPhase = ''
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
export RUSTFLAGS="-L ${rust-riscv32imc-crates}/lib/rustlib/riscv32imc-unknown-none-elf/lib -C linker=${binutils-riscv}/bin/riscv32-unknown-elf-ld -C link-arg=-Tlink.x"
cargo build --release --target riscv32imc-unknown-none-elf
'';
doCheck = false;
installPhase = ''
mkdir -p $out
cp target/riscv32imc-unknown-none-elf/release/helloworld $out
'';
}

9
shell-firmware.nix

@ -1,9 +0,0 @@
{ }:
let
pkgs = import <nixpkgs> { overlays = [ import ./overlay.nix ]; };
hx = import ./derivations.nix { inherit pkgs; };
in
pkgs.mkShell {
buildInputs = [ hx.rustc hx.rust-riscv32imc-crates hx.binutils-riscv hx.cargo ];
RUSTFLAGS="-L ${hx.rust-riscv32imc-crates}/lib/rustlib/riscv32imc-unknown-none-elf/lib -C linker=riscv32-unknown-elf-ld -C link-arg=-Tlink.x";
}
Loading…
Cancel
Save