Skip to content

Commit 9108afa

Browse files
refactor makefile (dfinity#81)
1 parent 379809f commit 9108afa

File tree

15 files changed

+129
-186
lines changed

15 files changed

+129
-186
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ APPS = dapps collections crypto pub-sub heartbeat motoko
22

33
all:
44
$(foreach test_dir,$(APPS),make -C $(test_dir) &&) true
5-

collections/Makefile

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
1-
APP = collections
1+
include ../*.mk
22

33
.PHONY: all motoko rust build perf
44
all: build perf
55

66
motoko:
7-
set -e; \
8-
cd motoko; \
9-
envsubst < mops.template.toml > mops.toml; \
10-
mops install; \
11-
dfx canister create --all; \
12-
dfx ledger fabricate-cycles --t 100 --canister $$(dfx identity get-wallet); \
13-
dfx build; \
14-
echo "Optimize with ic-wasm level 3"; \
15-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
16-
rm mops.toml; \
17-
cd ..
7+
$(call build_with_mops,motoko)
188

199
rust:
20-
set -e; \
21-
cd rust; \
22-
dfx canister create --all; \
23-
dfx ledger fabricate-cycles --t 100 --canister $$(dfx identity get-wallet); \
24-
dfx build; \
25-
echo "Optimize with ic-wasm level 3"; \
26-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
27-
cd ..
10+
$(call build,rust)
2811

2912
build: motoko rust
3013

3114
perf:
32-
set -e; \
33-
mkdir -p ../_out/$(APP); \
34-
cp README.md ../_out/$(APP); \
35-
cd ../_out/$(APP); \
36-
ic-repl ../../$(APP)/perf.sh
15+
$(call perf,collections,perf.sh)

crypto/Makefile

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
1-
APP = crypto
1+
include ../*.mk
22

33
.PHONY: all motoko rust build perf
44
all: build perf
55

66
motoko:
7-
set -e; \
8-
cd motoko; \
9-
envsubst < mops.template.toml > mops.toml; \
10-
mops install; \
11-
dfx canister create --all; \
12-
dfx build; \
13-
echo "Optimize with ic-wasm level 3"; \
14-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
15-
rm mops.toml; \
16-
cd ..
7+
$(call build_with_mops,motoko)
178

189
rust:
19-
set -e; \
20-
cd rust; \
21-
dfx canister create --all; \
22-
dfx build; \
23-
echo "Optimize with ic-wasm level 3"; \
24-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
25-
cd ..
10+
$(call build,rust)
2611

2712
build: motoko rust
2813

2914
perf:
30-
set -e; \
31-
mkdir -p ../_out/$(APP); \
32-
cp README.md ../_out/$(APP); \
33-
cd ../_out/$(APP); \
34-
ic-repl ../../$(APP)/perf.sh
15+
$(call perf,crypto,perf.sh)

dapps/Makefile

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
APP = dapps
1+
include ../*.mk
22

33
.PHONY: all motoko rust build perf
44
all: build perf
55

66
motoko:
7-
cd motoko; \
8-
dfx canister create --all; \
9-
dfx build; \
10-
echo "Optimize with ic-wasm level 3"; \
11-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
12-
cd ..
7+
$(call build,motoko)
138

149
rust:
15-
cd rust; \
16-
dfx canister create --all; \
17-
dfx build; \
18-
echo "Optimize with ic-wasm level 3"; \
19-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
20-
cd ..
10+
$(call build,rust)
2111

2212
build: motoko rust
2313

2414
perf:
25-
set -e; \
26-
mkdir -p ../_out/$(APP); \
27-
cp README.md ../_out/$(APP); \
28-
cd ../_out/$(APP); \
29-
ic-repl ../../$(APP)/basic_dao.sh; \
30-
ic-repl ../../$(APP)/nft.sh
15+
$(call perf_two,dapps,basic_dao.sh,nft.sh)

heartbeat/Makefile

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
APP = heartbeat
1+
include ../*.mk
22

33
.PHONY: all motoko rust build perf
44
all: build perf
55

66
motoko:
7-
cd motoko; \
8-
envsubst < mops.template.toml > mops.toml; \
9-
mops install; \
10-
dfx canister create --all; \
11-
dfx build; \
12-
echo "Optimize with ic-wasm level 3"; \
13-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
14-
rm mops.toml; \
15-
cd ..
7+
$(call build_with_mops,motoko)
168

179
rust:
18-
cd rust; \
19-
dfx canister create --all; \
20-
dfx build; \
21-
echo "Optimize with ic-wasm level 3"; \
22-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
23-
cd ..
10+
$(call build,rust)
2411

2512
build: motoko rust
2613

2714
perf:
28-
set -e; \
29-
mkdir -p ../_out/$(APP); \
30-
cp README.md ../_out/$(APP); \
31-
cd ../_out/$(APP); \
32-
ic-repl ../../$(APP)/perf.sh
15+
$(call perf,heartbeat,perf.sh)

motoko/Makefile

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
APP = motoko
1+
include ../*.mk
22

33
.PHONY: all build perf
44
all: build perf
55

66
build:
7-
envsubst < mops.template.toml > mops.toml; \
8-
mops install; \
9-
dfx canister create --all; \
10-
dfx build; \
11-
echo "Optimize with ic-wasm level 3"; \
12-
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
13-
rm mops.toml; \
14-
cd ..
7+
$(call build_with_mops,motoko)
158

169
perf:
17-
set -e; \
18-
mkdir -p ../_out/$(APP); \
19-
cp README.md ../_out/$(APP); \
20-
cd ../_out/$(APP); \
21-
ic-repl ../../$(APP)/gc.sh; \
22-
ic-repl ../../$(APP)/classes.sh
23-
24-
clean:
25-
rm *.wasm && rm mops.toml
10+
$(call perf_two,motoko,gc.sh,classes.sh)

motoko/classes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!ic-repl
22
load "../prelude.sh";
33

4-
let class = wasm_profiling(".dfx/local/canisters/classes/classes.wasm");
4+
let class = wasm_profiling("motoko/.dfx/local/canisters/classes/classes.wasm");
55
let map = install(class, encode (), null);
66

77
let file = "README.md";

motoko/dfx.json

Lines changed: 0 additions & 54 deletions
This file was deleted.

motoko/gc.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!ic-repl
22
load "../prelude.sh";
33

4-
let default = wasm_profiling("default.wasm", vec{"schedule_copying_gc"});
5-
let copying = wasm_profiling("copying.wasm", vec {"copying_gc"});
6-
let compacting = wasm_profiling("compacting.wasm", vec{"compacting_gc"});
7-
let generational = wasm_profiling("generational.wasm", vec{"generational_gc"});
8-
let incremental = wasm_profiling("incremental.wasm", vec{"incremental_gc"});
4+
let default = wasm_profiling("motoko/default.wasm", vec{"schedule_copying_gc"});
5+
let copying = wasm_profiling("motoko/copying.wasm", vec {"copying_gc"});
6+
let compacting = wasm_profiling("motoko/compacting.wasm", vec{"compacting_gc"});
7+
let generational = wasm_profiling("motoko/generational.wasm", vec{"generational_gc"});
8+
let incremental = wasm_profiling("motoko/incremental.wasm", vec{"incremental_gc"});
99

1010
let file = "README.md";
1111
output(file, "\n\n## Garbage Collection\n\n| |generate 800k|max mem|batch_get 50|batch_put 50|batch_remove 50|\n|--:|--:|--:|--:|--:|--:|\n");

motoko/motoko/dfx.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"canisters": {
3+
"classes": {
4+
"type": "motoko",
5+
"main": "src/Map.mo"
6+
},
7+
"default": {
8+
"type": "custom",
9+
"candid": "../../collections/rust/collection.did",
10+
"wasm": "default.wasm",
11+
"build": [
12+
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o default.wasm --public-metadata candid:service $(mops sources)'"
13+
]
14+
},
15+
"copying": {
16+
"type": "custom",
17+
"candid": "../../collections/rust/collection.did",
18+
"wasm": "copying.wasm",
19+
"build": [
20+
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o copying.wasm --public-metadata candid:service $(mops sources) --force-gc --copying-gc'"
21+
]
22+
},
23+
"compacting": {
24+
"type": "custom",
25+
"candid": "../../collections/rust/collection.did",
26+
"wasm": "compacting.wasm",
27+
"build": [
28+
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o compacting.wasm --public-metadata candid:service $(mops sources) --force-gc --compacting-gc'"
29+
]
30+
},
31+
"generational": {
32+
"type": "custom",
33+
"candid": "../../collections/rust/collection.did",
34+
"wasm": "generational.wasm",
35+
"build": [
36+
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o generational.wasm --public-metadata candid:service $(mops sources) --force-gc --generational-gc'"
37+
]
38+
},
39+
"incremental": {
40+
"type": "custom",
41+
"candid": "../../collections/rust/collection.did",
42+
"wasm": "incremental.wasm",
43+
"build": [
44+
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o incremental.wasm --public-metadata candid:service $(mops sources) --force-gc --incremental-gc'"
45+
]
46+
}
47+
},
48+
"defaults": {
49+
"build": {
50+
"packtool": "mops sources",
51+
"args": ""
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)