Skip to content

Commit

Permalink
Add build script (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnzhou authored Oct 14, 2024
1 parent a1706a4 commit df25932
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Ignore macOS specific files
.DS_Store

# Ignore build artifacts
.build/

# Ignore Xcode project files
*.xcodeproj/
xcuserdata/

# Ignore Swift Package Manager files
.swiftpm/
Package.resolved

# Ignore user configuration files
.netrc
.vscode/

# Ignore other temporary files or directories
DerivedData/
images/
release/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ DerivedData/
.swiftpm
Package.resolved
.vscode
release/
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: clean
clean:
rm -rf .build .swiftpm Package.resolved || true

.PHONY: build-test
build-test:
swift build

.PHONY: build-release
build-release:
swift build --static-swift-stdlib -c release
17 changes: 17 additions & 0 deletions docker/build_debian.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM swift:5.10.1-bookworm

RUN apt update && \
apt install build-essential -y

COPY . /tmp/lcl-cli
WORKDIR /tmp/lcl-cli
RUN ls -a

RUN swift build \
--static-swift-stdlib \
-c release

RUN mv .build/release/lcl /lcl
RUN strip /lcl
RUN /lcl --help
RUN ldd /lcl
17 changes: 17 additions & 0 deletions docker/build_ubuntu.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM swift:5.10.1-noble

RUN apt-get update && \
apt-get install build-essential -y

COPY . /tmp/lcl-cli
WORKDIR /tmp/lcl-cli
RUN ls -a

RUN swift build \
--static-swift-stdlib \
-c release

RUN mv .build/release/lcl /lcl
RUN strip /lcl
RUN /lcl --help
RUN ldd /lcl
70 changes: 70 additions & 0 deletions scripts/build_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

set -e

if [[ ! -z "$(git status --porcelain=v1 2>/dev/null)" ]]; then
echo "There are uncommitted changes in the local tree, please commit or discard them"
exit 1
fi

raw_arch="$(uname -m)"
case "$raw_arch" in
"x86_64")
arch="x86_64"
;;

"aarch64" | "arm64")
arch="aarch64"
;;

*)
echo "Error: Unsupported CPU architecture: $raw_arch"
;;
esac

os="$(uname)"

release_tag="$(git describe --tags `git rev-list --tags --max-count=1`)"
echo "Release version: $release_tag"
echo "OS: $os"

git checkout "$release_tag"

mkdir -p release

image_name_prefix="lcl-cli-$release_tag"
binary_name_prefix="lcl-cli-$release_tag-$arch"

function build_for_linux() {
local platform=$1
local image_name="$image_name_prefix-$platform"

echo "arch: $arch"
echo "platform: $platform"
echo "image_name: $image_name"
echo "binary_name: $binary_name_prefix-$platform"

docker build -t "$image_name" -f "docker/build_$platform.dockerfile" .
local container_id=$(docker create "$image_name")
docker cp "$container_id:/lcl" "release/$binary_name_prefix-$platform"
docker rm -v "$container_id"
docker image rm -f "$image_name"

echo "Binary for $platform has been successfully built!"
}

function build_for_macos() {
echo "arch: $arch"
echo "platform: macOS"
echo "binary_name: $binary_name_prefix-macos"

make build-release
mv .build/release/lcl release/lcl
strip release/lcl
./release/lcl --help
mv release/lcl "release/$binary_name_prefix-macos"
}

build_for_linux ubuntu
build_for_linux debian
build_for_macos

0 comments on commit df25932

Please sign in to comment.