Following is a all-in-one BASH script to reproduce this:
When ran the first time successful, no code changes, re run it again, the build process still slow.
as you can see, I try to use cache like this:
RUN --mount=type=cache,target=/root/.cache/crystal shards build …
And, following is the output of the files in the /root/.cache/crystal before the next build
app-lib-baked_file_system-src-loader.cr
app-lib-baked_file_system_mounter-src-baked_file_system_mounter-baked_files.cr
app-lib-lucky-src-run_macros-generate_asset_helpers.cr
app-lib-rosetta-src-rosetta-runner.cr
app-src-build_doc_index.cr
app-src-crystal_china.cr
usr-lib-crystal-core-ecr-process.cr
And sum the file sizes in that folder, before and after the build process.
17.7M /root/.cache/crystal
cc /app/bin/crystal_china.o -o /app/bin/crystal_china -Wl,-L/app -s -pie -rdynamic -static -L/usr/bin/../lib/crystal -lxml2 -lm -lz -llzma -pthread -lpthread -lgmp -lyaml -lz command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto' command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto' -lpcre2-8 -pthread -lpthread -lgc -lpthread -ldl
cc /app/bin/index.o -o /app/bin/index -Wl,-L/app -s -pie -rdynamic -static -L/usr/bin/../lib/crystal -lyaml -lgc -lpthread -ldl
17.7M /root/.cache/crystal
But, the (the cross compile )build process speed far slow than development build (on AMD64) on my local.
I am not use the --release or others optimization option, following is my build options:
ARG flags=“–stats --time”
ARG compile_time_flags=“-Dstrict_multi_assign -Dno_number_autocast -Duse_pcre2 -Dpreview_overload_order”
link_flags=“–link-flags=-Wl,-L/app --link-flags=-s --link-flags=-pie”
shards build --production --static $flags $compile_time_flags $link_flags --cross-compile --target=aarch64-linux-musl