Repository navigation
Expand file tree
/
Copy pathaipstack_example.nix
More file actions
79 lines (66 loc) · 2.71 KB
/
Copy pathaipstack_example.nix
File metadata and controls
79 lines (66 loc) · 2.71 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
{ stdenv, lib, enableAssertions, enableSanitizers, customFlags }:
let
aipstackSrc = lib.cleanSource ../.;
stdFlags = [ "-std=c++17" ];
defines = lib.optional enableAssertions "-DAIPSTACK_CONFIG_ENABLE_ASSERTIONS";
sanitizeFlags = lib.optional enableSanitizers "-fsanitize=address,undefined";
baseWarnings = [ "-Wall" "-Wextra" "-Wpedantic" ];
optionalWarnings = [
"-Wshadow" "-Wswitch-default" "-Wreorder" "-Wredundant-decls"
"-Woverloaded-virtual" "-Wmissing-declarations" "-Wformat=2"
"-Wdelete-non-virtual-dtor" "-Wformat-signedness" "-Wlogical-op"
"-Wold-style-cast" "-Wundef" "-Wextra-semi" "-Wreserved-id-macro"
"-Wcast-align" "-Wno-tautological-constant-out-of-range-compare"
];
optionalWarningsClang = [ "-Wconversion" "-Wnon-virtual-dtor" ];
filterSupportedWarnings =
{ warnings, compilerMatch ? "" }:
stdenv.mkDerivation rec {
name = "aipstack_supported_warnings.txt";
buildCommand = ''
(
${if compilerMatch == "" then "" else ''
if ! c++ --version | head -n 1 | grep -i "${compilerMatch}" >/dev/null; then
return
fi
''}
touch test.cpp
${lib.concatMapStrings (warning: ''
if c++ ${concatFlags stdFlags} -Werror "${warning}" -c test.cpp \
>/dev/null 2>&1; then
echo -n "${warning} "
fi
'') warnings}
) >"$out"
'';
};
supportedOptionalWarnings = filterSupportedWarnings {
warnings = optionalWarnings;
};
supportedOptionalWarningsClang = filterSupportedWarnings {
warnings = optionalWarningsClang;
compilerMatch = "clang";
};
concatFlags = flags: lib.concatStringsSep " " flags;
in stdenv.mkDerivation {
name = "aipstack_example";
buildCommand = ''
mkdir -p $out/bin
cd ${aipstackSrc}
(
set -x
c++ \
examples/aipstack_example.cpp \
src/aipstack/event_loop/EventLoopAmalgamation.cpp \
src/aipstack/tap/TapDeviceAmalgamation.cpp \
-o $out/bin/aipstack_example \
-I src -pthread \
${concatFlags stdFlags} ${concatFlags sanitizeFlags} \
${concatFlags baseWarnings} \
$(cat ${supportedOptionalWarnings}) \
$(cat ${supportedOptionalWarningsClang}) \
${concatFlags defines} ${concatFlags customFlags}
)
'';
dontStrip = true;
}