-
Notifications
You must be signed in to change notification settings - Fork 387
Expand file tree
/
Copy pathdevelop.nix
More file actions
102 lines (84 loc) · 2.79 KB
/
develop.nix
File metadata and controls
102 lines (84 loc) · 2.79 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
# develop.nix
# sets up a development shell in which you can open your editor
{
buildpath ? "build",
# path to your unikernel source (project root with CMakeLists.txt)
unikernel ? ".",
# optional: path to a local vmrunner checkout (otherwise use includeos.vmrunner)
vmrunner ? "",
# Enable ccache support. See overlay.nix for details.
withCcache ? true,
# Enable multicore suport.
smp ? false,
includeos ? import ./default.nix { inherit withCcache smp; },
arch ? "x86_64"
}:
# override stdenv for furhter derivations so they're in sync with includeos patch requirements
includeos.pkgs.mkShell.override { inherit (includeos) stdenv; } rec {
vmrunnerPkg =
if vmrunner == "" then
includeos.vmrunner
else
includeos.pkgs.callPackage (builtins.toPath /. + vmrunner) {};
# handy tools available in the shell
packages = [
(includeos.pkgs.python3.withPackages (p: [
vmrunnerPkg
]))
includeos.pkgs.buildPackages.cmake
includeos.pkgs.buildPackages.nasm
includeos.pkgs.qemu
includeos.pkgs.which
includeos.pkgs.grub2
includeos.pkgs.iputils
includeos.pkgs.xorriso
includeos.pkgs.jq
];
# libraries/headers we include against
buildInputs = [
includeos
includeos.chainloader
includeos.lest
includeos.pkgs.openssl
includeos.pkgs.rapidjson
];
shellHook = ''
IOS_SRC=${toString ./.}
if [ ! -d "$IOS_SRC" ]; then
echo "$unikernel is not a valid directory" >&2
return 1
fi
echo "Configuring in: ${buildpath}"
echo "Source tree: $IOS_SRC"
# delete old just in case it's dirty
rm -rf ${buildpath}
mkdir -p ${buildpath}
# build includeOS
cmake -S "$IOS_SRC" -B ${buildpath} \
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-D ARCH=${arch} \
-D CMAKE_MODULE_PATH=${includeos}/cmake
# procuced by CMake
CCDB="${buildpath}/compile_commands.json"
#
# attempting to use -resource-dir with 'clang++ -print-resource-dir'
# doesn't work here as we're using -nostdlib/-nostdlibinc
#
tmp="$CCDB.clangd.tmp"
jq \
--arg libcxx "${includeos.libraries.libcxx.include}" \
--arg libc "${includeos.libraries.libc}" \
--arg libfmt "${includeos.passthru.libfmt.include}" \
--arg localsrc "${toString ./.}" \
'
map(.command |= ( .
+ " -isystem \($libcxx)"
+ " -isystem \($libc)/include"
+ " -I \($libfmt)"
| gsub("(?<a>-I)(?<b>/lib/LiveUpdate/include)"; .a + $localsrc + .b)
))
' "$CCDB" > "$tmp" && mv "$tmp" "$CCDB"
# most clangd configurations and editors will look in ./build/, but this just makes it easier to find for some niche edge cases
ln -sfn "${buildpath}/compile_commands.json" "$IOS_SRC/compile_commands.json"
'';
}