Skip to content

Commit

Permalink
build: support building from aarch64 (#3807)
Browse files Browse the repository at this point in the history
* build: support building from aarch64

- include pre-compiled thirdparty and zetasql for aarch64
- fix python sdk naming under aarch64

* docs(compile): briefly introduce arm building
  • Loading branch information
aceforeverd authored Mar 22, 2024
1 parent 524dba1 commit 0a5fa74
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

FROM centos:7

ARG ZETASQL_VERSION=0.3.4-b0
ARG ZETASQL_VERSION=0.3.4
ARG THIRDPARTY_VERSION=0.7.0
ARG TARGETARCH

Expand Down
9 changes: 4 additions & 5 deletions docker/setup_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ if [[ "$ARCH" = "x86_64" ]]; then
curl -Lo zetasql.tar.gz "https://github.com/4paradigm/zetasql/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-x86_64-centos.tar.gz" && \
echo "downloaed zetasql.tar.gz version $ZETASQL_VERSION for $ARCH"
elif [[ "$ARCH" = "aarch64" ]]; then
# NOTE(aceforeverd): thirdparty for arm is out-of-date
curl -Lo thirdparty.tar.gz https://github.com/4paradigm/hybridsql-asserts/releases/download/v0.4.0/thirdparty-2021-08-03-linux-gnu-aarch64.tar.gz && \
echo "downloaded thirdparty.tar.gz version 0.4.0 for $ARCH"
curl -Lo zetasql.tar.gz "https://github.com/4paradigm/zetasql/releases/download/v0.2.6/libzetasql-0.2.6-linux-gnu-aarch64-centos.tar.gz" && \
echo "downloaed zetasql.tar.gz for version 0.2.6 $ARCH"
curl -Lo thirdparty.tar.gz "https://github.com/4paradigm/hybridsql-asserts/releases/download/v${THIRDPARTY_VERSION}/thirdparty-${THIRDPARTY_VERSION}-linux-gnu-${ARCH}.tar.gz" && \
echo "downloaded thirdparty.tar.gz version $THIRDPARTY_VERSION for $ARCH"
curl -Lo zetasql.tar.gz "https://github.com/4paradigm/zetasql/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-${ARCH}.tar.gz" && \
echo "downloaed zetasql.tar.gz version $ZETASQL_VERSION for $ARCH"
else
echo "no pre-compiled deps for arch=$ARCH"
exit 1
Expand Down
28 changes: 28 additions & 0 deletions docs/en/deploy/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,34 @@ After forking the OpenMLDB repository, you can trigger the `Other OS Build` work

Please note that this compilation process involves building third-party dependencies from source code, and it may take a while to complete due to limited resources. The approximate time for this process is around 3 hours and 5 minutes (2 hours for third-party dependencies and 1 hour for OpenMLDB). However, the workflow caches the compilation output for third-party dependencies, so the second compilation will be much faster, taking approximately 1 hour and 15 minutes for OpenMLDB.

### Linux for ARM64

It's possible to run OpenMLDB on Linux for ARM64(AArch64), which you may compile the source from scratch. ARM version of compile image `ghcr.io/4paradigm/hybridsql` is recommended:

```sh
docker run -it ghcr.io/4paradigm/hybridsql:latest

# inside docker container
git clone https://github.com/4paradigm/OpenMLDB
cd OpenMLDB

# necessary deps for all third-party
yum install -y flex autoconf automake unzip bc expect libtool \
rh-python38-python-devel gettext byacc xz tcl cppunit-devel rh-python38-python-wheel patch java-1.8.0-openjdk-devel
# bazel
curl --create-dirs -SLo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-arm64
chmod +x /usr/local/bin/bazel

# third-party
cmake -S third-party -B .deps -DBUILD_BUNDELD=ON -DMAKEOPTS=-j$(nproc)
cmake --build .deps

# OpenMLDB source
cmake -S . -B build -DCMKAE_PREFIX_PATH=$(pwd)/.deps/usr -DSQL_JAVASDK_ENABLE=ON -DSQL_PYSDK_ENABLE=ON
cmake --build build -- -j$(nproc)
```


### Macos 10.15, 11

MacOS doesn't require compiling third-party dependencies from source code, so compilation is relatively faster, taking about 1 hour and 15 minutes. Local compilation is similar to the steps outlined in the [Detailed Instructions for Build](#detailed-instructions-for-build) and does not require compiling third-party dependencies (`BUILD_BUNDLED=OFF`). For cloud compilation on macOS, trigger the `Other OS Build` workflow in `Actions` with the specified macOS version (`os name` as `macos10` or `macos11`). You can also disable Java or Python SDK compilation if they are not needed, by setting `java sdk enable` or `python sdk enable` to `OFF`.
Expand Down
28 changes: 28 additions & 0 deletions docs/zh/deploy/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ Fork OpenMLDB仓库后,可以使用在`Actions`中触发workflow `Other OS Bui
此编译流程需要从源码编译thirdparty,且资源较少,无法开启较高的并发编译。因此编译时间较长,大约需要3h5m(2h thirdparty+1h OpenMLDB)。workflow会缓存thirdparty的编译产出,因此第二次编译会快很多(1h15m OpenMLDB)。
### Linux for ARM64
支持在 AArch64 架构的 Linux 系统上编译, 建议选择编译镜像 `ghcr.io/4paradigm/hybridsql` 在容器内编译. 在容器内:
```sh
# 建议在编译镜像内进行
docker run -it ghcr.io/4paradigm/hybridsql:latest
# inside docker container
git clone https://github.com/4paradigm/OpenMLDB
cd OpenMLDB
# 安装 third-party 编译 deps
yum install -y flex autoconf automake unzip bc expect libtool \
rh-python38-python-devel gettext byacc xz tcl cppunit-devel rh-python38-python-wheel patch java-1.8.0-openjdk-devel
# bazel
curl --create-dirs -SLo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-arm64
chmod +x /usr/local/bin/bazel
# third-party
cmake -S third-party -B .deps -DBUILD_BUNDELD=ON -DMAKEOPTS=-j$(nproc)
cmake --build .deps
# OpenMLDB source
cmake -S . -B build -DCMKAE_PREFIX_PATH=$(pwd)/.deps/usr -DSQL_JAVASDK_ENABLE=ON -DSQL_PYSDK_ENABLE=ON
cmake --build build -- -j$(nproc)
```
### Macos 10.15, 11
Macos适配不需要从源码编译thirdparty,所以云编译耗时不会太长,大约1h15m。本地编译与[从源码全量编译](#从源码全量编译)章节相同,无需编译thirdparty(`BUILD_BUNDLED=OFF`)。云编译需要在`Actions`中触发workflow `Other OS Build`,编译产出在`Actions`的`Artifacts`中。workflow 配置 `os name`为`macos10`/`macos11`,同样可配置`java sdk enable`或`python sdk enable`为`OFF`。
13 changes: 12 additions & 1 deletion src/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ if(SQL_PYSDK_ENABLE)
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:sql_router_sdk> ${PROJECT_SOURCE_DIR}/python/openmldb_sdk/openmldb/native/
COMMAND echo "Do not strip library for MacOS, refer to https://github.com/4paradigm/OpenMLDB/issues/905")
else()
set(PYTHON_PLATFORM manylinux1_x86_64)
# ref https://peps.python.org/pep-0600/
# centos7 is glibc 2.17, so 'manylinux2014' should preferred,
# 'manylinux2014' is just legacy alias 'manylinux_2_17', we keep this legacy name
# since there still installation issue on python 3.8 for new the name.
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64)|(x86_64)")
set(PYTHON_PLATFORM manylinux1_x86_64)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)")
set(PYTHON_PLATFORM manylinux2014_aarch64)
else()
message(FATAL_ERROR "unsupported architecture ${CMAKE_SYSTEM_PROCESSOR}")
endif()

add_custom_target(strip_python_so ALL DEPENDS sql_router_sdk
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:sql_router_sdk> ${PROJECT_SOURCE_DIR}/python/openmldb_sdk/openmldb/native/
COMMAND strip ${PROJECT_SOURCE_DIR}/python/openmldb_sdk/openmldb/native/_sql_router_sdk.so)
Expand Down
5 changes: 2 additions & 3 deletions third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ function(init_hybridsql_thirdparty_urls)
get_linux_lsb_release_information()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)")
# NOTE(#1138): pre-compiled thirdparty is out-of-date
set(HYBRIDSQL_ASSERTS_URL "https://github.com/4paradigm/hybridsql-asserts/releases/download/v0.4.0/thirdparty-2021-08-03-linux-gnu-aarch64.tar.gz" PARENT_SCOPE)
set(HYBRIDSQL_ASSERTS_HASH 128e2147903c6b4f5649284326c60ba048ff369f2925f9957f2973a515c65d75 PARENT_SCOPE)
set(HYBRIDSQL_ASSERTS_URL "${HYBRIDSQL_ASSERTS_HOME}/releases/download/v${HYBRIDSQL_ASSERTS_VERSION}/thirdparty-${HYBRIDSQL_ASSERTS_VERSION}-linux-gnu-aarch64.tar.gz" PARENT_SCOPE)
set(HYBRIDSQL_ASSERTS_HASH 323ca51573b46bb71b781a1a10a91a4112559fa54c18ae2d7bacc7e342f49f3d PARENT_SCOPE)
else()
if (LSB_RELEASE_ID_SHORT STREQUAL "centos")
set(HYBRIDSQL_ASSERTS_URL "${HYBRIDSQL_ASSERTS_HOME}/releases/download/v${HYBRIDSQL_ASSERTS_VERSION}/thirdparty-${HYBRIDSQL_ASSERTS_VERSION}-linux-gnu-x86_64-centos.tar.gz" PARENT_SCOPE)
Expand Down
11 changes: 11 additions & 0 deletions third-party/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ The pre-compiled thirdparty for Linux is built on Centos7 with gcc8, and macOS i
- make, autoreconf
- pkg-config


For Debian:
```sh
sudo apt-get install bison python3-dev libcppunit-dev build-essential cmake autoconf tcl pkg-config git curl patch libtool-bin unzip
# ensure python3 is the default, you may skip if it already is
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100

curl --create-dirs -SLo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64
chmod +x /usr/local/bin/bazel
```

### Build thirdparty

```bash
Expand Down
17 changes: 10 additions & 7 deletions third-party/cmake/FetchZetasql.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
# limitations under the License.

set(ZETASQL_HOME https://github.com/4paradigm/zetasql)
set(ZETASQL_VERSION 0.3.4-b0)
set(ZETASQL_HASH_DARWIN 0cd74b469396f877751cf7efd39685cc4fc544608aef4a901f3f640c3d8aa947)
set(ZETASQL_HASH_LINUX_UBUNTU f94e97ad0b70b34d876cd3820f64756a164b061f3cb40a089e179f2997995bdc)
set(ZETASQL_HASH_LINUX_CENTOS 8e853c4dd9b6638092357fa250ee29e634a1bc8b85ab8c829fbafac1b43ee8b8)
set(ZETASQL_VERSION 0.3.4)
set(ZETASQL_HASH_DARWIN a8d18f1595fa6a78d09c5feca813e9a332cd4d156a95124165f7c1a1ebcb86b2)
set(ZETASQL_HASH_LINUX_UBUNTU 11988ad45de027566386a8e832e7385755f9367d78243b8d2aa6ef3493c0ee3d)
set(ZETASQL_HASH_LINUX_CENTOS 92c9eb4d1ffb7d96fcb33150366906c52f27db4cf8dfb442c06e5fe5c738cd4a)
set(ZETASQL_HASH_LINUX_AARCH64 e20e03938ec108b1c08203c238841ae781498dd66c5d791f4ecc326440287cdb)
set(ZETASQL_TAG v${ZETASQL_VERSION})

function(init_zetasql_urls)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
get_linux_lsb_release_information()

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)")
set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-aarch64.tar.gz" PARENT_SCOPE)
set(ZETASQL_HASH ${ZETASQL_HASH_LINUX_AARCH64} PARENT_SCOPE)
endif()

if (LSB_RELEASE_ID_SHORT STREQUAL "centos")
set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-x86_64-centos.tar.gz" PARENT_SCOPE)
set(ZETASQL_HASH ${ZETASQL_HASH_LINUX_CENTOS} PARENT_SCOPE)
Expand All @@ -42,9 +48,6 @@ endfunction()
if (NOT BUILD_BUNDLED_ZETASQL)
init_zetasql_urls()

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)")
message(FATAL_ERROR "pre-compiled zetasql for arm64 not available, try compile zetasql from source by cmake flag: '-DBUILD_BUNDLED_ZETASQL=ON'")
endif()
message(STATUS "Download pre-compiled zetasql from ${ZETASQL_URL}")
# download pre-compiled zetasql from GitHub Release
ExternalProject_Add(zetasql
Expand Down

0 comments on commit 0a5fa74

Please sign in to comment.