-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
123 lines (110 loc) · 3.59 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
{
description = "Mandelbulbs in Metals in Pure C++23";
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"x86_64-darwin"
];
perSystem =
{
lib,
pkgs,
config,
...
}:
let
llvm = pkgs.llvmPackages_19;
stdenv = llvm.stdenv;
fs = lib.fileset;
in
{
packages.mandelbulb = stdenv.mkDerivation {
pname = "mandelbulb";
version = "0.1.0";
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./include
./src
];
};
outputs = [
"out"
"development"
];
buildInputs = [
pkgs.apple-sdk_15
llvm.libcxx
(pkgs.darwinMinVersionHook "12.0")
];
FLAGS = [
"--start-no-unused-arguments"
"-std=c++23"
"-stdlib=libc++"
"-fstrict-enums"
"-fsanitize=undefined"
"-fsanitize=address"
"-fcoroutines"
"-flto"
"-fno-exceptions"
"-fno-rtti"
"-fno-threadsafe-statics"
"-fno-operator-names"
"-fno-common"
"-fvisibility=hidden"
"-Wall"
"-Wconversion"
];
preBuild = ''
mkdir -p pcms
$CXX -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile \
-o pcms/std.pcm ${llvm.libcxx}/share/libc++/v1/std.cppm $FLAGS
'';
buildPhase = ''
runHook preBuild
$CXX src/main.cc src/AppDelegate.cc src/MTKViewDelegate.cc src/Renderer.cc \
-o mandelbulb -fprebuilt-module-path=pcms -Iinclude -lobjc -framework MetalKit \
-framework AppKit -framework Metal -framework QuartzCore -framework Foundation \
-MJ mandelbulb.o.json $FLAGS
'';
installPhase = ''
install -D -t $out/bin mandelbulb
install -D -t $development/pcms pcms/*
install -D -t $development/fragments *.o.json
'';
meta.mainProgram = "mandelbulb";
};
devShells.default = pkgs.mkShell.override { inherit stdenv; } {
packages = [ (pkgs.ccls.override { llvmPackages = llvm; }) ];
inputsFrom = [ config.packages.mandelbulb ];
};
apps.ccdb = {
type = "app";
program = lib.getExe (
pkgs.writeShellApplication {
name = "ccdb";
runtimeInputs = [ pkgs.gnused ];
text =
let
proj = config.packages.mandelbulb.development;
in
''
sed -e '1s/^/[\n/' -e '$s/,$/\n]/' \
-e "s|/private/tmp/nix-build-${proj.name}.drv-0\(/source\)\?|$(pwd)|g" \
-e "s|prebuilt-module-path=pcms|prebuilt-module-path=${proj}/pcms|g" \
${proj}/fragments/*.o.json \
> compile_commands.json
'';
}
);
};
packages.default = config.packages.mandelbulb;
};
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};
}