forked from holochain/holochain-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
206 lines (167 loc) · 7.53 KB
/
Makefile
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
# holochain-rust Makefile
# currently only supports 'debug' builds
# run `make` to build all the libraries and binaries
# run `make test` to execute all the tests
# run `make clean` to clean up the build environment
# run `make test_holochain` to test holochain builds
# run `make test_cmd` to test the command line tool builds
all: lint build_holochain build_cmd
CORE_RUST_VERSION ?= nightly-2018-11-28
TOOLS_RUST_VERSION ?= nightly-2018-11-28
CARGO = RUSTFLAGS="-Z external-macro-backtrace -D warnings" RUST_BACKTRACE=1 rustup run $(CORE_RUST_VERSION) cargo $(CARGO_ARGS)
CARGO_TOOLS = RUSTFLAGS="-Z external-macro-backtrace -D warnings" RUST_BACKTRACE=1 rustup run $(TOOLS_RUST_VERSION) cargo $(CARGO_ARGS)
CARGO_TARPULIN_INSTALL = RUSTFLAGS="--cfg procmacro2_semver_exempt -D warnings" RUST_BACKTRACE=1 cargo $(CARGO_ARGS) +$(CORE_RUST_VERSION)
# list all the "C" binding tests that have been written
C_BINDING_DIRS = $(sort $(dir $(wildcard c_binding_tests/*/)))
# list all the "C" binding test executables that should be produced
C_BINDING_TESTS = $(foreach dir,$(C_BINDING_DIRS),target/debug/c_binding_tests/$(shell basename $(dir))/test_executable)
# list all the extraneous files that will be generated when running tests
C_BINDING_CLEAN = $(foreach dir,$(C_BINDING_DIRS),$(dir)Makefile $(dir).qmake.stash)
# build artifact / dependency checking is handled by our sub-tools
# we can just try to build everything every time, it should be efficient
.PHONY: lint \
c_binding_tests ${C_BINDING_DIRS} \
test ${C_BINDING_TESTS} \
test_holochain \
clean ${C_BINDING_CLEAN}
# apply formatting / style guidelines
lint: fmt_check clippy
# idempotent install rustup with the default toolchain set for tooling
# best for CI based on tools only
.PHONY: install_rustup
install_rustup:
if ! which rustup ; then \
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $(CORE_RUST_VERSION) -y; \
fi
export PATH="${HOME}/.cargo/bin:${PATH}"
# idempotent install rustup with the default toolchain set for Holochain core
# best for green fields Rust installation
.PHONY: install_rustup_tools
install_rustup_tools:
if ! which rustup ; then \
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $(TOOLS_RUST_VERSION) -y; \
fi
export PATH="${HOME}/.cargo/bin:${PATH}"
# idempotent installation of libzmq system library
# note, this is complicated by our use of travis-ci ubuntu trusty
# we need to install a newer version than is otherwise available
.PHONY: install_system_libzmq
install_system_libzmq:
if ! (pkg-config libzmq --libs) ; then \
if ! which apt-get ; then \
if which brew ; then \
echo "\033[0;93m## Attempting to install zmq using homebrew ##\033[0m"; \
brew install zmq; \
else \
echo "\033[0;93m## libzmq couldn't be installed, build probably won't work\033[0m"; \
fi; \
else \
if [ "x${TRAVIS}" = "x" ]; then \
echo "\033[0;93m## Attempting to install libzmq3-dev with apt-get ##\033[0m"; \
sudo apt-get install -y libzmq3-dev; \
else \
echo "\033[0;93m## Attempting to install libzmq3-dev on UBUNTU TRUSTY ##\033[0m"; \
echo "deb http://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/xUbuntu_14.04/ ./" >> /etc/apt/sources.list; \
wget https://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/xUbuntu_14.04/Release.key -O- | sudo apt-key add; \
sudo apt-get update -qq; \
sudo apt-get install libzmq3-dev; \
fi; \
fi; \
fi; \
# idempotent install of any required system libraries
.PHONY: install_system_libs
install_system_libs: install_system_libzmq
# idempotent installation of core toolchain
.PHONY: core_toolchain
core_toolchain: install_rustup install_system_libs
rustup toolchain install ${CORE_RUST_VERSION}
# idempotent installation of tools toolchain
.PHONY: tools_toolchain
tools_toolchain: install_rustup_tools install_system_libs
rustup toolchain install ${TOOLS_RUST_VERSION}
# idempotent addition of wasm target
.PHONY: ensure_wasm_target
ensure_wasm_target: core_toolchain
rustup target add wasm32-unknown-unknown --toolchain ${CORE_RUST_VERSION}
# idempotent installation of development tooling
.PHONY: install_rust_tools
install_rust_tools: tools_toolchain
# rust format
if ! rustup component list --toolchain $(TOOLS_RUST_VERSION) | grep 'rustfmt-preview.*(installed)'; then \
rustup component add --toolchain $(TOOLS_RUST_VERSION) rustfmt-preview; \
fi
# clippy
if ! rustup component list --toolchain $(TOOLS_RUST_VERSION) | grep 'clippy-preview.*(installed)'; then \
rustup component add --toolchain $(TOOLS_RUST_VERSION) clippy-preview; \
fi
# idempotent installation of code coverage CI/testing tools
.PHONY: install_ci
install_ci: core_toolchain
# tarpaulin (code coverage)
if ! $(CARGO) install --list | grep 'cargo-tarpaulin'; then \
$(CARGO_TARPULIN_INSTALL) install cargo-tarpaulin --force; \
fi
.PHONY: install_mdbook
install_mdbook: tools_toolchain
if ! $(CARGO_TOOLS) install --list | grep 'mdbook'; then \
$(CARGO_TOOLS) install mdbook --vers "^0.2.2"; \
fi
# list all our found "C" binding tests
c_binding_tests: ${C_BINDING_DIRS}
# build all our found "C" binding tests
${C_BINDING_DIRS}:
qmake -o $@Makefile $@qmake.pro
cd $@; $(MAKE)
# execute all tests: holochain, command-line tools, app spec, nodejs container, and "C" bindings
test: test_holochain test_cmd test_app_spec c_binding_tests ${C_BINDING_TESTS}
test_holochain: build_holochain
RUSTFLAGS="-D warnings" $(CARGO) test --all --exclude hc
test_cmd: build_cmd
cd cmd && RUSTFLAGS="-D warnings" $(CARGO) test
test_app_spec: ensure_wasm_target install_cmd build_nodejs_container
rustup default ${CORE_RUST_VERSION}
cd app_spec && ./build_and_test.sh
build_nodejs_container: core_toolchain
rustup default ${CORE_RUST_VERSION}
./scripts/build_nodejs_container.sh
c_build: core_toolchain
cd dna_c_binding && $(CARGO) build
test_c_ci: c_build c_binding_tests ${C_BINDING_TESTS}
.PHONY: wasm_build
wasm_build: ensure_wasm_target
cd core/src/nucleus/actions/wasm-test && $(CARGO) build --release --target wasm32-unknown-unknown
cd container_api/wasm-test && $(CARGO) build --release --target wasm32-unknown-unknown
cd container_api/test-bridge-caller && $(CARGO) build --release --target wasm32-unknown-unknown
cd hdk-rust/wasm-test && $(CARGO) build --release --target wasm32-unknown-unknown
cd wasm_utils/wasm-test/integration-test && $(CARGO) build --release --target wasm32-unknown-unknown
.PHONY: build_holochain
build_holochain: core_toolchain wasm_build
$(CARGO) build --all --exclude hc
.PHONY: build_cmd
build_cmd: core_toolchain ensure_wasm_target
$(CARGO) build -p hc
.PHONY: install_cmd
install_cmd: build_cmd
cd cmd && $(CARGO) install -f --path .
.PHONY: code_coverage
code_coverage: core_toolchain wasm_build install_ci
$(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
.PHONY: code_coverage_crate
code_coverage_crate: core_toolchain wasm_build install_ci
$(CARGO) tarpaulin --ignore-tests --timeout 600 --skip-clean -v -p $(CRATE)
fmt_check: install_rust_tools
$(CARGO_TOOLS) fmt -- --check
clippy: install_rust_tools
$(CARGO_TOOLS) clippy -- -A needless_return --A useless_attribute
fmt: install_rust_tools
$(CARGO_TOOLS) fmt
# execute all the found "C" binding tests
${C_BINDING_TESTS}:
$@
# clean up the target directory and all extraneous "C" binding test files
clean: ${C_BINDING_CLEAN}
-@$(RM) -rf target
-@$(RM) -rf wasm_utils/wasm-test/integration-test/target
# clean up the extraneous "C" binding test files
${C_BINDING_CLEAN}:
-@$(RM) $@