forked from holochain/holochain-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
158 lines (129 loc) · 4.85 KB
/
shell.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
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
let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
nixpkgs = import <nixpkgs> {
overlays = [ moz_overlay ];
};
date = "2019-01-24";
wasmTarget = "wasm32-unknown-unknown";
rust-build = (nixpkgs.rustChannelOfTargets "nightly" date [ wasmTarget ]);
nodejs-8_13 = nixpkgs.nodejs-8_x.overrideAttrs(oldAttrs: rec {
name = "nodejs-${version}";
version = "8.13.0";
src = nixpkgs.fetchurl {
url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz";
sha256 = "1qidcj4smxsz3pmamg3czgk6hlbw71yw537h2jfk7iinlds99a9a";
};
});
hc-flush-cargo-registry = nixpkgs.writeShellScriptBin "hc-flush-cargo-registry"
''
rm -rf ~/.cargo/registry;
rm -rf ~/.cargo/git;
'';
hc-install-node-conductor = nixpkgs.writeShellScriptBin "hc-install-node-conductor"
''
. ./scripts/build_nodejs_conductor.sh;
'';
hc-install-tarpaulin = nixpkgs.writeShellScriptBin "hc-install-tarpaulin"
''
if ! cargo --list | grep --quiet tarpaulin;
then
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin;
fi;
'';
hc-tarpaulin = nixpkgs.writeShellScriptBin "hc-tarpaulin" "cargo tarpaulin --ignore-tests --timeout 600 --all --out Xml --skip-clean -v -e holochain_core_api_c_binding -e hdk -e hc -e holochain_core_types_derive";
hc-install-cli = nixpkgs.writeShellScriptBin "hc-install-cli" "cargo build -p hc --release && cargo install -f --path cli";
hc-install-conductor = nixpkgs.writeShellScriptBin "hc-install-conductor" "cargo build -p holochain --release && cargo install -f --path conductor";
hc-test-cli = nixpkgs.writeShellScriptBin "hc-test-cli" "cd cli && cargo test";
hc-test-app-spec = nixpkgs.writeShellScriptBin "hc-test-app-spec" "cd app_spec && . build_and_test.sh";
hc-test-node-conductor = nixpkgs.writeShellScriptBin "hc-test-node-conductor" "cd nodejs_conductor && npm test";
hc-fmt = nixpkgs.writeShellScriptBin "hc-fmt" "cargo fmt";
hc-fmt-check = nixpkgs.writeShellScriptBin "hc-fmt-check" "cargo fmt -- --check";
# runs all standard tests and reports code coverage
hc-codecov = nixpkgs.writeShellScriptBin "hc-codecov"
''
hc-install-tarpaulin && \
hc-tarpaulin && \
bash <(curl -s https://codecov.io/bash);
'';
# simulates all supported ci tests in a local circle ci environment
ci = nixpkgs.writeShellScriptBin "ci"
''
circleci-cli local execute
'';
build-wasm = wasm-path:
''
export WASM_PATH=${wasm-path}/
cargo build --release --target wasm32-unknown-unknown --manifest-path "$WASM_PATH"Cargo.toml --target-dir "$HC_TARGET_PREFIX""$WASM_PATH"target;
'';
wasm-paths = [
"hdk-rust/wasm-test"
"wasm_utils/wasm-test/integration-test"
"conductor_api/wasm-test"
"conductor_api/test-bridge-caller"
"core/src/nucleus/actions/wasm-test"
];
hc-build-wasm = nixpkgs.writeShellScriptBin "hc-build-wasm"
''
${nixpkgs.lib.concatMapStrings (path: build-wasm path) wasm-paths}
'';
hc-test = nixpkgs.writeShellScriptBin "hc-test"
''
hc-build-wasm
HC_SIMPLE_LOGGER_MUTE=1 cargo test --all --release --target-dir "$HC_TARGET_PREFIX"target;
'';
in
with nixpkgs;
stdenv.mkDerivation rec {
name = "holochain-rust-environment";
buildInputs = [
# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md
binutils gcc gnumake openssl pkgconfig coreutils
cmake
python
pkgconfig
rust-build
nodejs-8_13
yarn
hc-flush-cargo-registry
hc-build-wasm
hc-test
hc-install-tarpaulin
hc-tarpaulin
hc-install-cli
hc-install-conductor
hc-install-node-conductor
hc-test-cli
hc-test-app-spec
hc-test-node-conductor
hc-fmt
hc-fmt-check
zeromq4
# dev tooling
git
# curl needed to push to codecov
curl
circleci-cli
hc-codecov
ci
];
# https://github.com/rust-unofficial/patterns/blob/master/anti_patterns/deny-warnings.md
# https://llogiq.github.io/2017/06/01/perf-pitfalls.html
RUSTFLAGS = "-D warnings -Z external-macro-backtrace -Z thinlto -C codegen-units=16 -C opt-level=z";
CARGO_INCREMENTAL = "1";
# https://github.com/rust-lang/cargo/issues/4961#issuecomment-359189913
# RUST_LOG = "info";
# non-nixos OS can have a "dirty" setup with rustup installed for the current
# user.
# `nix-shell` can inherit this e.g. through sourcing `.bashrc`.
# even `nix-shell --pure` will still source some files and inherit paths.
# for those users we can at least give the OS a clue that we want our pinned
# rust version through this environment variable.
# https://github.com/rust-lang/rustup.rs#environment-variables
# https://github.com/NixOS/nix/issues/903
RUSTUP_TOOLCHAIN = "nightly-${date}";
shellHook = ''
# needed for install cli and tarpaulin
export PATH=$PATH:~/.cargo/bin;
export HC_TARGET_PREFIX=~/nix-holochain/
'';
}