Skip to content

Commit

Permalink
feat: add linux/arm64 (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: Hu Yueh-Wei <wei.hu.tw@gmail.com>
  • Loading branch information
wangyoucao577 and halajohn authored Oct 14, 2024
1 parent 8e1c00f commit 22f545b
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ jobs:
include:
- image_name: "ubuntu2204"
workdir: "tools/docker_for_building/ubuntu/22.04"
platforms: linux/amd64,linux/arm64
- image_name: "ubuntu1804"
workdir: "tools/docker_for_building/ubuntu/18.04"
platforms: linux/amd64
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build & Publish to Github Container Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
Expand All @@ -33,5 +38,6 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: ${{ matrix.workdir }}
platforms: ${{ matrix.platforms }}
snapshot: true
tags: "${{ github.ref == 'refs/heads/main' && 'latest,' || '' }}"
99 changes: 99 additions & 0 deletions .github/workflows/build_linux_arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Build - linux arm64

on:
release:
types: [created]
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- "tools/**"
- "docs/**"
- ".vscode/**"
- ".devcontainer/**"
- ".github/**"
- "!.github/workflows/build_linux_arm64.yml"
- "**.md"

jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: build-linux-arm64-${{ github.head_ref }}-${{ matrix.compiler }}-${{ matrix.build_type }}
cancel-in-progress: true
strategy:
matrix:
compiler: [gcc]
build_type: [release]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
submodules: "true"

- name: Update version
run: |
git config --global --add safe.directory $(pwd)
python3 tools/version/update_version_in_ten_framework.py
python3 tools/version/check_version_in_ten_framework.py
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Build
run: |
docker run --rm --platform linux/arm64 \
-v $(pwd):/${{ github.workspace }} -w ${{ github.workspace }} \
ghcr.io/ten-framework/ten_building_ubuntu2204 \
bash -c "\
export PATH=$(pwd)/core/ten_gn:/usr/local/go/bin:/root/go/bin:/root/.cargo/bin:$PATH && \
echo $PATH && \
go env -w GOFLAGS="-buildvcs=false" && \
go1.20.12 download && \
rustup default nightly && \
tgn gen linux arm64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_enable_tests=false ten_enable_libwebsockets=false && \
tgn build linux arm64 ${{ matrix.build_type }} && \
tree -I 'gen|obj' out \
"
- name: Upload tman
uses: actions/upload-artifact@v4
with:
name: tman-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}
path: out/linux/arm64/ten_manager/bin/tman

- name: Upload ten_packages
uses: actions/upload-artifact@v4
with:
name: ten_packages-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}
path: |
out/linux/x64/ten_packages/system/ten_runtime
out/linux/x64/ten_packages/system/ten_runtime_go
out/linux/x64/ten_packages/system/ten_runtime_python
out/linux/arm64/ten_packages/extension/default_extension_cpp
out/linux/arm64/ten_packages/extension/default_extension_go
out/linux/arm64/ten_packages/extension/default_extension_python
out/linux/arm64/ten_packages/extension/py_init_extension_cpp
- name: Package assets
if: startsWith(github.ref, 'refs/tags/')
run: |
cd out/linux/arm64
zip -vr tman-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip ten_manager/bin/tman
zip -vr ten_packages-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip \
ten_packages/system/ten_runtime \
ten_packages/system/ten_runtime_go \
ten_packages/system/ten_runtime_python \
ten_packages/extension/default_extension_cpp \
ten_packages/extension/default_extension_go \
ten_packages/extension/default_extension_python \
ten_packages/extension/py_init_extension_cpp
- name: Publish to release assets
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
out/linux/arm64/tman-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip
out/linux/arm64/ten_packages-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip
24 changes: 16 additions & 8 deletions build/common/scripts/package_asan_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def detect_mac_asan_lib(arch: str) -> str:


def detect_linux_asan_lib(arch: str) -> str:
if arch == "x64":
if arch in ["x64", "arm64"]:
out, _ = subprocess.Popen(
"gcc -print-file-name=libasan.so",
shell=True,
Expand All @@ -79,13 +79,21 @@ def detect_linux_asan_lib(arch: str) -> str:

# Generally speaking, this function should not need to be called because Clang's
# default ASan mechanism is static linking.
def detect_linux_clang_asan_lib(_arch: str) -> str:
out, _ = subprocess.Popen(
"clang -print-file-name=libclang_rt.asan-x86_64.so",
shell=True,
stdout=subprocess.PIPE,
encoding="utf-8",
).communicate()
def detect_linux_clang_asan_lib(arch: str) -> str:
if arch == "x64":
out, _ = subprocess.Popen(
"clang -print-file-name=libclang_rt.asan-x86_64.so",
shell=True,
stdout=subprocess.PIPE,
encoding="utf-8",
).communicate()
elif arch == "arm64":
out, _ = subprocess.Popen(
"clang -print-file-name=libclang_rt.asan-aarch64.so",
shell=True,
stdout=subprocess.PIPE,
encoding="utf-8",
).communicate()

libasan_path = out.strip()

Expand Down
4 changes: 2 additions & 2 deletions build/ten_manager/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ declare_args() {
}

declare_args() {
ten_package_manager_enable_tests =
is_linux || is_win || (is_mac && target_cpu == "x64")
ten_package_manager_enable_tests = (is_linux && target_cpu == "x64") ||
is_win || (is_mac && target_cpu == "x64")
}
10 changes: 8 additions & 2 deletions build/ten_runtime/feature/autotool.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ def copy_system_deps(self):

if sys.platform == "linux":
libs.extend(
glob.glob(f"/usr/lib/x86_64-linux-gnu/lib{dep}.so.*")
glob.glob(
f"/usr/lib/{os.uname().machine}-linux-gnu/lib{dep}.so.*"
)
)
libs.extend(
glob.glob(
f"/usr/lib/{os.uname().machine}-linux-gnu/lib{dep}.so"
)
)
libs.extend(glob.glob(f"/usr/lib/x86_64-linux-gnu/lib{dep}.so"))
else:
print("TODO: Add support for other platforms.")
sys.exit(1)
Expand Down
17 changes: 10 additions & 7 deletions build/ten_runtime/feature/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,16 @@ def _fill_attributes(self):
self.sharedlinkerflags.append("--target=arm-linux-gnueabihf")
self.exelinkerflags.append("--target=arm-linux-gnueabihf")
elif self.args.target_cpu == "arm64":
self.cflags.append("--target=aarch64-linux-gnu")
self.sharedlinkerflags.append("--target=aarch64-linux-gnu")
self.exelinkerflags.append("--target=aarch64-linux-gnu")
if self.args.use_clang:
self.cflags.append("-fuse-ld=lld")
self.sharedlinkerflags.append("-fuse-ld=lld")
self.exelinkerflags.append("-fuse-ld=lld")
if os.uname().machine in ["arm64", "aarch64"]:
pass
else:
self.cflags.append("--target=aarch64-linux-gnu")
self.sharedlinkerflags.append("--target=aarch64-linux-gnu")
self.exelinkerflags.append("--target=aarch64-linux-gnu")
if self.args.use_clang:
self.cflags.append("-fuse-ld=lld")
self.sharedlinkerflags.append("-fuse-ld=lld")
self.exelinkerflags.append("-fuse-ld=lld")
else:
raise Exception(
"Currently can not build Linux target with CPU arch"
Expand Down
3 changes: 2 additions & 1 deletion build/ten_runtime/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ declare_args() {
ten_enable_go_binding = is_mac || is_linux

# TODO: enable it on mac and win
ten_enable_python_binding = is_linux && target_cpu == "x64"
ten_enable_python_binding =
is_linux && (target_cpu == "x64" || target_cpu == "arm64")
}

# ten_runtime extensions
Expand Down
3 changes: 2 additions & 1 deletion build/ten_rust/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ declare_args() {
}

declare_args() {
ten_rust_enable_tests = is_linux || is_win || (is_mac && target_cpu == "x64")
ten_rust_enable_tests = (is_linux && target_cpu == "x64") || is_win ||
(is_mac && target_cpu == "x64")
}
18 changes: 11 additions & 7 deletions tools/docker_for_building/ubuntu/22.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommend
tree \
zip \
unzip \
jq \
cpulimit \
util-linux \
libasan5 \
autoconf \
libtool \
uuid-dev \
g++-multilib \
libmsgpack-dev \
libmysqlclient-dev \
libmysqlcppconn-dev \
Expand Down Expand Up @@ -54,6 +56,11 @@ RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommend
python3-pip \
python3-venv

RUN export ARCH=$(dpkg --print-architecture) && \
if [ ${ARCH} = "amd64" ]; then \
apt-get install -y --no-install-recommends g++-multilib; \
fi

# =======================================
# Installing Python deps

Expand Down Expand Up @@ -84,10 +91,7 @@ RUN wget --no-check-certificate -O - https://apt.llvm.org/llvm-snapshot.gpg.key
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100 && \
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-18 100 && \
update-alternatives --install /usr/bin/clang-check clang-check /usr/bin/clang-check-18 100 && \
update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-18 100 && \
mkdir -p /usr/lib/llvm-18/lib/x86_64-pc-linux-gnu && \
ln -sf $(clang -print-file-name=libc++.a) /usr/lib/llvm-18/lib/x86_64-pc-linux-gnu && \
ln -sf $(clang -print-file-name=libclang_rt.asan.so) $(dirname $(clang -print-file-name=libclang_rt.asan.so))/libclang_rt.asan-x86_64.so
update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-18 100

# =======================================
# Install golang
Expand All @@ -97,8 +101,8 @@ ENV PATH="$PATH:/usr/local/go/bin:/root/go/bin"

# TEN go binding needs to be compatible with GO 1.20, so we need to install GO
# 1.20 to check the compatibility.
RUN curl -OL https://go.dev/dl/go1.22.3.linux-amd64.tar.gz && \
rm -rf /usr/local/go && tar -C /usr/local -xvf go1.22.3.linux-amd64.tar.gz && rm go1.22.3.linux-amd64.tar.gz && \
RUN export ARCH=$(dpkg --print-architecture) && curl -OL https://go.dev/dl/go1.22.3.linux-${ARCH}.tar.gz && \
rm -rf /usr/local/go && tar -C /usr/local -xvf go1.22.3.linux-${ARCH}.tar.gz && rm go1.22.3.linux-${ARCH}.tar.gz && \
go install golang.org/dl/go1.20.12@latest && go1.20.12 download

# =======================================
Expand Down

0 comments on commit 22f545b

Please sign in to comment.