-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelements.nix
132 lines (121 loc) · 5.41 KB
/
elements.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
124
125
126
127
128
129
130
131
132
args@
{ stdenv, fetchFromGitHub ? null, fetchpatch, pkg-config, autoreconfHook, db48, boost, zeromq
, zlib, miniupnpc, qtbase ? null, qttools ? null, util-linux ? null, hexdump ? null, protobuf, python3, qrencode, libevent
, lcov ? null
, lib, writeText
, withSource ? null
, withBench ? false
, withWallet ? true
, withCoverage ? false
, withDebug ? false
, sanitizers ? []
, withFuzz ? lib.elem "fuzzer" sanitizers
, doCheck ? (doFunctionalTests || withCoverage)
, withTests ? doCheck
, doFunctionalTests ? true
, qaAssetsDir ? null
, unitTestDataDir ? if qaAssetsDir != null then "${qaAssetsDir}/unit_test_data" else null
, fuzzSeedCorpusDir ? if qaAssetsDir != null then "${qaAssetsDir}/fuzz_seed_corpus" else null
, withGCC13Patches ? false
}:
assert withFuzz -> stdenv.cc.isClang;
assert withCoverage -> stdenv.cc.isClang;
assert doCheck -> withTests;
with lib;
let withAssets = doCheck && (withCoverage || doFunctionalTests); in
stdenv.mkDerivation rec {
pname = "elements";
version = if withSource == null then "23.2.4" else "custom";
src = if withSource != null then withSource else
fetchFromGitHub {
owner = "ElementsProject";
repo = "elements";
rev = "elements-${version}";
sha256 = "sha256-UNjYkEZBjGuhkwBxSkNXjBBcLQqoan/afCLhoR2lOY4=";
};
patches = optionals withCoverage [ ./elements-lcov.patch ]
++ optionals withGCC13Patches [
(fetchpatch {
name = "Add-missing-includes-to-fix-gcc-13-compile-error.patch";
url = "https://github.com/bitcoin/bitcoin/commit/398768769f85cc1b6ff212ed931646b59fa1acd6.patch";
hash = "sha256-4nnE4W0Z5HzVaJ6tB8QmyohXmt6UHUGgDH+s9bQaxhg=";
})
(fetchpatch {
name = "23-x-Add-missing-includes-to-fix-gcc-13-compile-error.patch";
url = "https://github.com/bitcoin/bitcoin/commit/af862661654966d5de614755ab9bd1b5913e0959.patch";
hash = "sha256-4hcJIje3VAdEEpn2tetgvgZ8nVft+A64bfWLspQtbVw=";
})
];
postPatch = optionals (doCheck)
''
patchShebangs contrib/filter-lcov.py
patchShebangs test/functional
patchShebangs test/fuzz
substituteInPlace test/sanitizer_suppressions/ubsan --replace "*/include/" "include/"
'';
nativeBuildInputs = [ pkg-config autoreconfHook ]
++ optionals stdenv.isLinux [ util-linux ]
++ optionals stdenv.isDarwin [ hexdump ]
++ optionals withCoverage [ lcov stdenv.cc.cc.libllvm python3 ];
buildInputs = [ db48 boost zlib zeromq
miniupnpc protobuf libevent];
nativeCheckInputs = [ python3 ];
configureFlags = [ "--with-boost-libdir=${boost.out}/lib"
"--with-boost=${boost.dev}"
] ++ optionals (withCoverage) [
"--enable-lcov --enable-lcov-branch-coverage"
] ++ optionals (withDebug) [
"--enable-debug"
] ++ optionals (withFuzz) [
"--enable-fuzz"
] ++ optionals ([] != sanitizers) [
"--with-sanitizers=${concatStringsSep "," sanitizers}"
] ++ optionals (!withBench) [
"--disable-bench"
] ++ optionals (!withWallet) [
"--disable-wallet"
] ++ optionals (!withTests && !withFuzz) [
"--disable-tests"
"--disable-gui-tests"
];
inherit doCheck;
${ if doCheck then "DIR_UNIT_TEST_DATA" else null} = unitTestDataDir;
${ if doCheck then "DIR_FUZZ_SEED_CORPUS" else null} = fuzzSeedCorpusDir;
checkFlags = [ "LC_ALL=C.UTF-8" ];
testRunnerFlags = [ ]; # ++ optionals enableParallelBuilding [ "-j=$NIX_BUILD_CORES" ];
checkTarget = if withCoverage then (if withFuzz then "cov_fuzz" else "cov") else "check";
preCheck = optionals (withCoverage) ''
# clang seems to have some sort of bug in '--coverage' which generates .gcno files that incorrectly think boost header files in elements/src/include/boost.
# This causes a bunch of warnings during the build and will caue genhtml to fail.
# This workaround is to ignore errors in genhtml.
# Though it is probably better to update the filter used in the build process to exclude these incorrect boost files and other non-src files.
checkFlagsArray+=(GENHTML="${lcov}/bin/genhtml --ignore-errors source")
'';
postCheck = if (!withCoverage && doFunctionalTests)
then ''
(cd test/functional && python3 test_runner.py $testRunnerFlags)
''
else "";
makeFlags = [ "VERBOSE=true" ];
postInstall = optionals (withFuzz)
[ ''
cp src/test/fuzz/fuzz $out/bin/fuzz
''] ++ optional (doCheck && withCoverage)
[''
mkdir -p $out/share
cp -r *.coverage $out/share/
''];
enableParallelBuilding = true;
meta = with lib; {
description = "Open Source implementation of advanced blockchain features extending the Bitcoin protocol";
longDescription= ''
The Elements blockchain platform is a collection of feature experiments and extensions to the
Bitcoin protocol. This platform enables anyone to build their own businesses or networks
pegged to Bitcoin as a sidechain or run as a standalone blockchain with arbitrary asset
tokens.
'';
homepage = "https://www.github.com/ElementsProject/elements";
license = licenses.mit;
platforms = platforms.unix;
};
}