forked from holochain/holochain-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
152 lines (120 loc) · 4.56 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
let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
nixpkgs = import <nixpkgs> {
overlays = [ moz_overlay ];
};
date = "2018-11-28";
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";
};
});
wasmBuild = path: "CARGO_HOME=${path}/.cargo CARGO_TARGET_DIR=${path}/target cargo build --release --target ${wasmTarget} --manifest-path ${path}/Cargo.toml";
hc-wasm-build = nixpkgs.writeShellScriptBin "hc-wasm-build"
''
${wasmBuild "core/src/nucleus/actions/wasm-test"}
${wasmBuild "container_api/test-bridge-caller"}
${wasmBuild "container_api/wasm-test"}
${wasmBuild "hdk-rust/wasm-test"}
${wasmBuild "wasm_utils/wasm-test/integration-test"}
'';
hc-flush-cargo-registry = nixpkgs.writeShellScriptBin "hc-flush-cargo-registry"
''
rm -rf ~/.cargo/registry;
rm -rf ~/.cargo/git;
'';
hc-build = nixpkgs.writeShellScriptBin "hc-build"
''
cargo build --all --exclude hc
'';
hc-test = nixpkgs.writeShellScriptBin "hc-test"
''
hc-build
cargo test --release --all --exclude hc;
'';
hc-install-node-container = nixpkgs.writeShellScriptBin "hc-install-node-container"
''
. ./scripts/build_nodejs_container.sh;
'';
hc-install-tarpaulin = nixpkgs.writeShellScriptBin "hc-install-tarpaulin" "if ! cargo --list | grep --quiet tarpaulin; then 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-cmd = nixpkgs.writeShellScriptBin "hc-install-cmd" "cargo build -p hc && cargo install -f --path cmd";
hc-test-cmd = nixpkgs.writeShellScriptBin "hc-test-cmd" "cd cmd && cargo test";
hc-test-app-spec = nixpkgs.writeShellScriptBin "hc-test-app-spec" "cd app_spec && . build_and_test.sh";
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-build && \
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
'';
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
# carnix
cmake
python
pkgconfig
rust-build
nodejs-8_13
yarn
hc-flush-cargo-registry
hc-wasm-build
hc-build
hc-test
hc-install-tarpaulin
hc-tarpaulin
hc-install-cmd
hc-install-node-container
hc-test-cmd
hc-test-app-spec
hc-fmt
hc-fmt-check
zeromq4
# dev tooling
git
# curl needed to push to codecov
curl
docker
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 --cfg procmacro2_semver_exempt -C lto=no -Z incremental-info";
RUSTFLAGS = "-D warnings -Z external-macro-backtrace --cfg procmacro2_semver_exempt -Z thinlto -C codegen-units=16";
# 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 cmd and tarpaulin
export PATH=$PATH:~/.cargo/bin;
'';
}