Skip to content

Commit

Permalink
refactor makefile (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity authored Sep 15, 2023
1 parent 379809f commit 9108afa
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 186 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ APPS = dapps collections crypto pub-sub heartbeat motoko

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

29 changes: 4 additions & 25 deletions collections/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
APP = collections
include ../*.mk

.PHONY: all motoko rust build perf
all: build perf

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

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

build: motoko rust

perf:
set -e; \
mkdir -p ../_out/$(APP); \
cp README.md ../_out/$(APP); \
cd ../_out/$(APP); \
ic-repl ../../$(APP)/perf.sh
$(call perf,collections,perf.sh)
27 changes: 4 additions & 23 deletions crypto/Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
APP = crypto
include ../*.mk

.PHONY: all motoko rust build perf
all: build perf

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

rust:
set -e; \
cd rust; \
dfx canister create --all; \
dfx build; \
echo "Optimize with ic-wasm level 3"; \
for f in .dfx/local/canisters/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done; \
cd ..
$(call build,rust)

build: motoko rust

perf:
set -e; \
mkdir -p ../_out/$(APP); \
cp README.md ../_out/$(APP); \
cd ../_out/$(APP); \
ic-repl ../../$(APP)/perf.sh
$(call perf,crypto,perf.sh)
23 changes: 4 additions & 19 deletions dapps/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
APP = dapps
include ../*.mk

.PHONY: all motoko rust build perf
all: build perf

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

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

build: motoko rust

perf:
set -e; \
mkdir -p ../_out/$(APP); \
cp README.md ../_out/$(APP); \
cd ../_out/$(APP); \
ic-repl ../../$(APP)/basic_dao.sh; \
ic-repl ../../$(APP)/nft.sh
$(call perf_two,dapps,basic_dao.sh,nft.sh)
25 changes: 4 additions & 21 deletions heartbeat/Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
APP = heartbeat
include ../*.mk

.PHONY: all motoko rust build perf
all: build perf

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

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

build: motoko rust

perf:
set -e; \
mkdir -p ../_out/$(APP); \
cp README.md ../_out/$(APP); \
cd ../_out/$(APP); \
ic-repl ../../$(APP)/perf.sh
$(call perf,heartbeat,perf.sh)
21 changes: 3 additions & 18 deletions motoko/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
APP = motoko
include ../*.mk

.PHONY: all build perf
all: build perf

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

perf:
set -e; \
mkdir -p ../_out/$(APP); \
cp README.md ../_out/$(APP); \
cd ../_out/$(APP); \
ic-repl ../../$(APP)/gc.sh; \
ic-repl ../../$(APP)/classes.sh

clean:
rm *.wasm && rm mops.toml
$(call perf_two,motoko,gc.sh,classes.sh)
2 changes: 1 addition & 1 deletion motoko/classes.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!ic-repl
load "../prelude.sh";

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

let file = "README.md";
Expand Down
54 changes: 0 additions & 54 deletions motoko/dfx.json

This file was deleted.

10 changes: 5 additions & 5 deletions motoko/gc.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!ic-repl
load "../prelude.sh";

let default = wasm_profiling("default.wasm", vec{"schedule_copying_gc"});
let copying = wasm_profiling("copying.wasm", vec {"copying_gc"});
let compacting = wasm_profiling("compacting.wasm", vec{"compacting_gc"});
let generational = wasm_profiling("generational.wasm", vec{"generational_gc"});
let incremental = wasm_profiling("incremental.wasm", vec{"incremental_gc"});
let default = wasm_profiling("motoko/default.wasm", vec{"schedule_copying_gc"});
let copying = wasm_profiling("motoko/copying.wasm", vec {"copying_gc"});
let compacting = wasm_profiling("motoko/compacting.wasm", vec{"compacting_gc"});
let generational = wasm_profiling("motoko/generational.wasm", vec{"generational_gc"});
let incremental = wasm_profiling("motoko/incremental.wasm", vec{"incremental_gc"});

let file = "README.md";
output(file, "\n\n## Garbage Collection\n\n| |generate 800k|max mem|batch_get 50|batch_put 50|batch_remove 50|\n|--:|--:|--:|--:|--:|--:|\n");
Expand Down
54 changes: 54 additions & 0 deletions motoko/motoko/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"canisters": {
"classes": {
"type": "motoko",
"main": "src/Map.mo"
},
"default": {
"type": "custom",
"candid": "../../collections/rust/collection.did",
"wasm": "default.wasm",
"build": [
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o default.wasm --public-metadata candid:service $(mops sources)'"
]
},
"copying": {
"type": "custom",
"candid": "../../collections/rust/collection.did",
"wasm": "copying.wasm",
"build": [
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o copying.wasm --public-metadata candid:service $(mops sources) --force-gc --copying-gc'"
]
},
"compacting": {
"type": "custom",
"candid": "../../collections/rust/collection.did",
"wasm": "compacting.wasm",
"build": [
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o compacting.wasm --public-metadata candid:service $(mops sources) --force-gc --compacting-gc'"
]
},
"generational": {
"type": "custom",
"candid": "../../collections/rust/collection.did",
"wasm": "generational.wasm",
"build": [
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o generational.wasm --public-metadata candid:service $(mops sources) --force-gc --generational-gc'"
]
},
"incremental": {
"type": "custom",
"candid": "../../collections/rust/collection.did",
"wasm": "incremental.wasm",
"build": [
"sh -c '$(dfx cache show)/moc ../../collections/motoko/src/triemap.mo -o incremental.wasm --public-metadata candid:service $(mops sources) --force-gc --incremental-gc'"
]
}
},
"defaults": {
"build": {
"packtool": "mops sources",
"args": ""
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 4 additions & 19 deletions pub-sub/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
APP = pub-sub
include ../*.mk

.PHONY: all motoko rust build perf
all: build perf

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

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

build: motoko rust

perf:
set -e; \
mkdir -p ../_out/$(APP); \
cp README.md ../_out/$(APP); \
cd ../_out/$(APP); \
ic-repl ../../$(APP)/motoko/perf.sh; \
ic-repl ../../$(APP)/rust/perf.sh
$(call perf_two,pub-sub,motoko/perf.sh,rust/perf.sh)
Loading

0 comments on commit 9108afa

Please sign in to comment.