refactor: update tinygo-build-all task to build targets in parallel using xargs
This commit is contained in:
28
Taskfile.yml
28
Taskfile.yml
@@ -252,25 +252,27 @@ tasks:
|
||||
- tinygo build -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-tinygo-debug -size short -opt=1 {{.MAIN_PACKAGE}}
|
||||
|
||||
tinygo-build-all:
|
||||
desc: Build for all available TinyGo targets
|
||||
desc: Build for all available TinyGo targets in parallel
|
||||
cmds:
|
||||
- mkdir -p {{.BUILD_DIR}}
|
||||
- echo "Building for all TinyGo targets..."
|
||||
- echo "Building for all TinyGo targets in parallel..."
|
||||
- |
|
||||
targets=$(tinygo targets)
|
||||
failed=0
|
||||
for target in $targets; do
|
||||
if [ -n "$target" ]; then
|
||||
echo "Building for target: $target"
|
||||
if ! tinygo build -target "$target" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-"$target" -size short -opt=z -gc=leaking -panic=trap {{.MAIN_PACKAGE}} 2>&1 | tee {{.BUILD_DIR}}/build-"$target".log; then
|
||||
echo "Failed to build for $target" >> {{.BUILD_DIR}}/build-"$target".log
|
||||
failed=$((failed + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
# Use xargs to build in parallel, limited to number of CPU cores
|
||||
echo "$targets" | xargs -P $(nproc) -I {} sh -c '
|
||||
target="{}";
|
||||
if [ -n "$target" ]; then
|
||||
echo "Building for target: $target";
|
||||
if ! tinygo build -target "$target" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-"$target" -size short -opt=z -gc=leaking -panic=trap {{.MAIN_PACKAGE}} 2>&1 | tee {{.BUILD_DIR}}/build-"$target".log; then
|
||||
echo "Failed to build for $target" >> {{.BUILD_DIR}}/build-"$target".log;
|
||||
exit 1;
|
||||
fi;
|
||||
fi' || failed=1
|
||||
|
||||
echo "Build complete. Check {{.BUILD_DIR}}/ for outputs and logs."
|
||||
if [ $failed -gt 0 ]; then
|
||||
echo "$failed target(s) failed to build. See logs in {{.BUILD_DIR}}/build-*.log"
|
||||
if [ $failed -ne 0 ]; then
|
||||
echo "Some target(s) failed to build. See logs in {{.BUILD_DIR}}/build-*.log"
|
||||
fi
|
||||
|
||||
tinygo-wasm:
|
||||
|
||||
Reference in New Issue
Block a user