Hi,
I’m trying to use a custom build in our project. Due to massive wasm size we are required to gzip the wasm or use factories eg: GitHub - crusso/alt-actor-classes at claudio/alt in order to avoid the 2mb limit.
We have the main canister which imports 3 actor classes:
import Content "../service/content/Actor";
import Global "../service/global/Actor";
import Player "../service/player/Actor";
Gzip works but building normally vs custom doesn’t give the expected output:
So the first method is the usual one:
In dfx.json
"main": {
"type": "motoko",
"main": "src/backend/main/Actor.mo"
}
dfx build time: real 2m14.632s
wasm size: 6,503kb
Second method:
dfx.json:
"main": {
"type": "custom",
"build": "sh -c './scripts/compress-main.sh main'",
"candid": "src/declarations/main/main.did",
"wasm": "src/declarations/content/main.wasm.gz"
}
And the bash script only generates the IDL and the wasm file and creates a gzip file as well.
mkdir -p src/declarations/$1
$(dfx cache show)/moc --idl src/backend/main/Actor.mo --package base ".vessel/base/master/src" -o src/declarations/$1/$1.did $(echo ${packages})
$(dfx cache show)/moc src/backend/main/Actor.mo -o src/declarations/$1/$1.did --package base ".vessel/base/master/src" -o src/declarations/$1/$1.wasm $(echo ${packages})
gzip -c src/declarations/$1/$1.wasm > src/declarations/$1/$1.wasm.gz
I was expecting roughly the same build time and size but I get something different:
dfx build time: real 3m33.676s
wasm size: 10,262kb
Also like 1/5 builds I get an error on the custom one like Error: Failed while trying to build all canisters. Caused by: Failed while trying to build all canisters. The post-build step failed for canister 'r7inp-6aaaa-aaaaa-aaabq-cai' (main) with an embedded error: No such file or directory (os error 2)
I was under the impression that dfx build runs the moc and it should be slower than running the moc compiler manually, but it seems to be the other way around.
Also I wonder how difficult will be to add a post-build key in dfx like
"post-build" : "sh -c 'compress.sh'"
This would be super helpful to generate stuff like declarations, gzip the wasm module etc.
Any suggestions are welcome.