-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
121 lines (107 loc) · 3.62 KB
/
flake.nix
File metadata and controls
121 lines (107 loc) · 3.62 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
{
description = "lean-ffi Nix flake (Lean4 + Rust)";
inputs = {
# System packages, follows lean4-nix so we stay in sync
nixpkgs.follows = "lean4-nix/nixpkgs";
# Lean 4 & Lake
lean4-nix.url = "github:lenianiva/lean4-nix";
# Helper: flake-parts for easier outputs
flake-parts.url = "github:hercules-ci/flake-parts";
# Rust-related inputs
fenix = {
url = "github:nix-community/fenix";
# Follow lean4-nix nixpkgs so we stay in sync
inputs.nixpkgs.follows = "lean4-nix/nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs = inputs @ {
nixpkgs,
flake-parts,
lean4-nix,
fenix,
crane,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
# Systems we want to build for
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
perSystem = {
system,
pkgs,
...
}: let
# Pins the Rust toolchain
rustToolchain = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-sqSWJDUxc+zaz1nBWMAJKTAGBuGWP25GCftIOlCEAtA=";
};
# Rust package
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource ./.;
craneArgs = {
inherit src;
strictDeps = true;
# build.rs uses LEAN_SYSROOT to locate lean/lean.h for bindgen
LEAN_SYSROOT = "${pkgs.lean.lean-all}";
# bindgen needs libclang to parse C headers
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
buildInputs =
[]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
rustPkg = craneLib.buildPackage (craneArgs // {cargoExtraArgs = "--locked";});
rustPkgTest = craneLib.buildPackage (craneArgs // {cargoExtraArgs = "--locked --features test-ffi";});
# Lake test package
lake2nix = pkgs.callPackage lean4-nix.lake {};
lakeTest = lake2nix.mkPackage {
name = "LeanFFITests";
src = ./.;
# Don't build the Rust static lib with Lake, since we build it with Crane
postPatch = ''
substituteInPlace lakefile.lean \
--replace-fail 'proc { cmd := "cargo"' '--proc { cmd := "cargo"' \
--replace-fail 'proc { cmd := "cp"' '--proc { cmd := "cp"'
'';
# Link the Rust static lib so Lake can find it
postConfigure = ''
mkdir -p target/release
ln -s ${rustPkgTest}/lib/liblean_ffi.a target/release/liblean_ffi_test.a
'';
};
in {
# Lean overlay
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [(lean4-nix.readToolchainFile ./lean-toolchain)];
};
packages = {
default = rustPkg;
test = lakeTest;
};
# Provide a unified dev shell with Lean + Rust
devShells.default = pkgs.mkShell {
# Disable fortify hardening as it causes warnings with cargo debug builds
hardeningDisable = ["fortify"];
# Add libclang for FFI with rust-bindgen
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
packages = with pkgs; [
clang
rustToolchain
rust-analyzer
lean.lean-all # Includes Lean compiler, lake, stdlib, etc.
valgrind
];
};
formatter = pkgs.alejandra;
};
};
}