-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
138 lines (125 loc) · 5.14 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
description = "things";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = {
url = "github:ipetkov/crane";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
parts.url = "github:hercules-ci/flake-parts";
parts.inputs.nixpkgs-lib.follows = "nixpkgs";
};
outputs =
inputs@{ self
, nixpkgs
, crane
, fenix
, parts
, ...
}:
parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;
imports = [
];
perSystem = { config, pkgs, system, lib, ... }:
let
arm-toolchain-plain = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-UH3aTxjEdeXYn/uojGVTHrJzZRCc3ODd05EDFvHmtKE=";
};
native-toolchain = (fenix.packages.${system}.complete.withComponents [
"cargo"
"clippy"
# "rust-src"
# "rustc"
# "rustfmt"
]);
arm-toolchain = pkgs.runCommand "turbowaker-rust" { } ''
echo "test $out ${arm-toolchain-plain}"
cp -RL ${arm-toolchain-plain} $out
chmod -R +rwx $out
echo "doing patch"
patch $out/lib/rustlib/src/rust/library/core/Cargo.toml ${./turbowaker/Cargo.toml.patch}
patch $out/lib/rustlib/src/rust/library/core/src/task/wake.rs ${./turbowaker/wake.rs.patch}
'';
toolchain = fenix.packages.${system}.combine [ arm-toolchain native-toolchain ];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
src = craneLib.cleanCargoSource ./.;
package = { target ? "thumbv6m-none-eabi", args ? "", profile ? "release" }: craneLib.buildPackage {
inherit src;
cargoVendorDir = craneLib.vendorMultipleCargoDeps {
inherit (craneLib.findCargoFiles src) cargoConfigs;
cargoLockList = [
./Cargo.lock
# Unfortunately this approach requires IFD (import-from-derivation)
# otherwise Nix will refuse to read the Cargo.lock from our toolchain
# (unless we build with `--impure`).
#
# Another way around this is to manually copy the rustlib `Cargo.lock`
# to the repo and import it with `./path/to/rustlib/Cargo.lock` which
# will avoid IFD entirely but will require manually keeping the file
# up to date!
"${toolchain}/lib/rustlib/src/rust/Cargo.lock"
];
};
cargoExtraArgs = "-Z build-std=core,panic_abort,alloc -Z build-std-features=optimize_for_size,panic_immediate_abort,core/turbowakers --target ${target} ${args}";
CARGO_PROFILE = profile;
pname = "rusty-dilemma";
version = "0.1.0";
strictDeps = true;
doCheck = false;
buildInputs = [
# Add additional build inputs here
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
elf = pkg: name: pkgs.runCommandLocal "mkelf" { } ''
mkdir -p $out
cp ${pkg}/bin/${name} $out/${name}.elf
'';
binary = pkg: name: pkgs.runCommandLocal "mkbinary" { buildInputs = [ pkgs.llvm ]; } ''
mkdir -p $out
llvm-objcopy -O binary ${pkg}/bin/${name} $out/${name}.bin
'';
in
rec
{
devShells.default = craneLib.devShell {
packages = with pkgs; [ picotool libiconv just ];
};
# binaries don't currently work because we need the macros package to be built with std supported, crane seems to do some weird stuff that makes it forced onto a no-std build env
# devShells.default = pkgs.mkShell {
# # inputsFrom = [ (firmware { args = "--lib"; profile = "dev"; }) ];
# nativeBuildInputs = with pkgs; [
# # fenix.packages.${system}.rust-analyzer
# # cargo-binutils
# # probe-rs
# picotool
# # pkgsCross.arm-embedded.buildPackages.binutils
# ];
# };
# packages.default = package { args = "--lib"; profile = "dev"; };
# packages.bin = package { args = "--bin binary --no-default-features"; profile = "release"; };
# packages.debug-bin = package { args = "--bin binary --features probe,m2"; profile = "dev"; };
# packages.binaries = pkgs.symlinkJoin {
# name = "dilemma-binaries";
# paths = [
# (elf packages.bin "binary")
# (binary packages.bin "binary")
# ];
# };
# packages.debug-binaries = pkgs.symlinkJoin {
# name = "dilemma-binaries";
# paths = [
# (elf packages.debug-bin "binary")
# (binary packages.debug-bin "binary")
# ];
# };
};
};
}