-
Notifications
You must be signed in to change notification settings - Fork 83
/
default.nix
105 lines (91 loc) · 2.7 KB
/
default.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
{ release ? true, jni ? true, pushS3 ? false, runTests ? false }:
let
pkgs = import ./nix/pkgs.nix { jdk = "jdk8"; };
pinned = import ./nix/pinned.nix;
inherit (import (pinned.gitignoreSrc { inherit (pkgs) fetchFromGitHub; }) { inherit (pkgs) lib; }) gitignoreSource;
secp256k1-chfast = import ./nix/secp256k1.nix { inherit pkgs; };
buildTypeFlag = if release
then [
"-DCMAKE_BUILD_TYPE=RELEASE"
]
else [
"-DCMAKE_BUILD_TYPE=DEBUG"
];
testFlag = if jni && runTests
then abort "Cannot build both for JNI and run the test suite. Choose only one."
else if runTests
then [ "-DBUILD_TESTS=ON" ]
else [ "-DBUILD_TESTS=OFF" ];
jniFlag = [ (pkgs.lib.optionalString jni "-DTARGET_JNI=ON") ];
cmakeFlags = buildTypeFlag
++ testFlag
++ jniFlag
++ [
"-DNIX_BUILD=ON"
];
in
pkgs.compilationStdenv.mkDerivation {
name = "libledger-core";
version = "4.1.1";
src = gitignoreSource ./.;
nativeBuildInputs = (pkgs.lib.attrVals [
"pkg-config"
"cmake"
"aws"
] pkgs);
buildInputs = (pkgs.lib.attrVals [
# Common build deps
"postgresql_12"
"openssl_1_1"
"sqlite"
"cmake"
"libkrb5"
"cryptopp"
"libuv"
# JNI bindings deps
"jdk8"
] pkgs)
++ [ secp256k1-chfast ]
++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.libselinux ] ;
inherit cmakeFlags;
shellHook = ''
export CMAKE_LIBCORE_FLAGS="${(toString cmakeFlags)}"
'';
doInstallCheck = runTests;
installCheckPhase = ''
echo "========= Provisioning Database"
initdb -D .tmp/mydb
pg_ctl -D .tmp/mydb -l logfile -o "--unix_socket_directories='$PWD'" start
createdb -p 5432 -h localhost test_db
echo "========= Running tests"
ctest --output-on-failure
'';
separateDebugInfo = true;
doDist = pushS3;
tarballs = [
"*.so"
"*.dylib"
];
distPhase = ''
function match {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -nE $*
else
sed -nr $*
fi
}
LIB_VERSION_MAJOR=`cat CMakeLists.txt | match 's/set\(VERSION_MAJOR.*([0-9]+).*\)/\1/p'`
LIB_VERSION_MINOR=`cat CMakeLists.txt | match 's/set\(VERSION_MINOR.*([0-9]+).*\)/\1/p'`
LIB_VERSION_PATCH=`cat CMakeLists.txt | match 's/set\(VERSION_PATCH.*([0-9]+).*\)/\1/p'`
LIB_VERSION=$LIB_VERSION_MAJOR.$LIB_VERSION_MINOR.$LIB_VERSION_PATCH
COMMIT_HASH=`echo $GITHUB_SHA | cut -c 1-6`
LIB_VERSION="$LIB_VERSION-rc-$COMMIT_HASH"
echo "=====> Libcore version : $LIB_VERSION"
echo "======= Pushing to S3 =========="
cd $out/lib
ls -la
aws s3 sync ./ s3://ledger-lib-ledger-core/$LIB_VERSION/ --acl public-read --exclude "*" --include "*.so" --include "*.dylib" && \
aws s3 ls s3://ledger-lib-ledger-core/$LIB_VERSION;
cd -
'';
}