Skip to content

Commit f5a8793

Browse files
authored
chore: optimize build process (#6)
1 parent 963c3c3 commit f5a8793

File tree

4 files changed

+57
-45
lines changed

4 files changed

+57
-45
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
DOCKER_IMAGE=swift:6.1.2
2+
13
.PHONY: clean
24
clean:
35
rm -rf .build .swiftpm Package.resolved || true
@@ -8,4 +10,11 @@ build-test:
810

911
.PHONY: build-release
1012
build-release:
11-
swift build --static-swift-stdlib -c release
13+
swift build --static-swift-stdlib -c release
14+
15+
dev:
16+
docker run --rm -it \
17+
-v $(shell pwd):/app \
18+
-w /app \
19+
$(DOCKER_IMAGE) \
20+
/bin/bash

docker/build_debian.dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

docker/build_ubuntu.dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/build_release.sh

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
set -e
44

5+
if [ -z "$1" ]; then
6+
echo "Error: No argument provided."
7+
echo "Usage: $0 {ubuntu|debian|macos}"
8+
exit 1
9+
fi
10+
511
if [[ ! -z "$(git status --porcelain=v1 2>/dev/null)" ]]; then
612
echo "There are uncommitted changes in the local tree, please commit or discard them"
713
exit 1
@@ -38,18 +44,34 @@ binary_name_prefix="lcl-cli-$release_tag-$arch"
3844
function build_for_linux() {
3945
local platform=$1
4046
local image_name="$image_name_prefix-$platform"
47+
case "$platform" in
48+
ubuntu)
49+
tag="noble"
50+
;;
51+
debian)
52+
tag="bookworm"
53+
;;
54+
*)
55+
echo "Error: Unsupported platform: $platform"
56+
exit 1
57+
;;
58+
esac
59+
local docker_image="swift:6.1.2-$tag"
4160

4261
echo "arch: $arch"
4362
echo "platform: $platform"
4463
echo "image_name: $image_name"
4564
echo "binary_name: $binary_name_prefix-$platform"
65+
echo "directory: $(pwd)"
4666

47-
docker build -t "$image_name" -f "docker/build_$platform.dockerfile" .
48-
local container_id=$(docker create "$image_name")
49-
docker cp "$container_id:/lcl" "release/$binary_name_prefix-$platform"
50-
docker rm -v "$container_id"
51-
docker image rm -f "$image_name"
67+
docker run --rm \
68+
-v "$(pwd)":/app \
69+
-v "$(pwd)/release":/app/release \
70+
-w /app \
71+
"$docker_image" \
72+
bash -c "swift build --static-swift-stdlib -c release && strip .build/release/lcl && mv .build/release/lcl release/$binary_name_prefix-$platform"
5273

74+
docker rmi -f "$docker_image" || true
5375
echo "Binary for $platform has been successfully built!"
5476
}
5577

@@ -59,12 +81,27 @@ function build_for_macos() {
5981
echo "binary_name: $binary_name_prefix-macos"
6082

6183
make build-release
62-
mv .build/release/lcl release/lcl
84+
mv .build/release/lcl release/$binary_name_prefix-macos
6385
strip release/lcl
6486
./release/lcl --help
65-
mv release/lcl "release/$binary_name_prefix-macos"
6687
}
6788

68-
build_for_linux ubuntu
69-
build_for_linux debian
70-
build_for_macos
89+
# Use a case statement to call the correct function
90+
case "$1" in
91+
ubuntu)
92+
build_for_linux ubuntu
93+
;;
94+
debian)
95+
build_for_linux debian
96+
;;
97+
macos)
98+
build_for_macos
99+
;;
100+
*)
101+
echo "Error: Invalid argument '$1'."
102+
echo "Usage: $0 {ubuntu|debian|macos}"
103+
exit 1
104+
;;
105+
esac
106+
107+
exit 0

0 commit comments

Comments
 (0)