diff --git a/Makefile b/Makefile index a912aa69..36473db0 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,3 @@ APPS = dapps collections crypto pub-sub heartbeat motoko all: $(foreach test_dir,$(APPS),make -C $(test_dir) &&) true - diff --git a/collections/Makefile b/collections/Makefile index 17c3ce4b..8222603c 100644 --- a/collections/Makefile +++ b/collections/Makefile @@ -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) diff --git a/crypto/Makefile b/crypto/Makefile index 20f25a0b..4714a4f7 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -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) diff --git a/dapps/Makefile b/dapps/Makefile index d60b6bd1..9c920ddf 100644 --- a/dapps/Makefile +++ b/dapps/Makefile @@ -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) diff --git a/heartbeat/Makefile b/heartbeat/Makefile index fbdb7ff8..58d91852 100644 --- a/heartbeat/Makefile +++ b/heartbeat/Makefile @@ -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) diff --git a/motoko/Makefile b/motoko/Makefile index e3a98ef9..1d5e0ebf 100644 --- a/motoko/Makefile +++ b/motoko/Makefile @@ -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) diff --git a/motoko/classes.sh b/motoko/classes.sh index e85beed0..124310a6 100644 --- a/motoko/classes.sh +++ b/motoko/classes.sh @@ -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"; diff --git a/motoko/dfx.json b/motoko/dfx.json deleted file mode 100644 index b18e8da9..00000000 --- a/motoko/dfx.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "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": "" - } - } -} diff --git a/motoko/gc.sh b/motoko/gc.sh index e8822ffe..64f68d52 100644 --- a/motoko/gc.sh +++ b/motoko/gc.sh @@ -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"); diff --git a/motoko/motoko/dfx.json b/motoko/motoko/dfx.json new file mode 100644 index 00000000..b47d608b --- /dev/null +++ b/motoko/motoko/dfx.json @@ -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": "" + } + } +} diff --git a/motoko/mops.template.toml b/motoko/motoko/mops.template.toml similarity index 100% rename from motoko/mops.template.toml rename to motoko/motoko/mops.template.toml diff --git a/motoko/src/Buckets.mo b/motoko/motoko/src/Buckets.mo similarity index 100% rename from motoko/src/Buckets.mo rename to motoko/motoko/src/Buckets.mo diff --git a/motoko/src/Map.mo b/motoko/motoko/src/Map.mo similarity index 100% rename from motoko/src/Map.mo rename to motoko/motoko/src/Map.mo diff --git a/pub-sub/Makefile b/pub-sub/Makefile index 5133bd18..a4bbdeed 100644 --- a/pub-sub/Makefile +++ b/pub-sub/Makefile @@ -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) diff --git a/utils.mk b/utils.mk new file mode 100644 index 00000000..bd44ea4b --- /dev/null +++ b/utils.mk @@ -0,0 +1,46 @@ +define ic-wasm + echo "Optimize with ic-wasm"; \ + for f in $(1)/*/*.wasm; do ic-wasm -o $$f $$f shrink --optimize O3 --keep-name-section; done +endef + +define build_with_mops + set -e; \ + cd $(1); \ + 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; \ + rm mops.toml; \ + $(call ic-wasm,.dfx/local/canisters/); \ + cd .. +endef + +define build + set -e; \ + cd $(1); \ + dfx canister create --all; \ + dfx ledger fabricate-cycles --t 100 --canister $$(dfx identity get-wallet); \ + dfx build; \ + $(call ic-wasm,.dfx/local/canisters/); \ + cd .. +endef + +define prepare_perf + mkdir -p ../_out/$(1); \ + cp README.md ../_out/$(1); \ + cd ../_out/$(1) +endef + +define perf + set -e; \ + $(call prepare_perf,$(1)); \ + ic-repl ../../$(1)/$(2) +endef + +define perf_two + set -e; \ + $(call prepare_perf,$(1)); \ + ic-repl ../../$(1)/$(2); \ + ic-repl ../../$(1)/$(3) +endef