forked from xarantolus/ax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
161 lines (120 loc) · 3.91 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
.PHONY: build build-cjs debug watch test test-local test-node test-js test-scripts clean switch coverage fmt example-programs example copy-programs dependencies web build-web stats fmt python-dependencies ax generate docs watch-programs watch-debug watch-tests precommit clean-programs node-dependencies
MOLD_INSTALLED := $(shell which mold 2> /dev/null)
ifneq ($(MOLD_INSTALLED),)
MOLD := mold -run
endif
EXE_SUFFIX:=
ifeq ($(OS),Windows_NT)
EXE_SUFFIX:=.exe
endif
PY_INSTALLED := $(shell which py 2> /dev/null)
ifeq ($(PY_INSTALLED),)
ifeq ($(shell which python3 2> /dev/null),)
PY := python
else
PY := python3
endif
else
PY := py -3
endif
NPM_INSTALL_COMMAND := npm install
ifneq ($(CI),)
NPM_INSTALL_COMMAND := npm ci
endif
RM_TARGETS := *.out Cargo.lock target
all: ax build build-cjs
######################
### WASM package builds
######################
build:
$(MOLD) wasm-pack build --target web --release
RM_TARGETS += pkg
build-cjs:
$(MOLD) wasm-pack build --target nodejs --release --out-dir pkg-cjs
RM_TARGETS += pkg-cjs
debug:
$(MOLD) wasm-pack build --target web --debug
######################
### Binary builds
######################
bin: ax
ax:
$(MOLD) cargo build --release && cp target/release/ax$(EXE_SUFFIX) .
RM_TARGETS += ax$(EXE_SUFFIX)
######################
### Web builds
######################
build-web: copy-programs build
cd examples/web && $(NPM_INSTALL_COMMAND) && npm run build
RM_TARGETS += examples/web/node_modules examples/web/dist .vite
######################
### Code generation and formatting
######################
# fmt will fail if switch or stats are not up to date, failing precommit
precommit: generate fmt test test-scripts all
# targets that might change files and thus prevent precommit from passing, especially when the version changes
generate: switch stats docs build-web test-js
stats:
@$(PY) stats.py
docs: node-dependencies build
npx typedoc pkg/ax_x86.d.ts --sort alphabetical --cleanOutputDir --categorizeByGroup --disableSources --includeVersion --excludeNotDocumented --out docs
switch:
$(PY) generate.py switch
######################
### Tests & other dev jobs
######################
fmt:
$(MOLD) cargo fix --allow-staged --all --all-features && \
$(MOLD) cargo fmt --all && \
$(MOLD) cargo clippy --all-targets --all-features --fix --allow-staged
test: test-local test-node test-js
test-local:
@echo "Running tests on processor..."
$(MOLD) cargo test
test-wasm: test-node
test-node:
@echo "Running tests in Node/WASM..."
wasm-pack test --node
test-js: build-cjs
@echo "Testing JS API"
cd js/test && $(NPM_INSTALL_COMMAND) && npm test
watch:
$(MAKE) -j3 web watch-debug watch-programs
watch-debug:
$(MOLD) cargo watch -w src -s "$(MAKE) debug"
coverage:
$(MOLD) cargo tarpaulin --out Lcov --skip-clean
watch-tests:
$(MOLD) cargo watch -w src --why --exec 'tarpaulin --out Lcov --skip-clean --target-dir target/tests -- -q' --ignore lcov.info
RM_TARGETS += lcov.info
web: copy-programs build
cd examples/web && $(NPM_INSTALL_COMMAND) && npm run dev -- --host
test-scripts: python-dependencies
$(PY) t.py --test
RM_TARGETS += __pycache__
######################
### Examples
######################
example-programs:
cd examples/programs && $(MAKE) build
copy-programs: example-programs
mkdir -p examples/web/public/programs
cp -r $(shell find examples/programs -name "*.bin") examples/web/public/programs
RM_TARGETS += examples/web/public/programs
clean-programs:
cd examples/programs && $(MAKE) clean
watch-programs:
cd examples/programs && \
cargo watch -w examples/programs -s "$(MAKE) clean-programs copy-programs"
######################
### Utilities
######################
dependencies: python-dependencies node-dependencies
cargo install cargo-tarpaulin cargo-watch python-launcher
python-dependencies:
$(PY) -m pip install pyperclip tqdm
node-dependencies:
npm install -g eslint
clean:
rm -rf $(RM_TARGETS)
cd examples/programs && $(MAKE) clean