-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathic.nix
More file actions
221 lines (210 loc) · 7.41 KB
/
ic.nix
File metadata and controls
221 lines (210 loc) · 7.41 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
{ pkgs, customRustPlatform, sources, moc }:
let
pkgs-with-overlays = pkgs.appendOverlays ([ ]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
(self: super: {
lmdb = self.callPackage ./nix/lmdb { src = sources.lmdb; };
})
]);
in let pkgs = pkgs-with-overlays;
in with pkgs;
let
rustPlatform = customRustPlatform;
bins = {
"replica" = "rs/replica/";
"ic-admin" = "rs/registry/admin/";
"ic-prep" = "rs/prep/";
"ic-replay" = "rs/replay/";
"ic-consensus-pool-util" = "rs/artifact_pool/";
"state-tool" = "rs/state_tool/";
"ic-https-outcalls-adapter" = "rs/https_outcalls/adapter/";
"canister_sandbox" = "rs/canister_sandbox/";
"compiler_sandbox" = "rs/canister_sandbox/";
"sandbox_launcher" = "rs/canister_sandbox/";
"ic-nns-init" = "rs/nns/init/";
"sns" = "rs/sns/";
"pocket-ic-server" = "rs/pocket_ic_server/";
};
wasms = {
"registry-canister" = "rs/registry/canister/";
"ledger-canister" = "rs/ledger_suite/icp/ledger/";
"genesis-token-canister" = "rs/nns/gtc/";
"governance-canister" = "rs/nns/governance/";
"sns-governance-canister" = "rs/sns/governance/";
"root-canister" = "rs/nns/handlers/root/impl/";
"sns-root-canister" = "rs/sns/root/";
"lifeline" = "rs/nns/handlers/lifeline/impl/";
};
stdenv = llvmPackages.libcxxStdenv;
rocksdb =
# (pkgsStatic.rocksdb_6_23.override ({ inherit stdenv; })).overrideAttrs (_: {
((callPackage ./nix/rocksdb.nix { }).override ({
inherit stdenv;
})).overrideAttrs (_: {
cmakeFlags = [
"-DPORTABLE=1"
"-DWITH_JEMALLOC=0"
"-DWITH_JNI=0"
"-DWITH_BENCHMARK_TOOLS=0"
"-DWITH_TESTS=1"
"-DWITH_TOOLS=0"
"-DWITH_BZ2=0"
"-DWITH_LZ4=0"
"-DWITH_SNAPPY=0"
"-DWITH_ZLIB=1"
"-DWITH_ZSTD=0"
"-DWITH_GFLAGS=0"
"-DUSE_RTTI=1"
"-DROCKSDB_BUILD_SHARED=0"
];
CFLAGS =
[ "-Wno-error=deprecated-copy" "-Wno-error=unused-private-field" ];
});
buildIC = { customLinker ? false, binname ? "", subdir ? ""
, hostTriple ? stdenv.hostPlatform.config, profile ? "release"
, isDev ? false }:
let linker = callPackage ./nix/static-linker.nix { inherit stdenv; };
in (rustPlatform.buildRustPackage rec {
inherit profile hostTriple;
name = "ic-" + binname;
src = sources.ic;
unpackPhase = ''
cp -r $src ${name}
echo source root is ${sourceRoot}
chmod -R u+w -- "$sourceRoot"
runHook postUnpack
'';
sourceRoot = "${name}";
nativeBuildInputs =
[ moc cmake llvmPackages.clang pkg-config python3 rustfmt protobuf ]
++ lib.optionals stdenv.hostPlatform.isx86 [ glibc_multi ];
buildInputs = [
libusb1
llvmPackages.libclang.lib
llvmPackages.llvm.lib
rocksdb
lmdb.dev
sqlite
openssl-static
zlib-static
] ++ (if stdenv.isDarwin then
with darwin.apple_sdk.frameworks; [ CoreServices Foundation Security ]
else if isDev then [
libunwind
cryptsetup
] else
[ libunwind-static ]);
doCheck = false;
# The following 2 variables are required by build.rs of ic-admin.
VERSION_TXT_PATH = writeText "version.txt" sources.ic.rev;
# use a dummy date since it's not easy to get the actal date
COMMIT_DATE_ISO_8601_TXT_PATH =
writeText "commit_date_iso_8601.txt" "1970-01-01T00:00:00+00:00";
# pocket-ic now requires and embeds this file at compile time.
MAINNET_ROUTING_TABLE = ./nix/mainnet_routing_table-55267.json;
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
CC = "";
CFLAGS = [ "-fno-stack-protector" ] ++ lib.optionals (!stdenv.isDarwin)
[ "-I${libunwind-static.dev}/include" ]
++ lib.optionals isDev [ "-Wno-int-conversion" ];
# Somehow clang includes gcc's libc++, we use -nostdinc++ to prevent it.
CXXFLAGS = lib.optionals customLinker [
"-nostdinc++"
"-I${libcxx.dev}/include/c++/v1"
];
RUSTFLAGS = lib.optionals customLinker [ "-Clinker=${linker}" ] ++ [
"-Lnative=${libcxx}/lib"
"-Lnative=${zlib-static}/lib"
"-Lnative=${lmdb.out}/lib"
"-lstatic=lmdb"
"-lstatic=z"
] ++ (if stdenv.isDarwin then [
"-Lall=${libiconv-static.out}/lib"
"-lstatic=iconv"
] else
lib.optionals (!isDev) [
"-Lnative=${lzma-static.out}/lib"
"-lstatic=lzma"
]);
RUST_SRC_PATH = "${rust-stable}/lib/rustlib/src/rust/library";
buildPhase = ''
pushd "${subdir}" && cargo build --frozen --profile ${profile} -j $NIX_BUILD_CORES --target ${hostTriple} --bin ${binname} && popd
'';
installPhase = ''
install -m 755 -D target/${hostTriple}/${profile}/${binname} $out/bin/${binname}
'';
# Placeholder, to allow a custom importCargoLock below
cargoSha256 = lib.fakeHash;
}).overrideAttrs (_: {
cargoDeps = rustPlatform.importCargoLock {
lockFile = "${sources.ic}/Cargo.lock";
allowBuiltinFetchGit = true;
outputHashes = {
"icrc1-test-env-0.1.1" =
"sha256-2PB7e64Owin/Eji3k8UoeWs+pfDfOOTaAyXjvjOZ/4g=";
"lmdb-rkv-0.14.99" =
"sha256-6yRjugQ1mshOgX6RFVjEyuli2wOhLvLkzm580lsTI3w=";
"build-info-0.0.27" =
"sha256-SkwWwDNrTsntkNiCv6rsyTFGazhpRDnKtVzPpYLKF9U=";
};
};
# not available for wasm32 targets
hardeningDisable = [ "zerocallusedregs" ];
});
mkBinaries = targets:
let
deps = lib.attrsets.mapAttrs (binname: subdir:
buildIC {
inherit binname subdir;
customLinker = true;
}) targets;
in stdenv.mkDerivation (rec {
name = "ic-binaries";
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/bin
'' + lib.attrsets.foldlAttrs (acc: _: deriv:
''
install -m 755 ${deriv}/bin/* $out/bin/
'' + acc) "" deps;
});
binaries = mkBinaries bins;
wasm-binaries = mkBinaries wasms;
canisters = let
profile = "canister-release";
hostTriple = "wasm32-unknown-unknown";
deps = lib.attrsets.mapAttrs (binname: subdir:
(buildIC { inherit binname subdir hostTriple profile; }).overrideAttrs
(self: {
installPhase = ''
mkdir -p $out/bin/
${binaryen}/bin/wasm-opt -O2 -o $out/bin/${binname}.wasm \
target/${hostTriple}/${profile}/${binname}.wasm
'';
})) wasms;
in stdenv.mkDerivation (rec {
name = "ic-canisters";
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/share/ic-canisters/
'' + lib.attrsets.foldlAttrs (acc: binname: deriv:
''
install -m 755 ${deriv}/bin/* $out/share/ic-canisters/
if [ "${binname}" = "ledger-canister" ]; then
cp ${sources.ic}/rs/ledger_suite/icp/ledger/*.did $out/share/ic-canisters/
elif [ "${binname}" = "lifeline" ]; then
true
elif [ "${binname}" = "root-canister" ]; then
true
else
${wasm-binaries}/bin/${binname} > $out/share/ic-canisters/${binname}.did
fi
'' + acc) "" deps;
});
in {
inherit binaries wasm-binaries canisters;
shell = buildIC { isDev = true; };
pocket-ic = mkBinaries { "pocket-ic-server" = "rs/pocket_ic_server/"; };
}