22
33set -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+
511if [[ ! -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"
3844function 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