-
-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathflake.nix
More file actions
221 lines (199 loc) · 7.06 KB
/
Copy pathflake.nix
File metadata and controls
221 lines (199 loc) · 7.06 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
{
description = "Dev environment for jank";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
self.submodules = true;
};
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = {
self',
pkgs,
lib,
...
}: let
llvmPackages = pkgs.llvmPackages_git;
# for cpptrace; versions from cpptrace/cmake/OptionVariables.cmake
libdwarf-lite-src = pkgs.fetchFromGitHub {
owner = "jeremy-rifkin";
repo = "libdwarf-lite";
rev = "d06f37ed6660b324e458387d43efde3d84c9dd55";
sha256 = "sha256-vPSHVrzsLRa29qnXWfkI3EJQeMTSpXHN9I129JjJxtE=";
};
zstd-src = pkgs.fetchFromGitHub {
owner = "facebook";
repo = "zstd";
rev = "v1.5.7";
sha256 = "sha256-tNFWIT9ydfozB8dWcmTMuZLCQmQudTFJIkSr0aG7S44=";
};
# Manually set compilation and linker flags, rather than depending on
# them to be implicitly set in the clang wrapper scripts. This is so
# that the jank build process can pick up the flags such that they can
# be passed along to downstream jank AOT compilation commands.
cmakeCxxFlags = lib.concatStringsSep " " [
(lib.trim (lib.readFile "${llvmPackages.clang}/nix-support/cc-cflags"))
(lib.trim (lib.readFile "${llvmPackages.clang}/nix-support/libc-crt1-cflags"))
];
cmakeLinkerFlags = lib.concatStringsSep " " [
(lib.trim (lib.readFile "${llvmPackages.clang}/nix-support/cc-ldflags"))
"-Wl,-rpath,${llvmPackages.stdenv.cc.libc}/lib"
"-L${lib.getLib llvmPackages.libllvm.lib}/lib"
"-L${lib.getLib pkgs.bzip2}/lib"
"-L${lib.getLib pkgs.openssl}/lib"
"-L${lib.getLib pkgs.zlib}/lib"
"-L${lib.getLib pkgs.zstd}/lib"
"-L${lib.getLib pkgs.libedit}/lib"
"-L${lib.getLib pkgs.libxml2}/lib"
];
in {
legacyPackages = pkgs;
formatter = pkgs.alejandra;
packages = rec {
default = jank-release;
jank-release = llvmPackages.stdenv.mkDerivation (finalAttrs: {
pname = "jank";
version = "git";
# Add only essential files so that the source hash is consistent.
src = lib.cleanSource (lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./.clang-format
./gdb
./compiler+runtime
];
});
nativeBuildInputs =
[
llvmPackages.clang
llvmPackages.libclang.dev
]
++ (with pkgs; [
cmake
git
ninja
]);
buildInputs =
[
llvmPackages.libllvm.dev
]
++ (with pkgs; [
bzip2
openssl
zstd
libedit
libxml2
boost
]);
checkInputs = with pkgs; [
glibcLocales
];
postPatch = ''
patchShebangs ./compiler+runtime/bin/ar-merge
'';
preConfigure = ''
cmakeFlagsArray+=(
"-DCMAKE_CXX_FLAGS=${lib.escapeShellArg cmakeCxxFlags}"
"-DCMAKE_EXE_LINKER_FLAGS=${lib.escapeShellArg cmakeLinkerFlags}"
"-DCMAKE_SHARED_LINKER_FLAGS=${lib.escapeShellArg cmakeLinkerFlags}"
"-DCMAKE_MODULE_LINKER_FLAGS=${lib.escapeShellArg cmakeLinkerFlags}"
)
'';
# Disable _FORTIFY_SOURCE to prevent linker errors for substituted
# memcpy/strcpy/etc. symbols.
#
# See: https://github.com/jank-lang/jank/pull/735#issuecomment-4316754811
#
# TODO: Figure out how to solve the linker issues without disabling
# fortification.
hardeningDisable = ["fortify"];
cmakeBuildDir = "./compiler+runtime/build";
cmakeDir = "..";
cmakeFlags = [
# TODO: Updating RPATHs during install causes the step to fail as it
# tries to rewrite non-existent RPATHs like /lib. Needs more
# investigation.
"-DCMAKE_SKIP_RPATH=ON"
# Manually provide any FetchContent sources as network requests are
# not allowed in the nix build sandbox.
"-DFETCHCONTENT_SOURCE_DIR_LIBDWARF=${libdwarf-lite-src}"
"-DFETCHCONTENT_SOURCE_DIR_ZSTD=${zstd-src}"
# jank options
(lib.cmakeBool "jank_unity_build" true)
(lib.cmakeBool "jank_test" finalAttrs.doCheck)
# We run out of memory in CI without this.
(lib.cmakeBool "jank_force_phase_2" true)
];
# Use a UTF-8 locale or else tests which use UTF-8 characters will
# fail. See: https://github.com/NixOS/nixpkgs/issues/172752
LC_ALL = "C.UTF-8";
doCheck = true;
checkPhase = ''
pushd ../
./build/jank-test
popd
'';
});
};
devShells.default = (pkgs.mkShell.override {stdenv = llvmPackages.stdenv;}) {
packages = with pkgs; [
## Required tools.
cmake
ninja
pkg-config
llvmPackages.clang
llvmPackages.libclang
llvmPackages.libllvm
bubblewrap
## Required libs.
boehmgc
openssl
boost
## Dev tools.
babashka
entr
gcovr
lcov
git
nixd
shellcheck
# For clangd & clang-tidy.
clang-tools
gdb
clangbuildanalyzer
openjdk
leiningen
expect
nodejs
# Examples.
pkg-config
glfw3
libGL
sqlite
gnumake
alsa-lib
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXinerama
xorg.libXrandr
xorg.xorgproto
## Book.
mdbook
mdbook-mermaid
];
shellHook = ''
export CXXFLAGS=${lib.escapeShellArg cmakeCxxFlags}
export LDFLAGS=${lib.escapeShellArg cmakeLinkerFlags}
export ASAN_OPTIONS=detect_leaks=0
'';
# Nix assumes fortification by default, but that fails with debug builds.
# Since this shell is used for development, we disabled fortification. It's
# still enabled for our release builds in build.nix.
# https://github.com/NixOS/nixpkgs/issues/18995
hardeningDisable = ["fortify"];
};
};
};
}