-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathflake.nix
More file actions
276 lines (261 loc) · 10.8 KB
/
Copy pathflake.nix
File metadata and controls
276 lines (261 loc) · 10.8 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
{
description = "rumoca — a Modelica compiler (crane + fenix reproducible build)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
openmodelica.url = "git+https://github.com/jgoppert/OpenModelica?submodules=1&rev=a96aa1a682c463b0fd2d285b486c09a8b7fe496d";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
crane,
openmodelica,
fenix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
rumocaVersion = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
# Pin the EXACT toolchain from rust-toolchain.toml (nightly-2026-02-27 +
# rust-src + wasm32) via fenix, so the Nix build and CI use the same
# rustc the developers pin. The sha256 is discovered on first build.
rustToolchain = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-5twI9QsrPl0ryOZ4POGYAivSeI08jgmWnv0wVvzbjcE=";
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
ciJulia = pkgs.julia_111;
ciPython = pkgs.python312.withPackages (ps: [
ps.casadi
ps.ipython
ps.numpy
ps.pandas
ps.pip
ps.sympy
ps.virtualenv
]);
openModelicaCli = openmodelica.packages.${system}.default;
# Native libs the workspace links against. libudev (systemd) for the
# gamepad/input crates; clang/libclang for any bindgen-using dep.
# crane's cleanCargoSource keeps only *.rs + Cargo.*, but several build
# scripts embed non-Rust assets (jinja/toml templates under
# crates/*/src/templates, XSD schemas, .mo models). Keep the whole
# crates/ tree (plus the root manifests + .cargo config), scoped so we
# never pull in packages/ node_modules or examples/.venv.
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
path: _type:
let
rel = pkgs.lib.removePrefix (toString ./. + "/") (toString path);
in
pkgs.lib.hasPrefix "crates" rel
# examples/ holds the .mo models that crate examples `include_str!`
# (e.g. quadrotor_sil); keep it but drop the Python venv / node deps.
|| (
pkgs.lib.hasPrefix "examples" rel
&& !(pkgs.lib.hasInfix ".venv" rel)
&& !(pkgs.lib.hasInfix "node_modules" rel)
)
|| pkgs.lib.hasPrefix ".cargo" rel
|| rel == "Cargo.toml"
|| rel == "Cargo.lock"
|| rel == "rust-toolchain.toml";
name = "rumoca-src";
};
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.udev ];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
# The wasm binding crates are cdylibs for wasm32 and the python
# binding needs a Python interpreter; the reproducible native build
# targets only the CLI binaries. (CI's wasm/python jobs stay separate.)
cargoExtraArgs = "--bin rumoca --bin rumoca-lsp";
};
# Build the third-party dependency closure once; every package/check
# below reuses it so a code change never recompiles dependencies.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
rumoca = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
doCheck = false; # tests run in CI, not in the package build
# A dependency (gamepad/input) links libudev; autoPatchelfHook bakes
# the store RPATH into the binaries so they run outside a nix shell.
# libgcc_s (compiler runtime) is pulled from stdenv's cc lib.
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ pkgs.autoPatchelfHook ];
buildInputs = commonArgs.buildInputs ++ [ pkgs.stdenv.cc.cc.lib ];
}
);
# Store-native Python binding used by cross-repository integration
# builds. This replaces the workspace's mutable venv/wheel-by-mtime
# staging while retaining Rumoca's pinned fenix toolchain.
rumocaPython = pkgs.python312Packages.buildPythonPackage {
pname = "rumoca";
version = rumocaVersion;
pyproject = true;
inherit src;
sourceRoot = "rumoca-src/crates/rumoca-bind-python";
cargoRoot = "../..";
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
inherit src;
cargoRoot = ".";
name = "rumoca-${rumocaVersion}-cargo-vendor";
hash = "sha256-Vk0Rcz/z16eQOfluUF3dpob9uFES0D1bM09X/AUg5KU=";
};
nativeBuildInputs = [
rustToolchain
pkgs.pkg-config
pkgs.rustPlatform.cargoSetupHook
pkgs.rustPlatform.maturinBuildHook
];
# Parser build scripts refresh generated files inside the Cargo
# workspace. Nix sources are read-only, so make this derivation's
# private build copy writable without mutating the checkout.
postPatch = ''
chmod -R u+w ../..
'';
buildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.udev ];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
CARGO_TARGET_DIR = "target";
doCheck = false;
pythonImportsCheck = [ "rumoca" ];
};
rumocaPythonEnv = pkgs.python312.withPackages (_: [ rumocaPython ]);
# Release-mode artifacts for the MSL parity gate, built as one Cargo
# graph so the shard / merge / ModelicaTest / pinned-library consumers
# restore them via
# Cachix instead of recompiling + re-LTO'ing the workspace. A single
# derivation keeps rumoca-worker, rumoca-sim-worker, rumoca-msl-tools,
# the focused profile runner, and the libtest harness in one target
# directory; separate derivations
# rebuild the same workspace crates and made rumoca-worker a serial
# extra build.
msl-artifacts = craneLib.mkCargoDerivation (
commonArgs
// {
inherit cargoArtifacts;
pname = "rumoca-msl-artifacts";
buildPhaseCargoCommand = ''
cargo build --release \
-p rumoca-worker \
-p rumoca-test-msl \
--features rumoca-test-msl/msl-full-test \
--bin rumoca-worker \
--bin rumoca-sim-worker \
--bin rumoca-msl-tools \
--bin rumoca-msl-profile \
--test msl_tests
'';
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ pkgs.autoPatchelfHook ];
buildInputs = commonArgs.buildInputs ++ [ pkgs.stdenv.cc.cc.lib ];
installPhaseCommand = ''
mkdir -p $out/bin
bin=$(find target/release/deps -maxdepth 1 -type f \
-name 'msl_tests-*' ! -name '*.d' -perm -u+x | head -1)
test -n "$bin" || { echo "msl_tests test binary not found"; exit 1; }
cp "$bin" $out/bin/msl_tests
cp target/release/rumoca-worker $out/bin/rumoca-worker
cp target/release/rumoca-sim-worker $out/bin/rumoca-sim-worker
cp target/release/rumoca-msl-tools $out/bin/rumoca-msl-tools
cp target/release/rumoca-msl-profile $out/bin/rumoca-msl-profile
'';
}
);
templateRuntimeShell =
extraPackages:
craneLib.devShell {
inputsFrom = [ rumoca ];
packages = extraPackages;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.gfortran.cc.lib
pkgs.stdenv.cc.cc.lib
pkgs.zlib
];
};
# xtask itself is NOT built here: after the light-xtask split it carries no
# compiler deps and compiles per-job in seconds, so build-once buys nothing.
# The MSL merge and ModelicaTest jobs run reporting through the
# compiler-linked `rumoca-msl-tools` bin, so the MSL artifact bundle
# includes it and those jobs invoke the prebuilt binary instead of
# recompiling the stack.
in
{
packages = {
default = rumoca;
rumoca = rumoca;
# rumoca already builds `--bin rumoca-lsp`; alias so the LSP gate can
# `nix build .#rumoca-lsp` and read result/bin/rumoca-lsp.
rumoca-lsp = rumoca;
rumoca-python = rumocaPython;
rumoca-python-env = rumocaPythonEnv;
msl-artifacts = msl-artifacts;
}
// pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
openmodelica-cli = openModelicaCli;
};
checks = {
inherit rumoca;
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- -D warnings";
}
);
fmt = craneLib.cargoFmt { src = ./.; };
}
// pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
openmodelica-cli = openModelicaCli;
};
devShells.default = craneLib.devShell {
inputsFrom = [ rumoca ];
packages =
pkgs.lib.optionals pkgs.stdenv.isLinux [
ciJulia
]
++ pkgs.lib.optionals pkgs.stdenv.isLinux [
openModelicaCli
]
++ [
ciPython
pkgs.binaryen
pkgs.cargo-llvm-cov
pkgs.libxml2
pkgs.maturin
pkgs.mdbook
pkgs.nodejs_22
pkgs.wasm-pack
];
shellHook = ''
export PATH="''${CARGO_HOME:-$HOME/.cargo}/bin:$PATH"
'';
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (
[
pkgs.gfortran.cc.lib
pkgs.stdenv.cc.cc.lib
pkgs.zlib
]
++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.udev ]
);
};
devShells.ci-template-core = templateRuntimeShell [ ];
devShells.ci-template-python = templateRuntimeShell [ ciPython ];
devShells.ci-template-julia = templateRuntimeShell (
pkgs.lib.optionals pkgs.stdenv.isLinux [ ciJulia ]
);
}
);
}