-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
118 lines (114 loc) · 3.88 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
{
description = "OpenGL bindings for Lean";
inputs = {
lean = {
url = github:leanprover/lean4;
};
nixpkgs.url = github:nixos/nixpkgs;
flake-utils = {
url = github:numtide/flake-utils;
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, lean, flake-utils, nixpkgs }:
let
supportedSystems = [
# "aarch64-linux"
# "aarch64-darwin"
"i686-linux"
"x86_64-darwin"
"x86_64-linux"
];
in
flake-utils.lib.eachSystem supportedSystems (system:
let
leanPkgs = lean.packages.${system};
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib // (import ./nix/lib.nix { inherit (nixpkgs) lib; });
inherit (lib) concatStringsSep makeOverridable;
buildCLib = import ./nix/buildCLib.nix { inherit nixpkgs system lib; };
includes = [
"${pkgs.libglvnd.dev}/include"
"${leanPkgs.lean-bin-tools-unwrapped}/include"
];
INCLUDE_PATH = concatStringsSep ":" includes;
hasPrefix =
# Prefix to check for
prefix:
# Input string
content:
let
lenPrefix = builtins.stringLength prefix;
in
prefix == builtins.substring 0 lenPrefix content;
libOpenGL = pkgs.libglvnd.out // {
name = "lib/libSDL2.so";
linkName = "OpenGL";
libName = "lib/libOpenGL.so";
# __toString = d: "${pkgs.SDL2.out}/lib";
};
sharedLibDeps = [ libOpenGL ];
linkName = "lean-opengl-bindings";
c-shim = buildCLib {
updateCCOptions = d: d ++ (map (i: "-I${i}") includes);
name = linkName;
sourceFiles = [ "bindings/*.c" ];
src = builtins.filterSource
(path: type: hasPrefix (toString ./. + "/bindings") path) ./.;
extraDrvArgs = {
inherit linkName;
};
};
c-shim-debug = c-shim.override {
debug = true;
updateCCOptions = d: d ++ (map (i: "-I${i}") includes) ++ [ "-O0" ];
};
name = "OpenGL"; # must match the name of the top-level .lean file
project = makeOverridable leanPkgs.buildLeanPackage
{
inherit name;
linkFlags = [ "-L${pkgs.libglvnd.out}/lib" "-lOpenGL" "-lGL" "-lGLESv2" ];
# Where the lean files are located
nativeSharedLibs = sharedLibDeps ++ [ c-shim ];
src = ./src;
};
test = makeOverridable leanPkgs.buildLeanPackage
{
name = "Tests";
deps = [ project ];
# Where the lean files are located
src = ./test;
};
joinDepsDerivationns = getSubDrv:
pkgs.lib.concatStringsSep ":" (map (d: "${getSubDrv d}") ([ ] ++ project.allExternalDeps));
withGdb = bin: pkgs.writeShellScriptBin "${bin.name}-with-gdb" "${pkgs.gdb}/bin/gdb ${bin}/bin/${bin.name}";
in
{
inherit project test;
packages = {
${name} = project.sharedLib;
test = test.executable;
debug-test = (test.overrideArgs {
debug = true;
deps =
[ (project.override {
nativeSharedLibs = sharedLibDeps ++ [ c-shim-debug ];
})
];
}).executable // { allowSubstitutes = false; };
gdb-test = withGdb self.packages.${system}.debug-test;
};
checks.test = test.executable;
defaultPackage = self.packages.${system}.${name};
devShell = pkgs.mkShell {
inputsFrom = [ project ];
buildInputs = with pkgs; [
leanPkgs.lean
];
LEAN_PATH = joinDepsDerivationns (d: d.modRoot);
LEAN_SRC_PATH = joinDepsDerivationns (d: d.src);
C_INCLUDE_PATH = INCLUDE_PATH;
CPLUS_INCLUDE_PATH = INCLUDE_PATH;
};
});
}