From 6e4c8dfa50bc9fecb6b1482f76c0a0f27bf03fb6 Mon Sep 17 00:00:00 2001 From: Chao Sun Date: Thu, 15 Feb 2024 13:24:39 -0800 Subject: [PATCH] build: Add CI for MacOS aarch64 --- .github/actions/setup-builder/action.yaml | 13 ++- .../actions/setup-macos-builder/action.yaml | 62 ++++++++++++++ .github/workflows/pr_build.yml | 81 +++++++++++++++++-- 3 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 .github/actions/setup-macos-builder/action.yaml diff --git a/.github/actions/setup-builder/action.yaml b/.github/actions/setup-builder/action.yaml index a4cd393d55..f518ed24f5 100644 --- a/.github/actions/setup-builder/action.yaml +++ b/.github/actions/setup-builder/action.yaml @@ -33,7 +33,18 @@ runs: shell: bash run: | apt-get update - apt-get install -y openjdk-${{inputs.jdk-version}}-jdk protobuf-compiler + apt-get install -y protobuf-compiler + + - name: Install JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'adopt' + java-version: '17' + + - name: Set JAVA_HOME + shell: bash + run: echo "JAVA_HOME=$(echo ${JAVA_HOME})" >> $GITHUB_ENV + - name: Setup Rust toolchain shell: bash # rustfmt is needed for the substrait build script diff --git a/.github/actions/setup-macos-builder/action.yaml b/.github/actions/setup-macos-builder/action.yaml new file mode 100644 index 0000000000..a850b10281 --- /dev/null +++ b/.github/actions/setup-macos-builder/action.yaml @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: Prepare Builder for MacOS +description: 'Prepare Build Environment' +inputs: + rust-version: + description: 'version of rust to install (e.g. nightly)' + required: true + default: 'nightly' + jdk-version: + description: 'jdk version to install (e.g., 17)' + required: true + default: '17' +runs: + using: "composite" + steps: + - name: Install Build Dependencies + shell: bash + run: | + # Install protobuf + mkdir -p $HOME/d/protoc + cd $HOME/d/protoc + export PROTO_ZIP="protoc-21.4-osx-aarch_64.zip" + curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.4/$PROTO_ZIP + unzip $PROTO_ZIP + echo "$HOME/d/protoc/bin" >> $GITHUB_PATH + export PATH=$PATH:$HOME/d/protoc/bin + + - name: Install JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'adopt' + java-version: '17' + architecture: 'aarch64' + + - name: Set JAVA_HOME + shell: bash + run: echo "JAVA_HOME=$(echo ${JAVA_HOME})" >> $GITHUB_ENV + + - name: Setup Rust toolchain + shell: bash + # rustfmt is needed for the substrait build script + run: | + echo "Installing ${{inputs.rust-version}}" + rustup toolchain install ${{inputs.rust-version}} + rustup default ${{inputs.rust-version}} + rustup component add rustfmt clippy diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml index da9346f2ba..94b23cc2b5 100644 --- a/.github/workflows/pr_build.yml +++ b/.github/workflows/pr_build.yml @@ -66,10 +66,6 @@ jobs: cd core cargo check --benches - - name: Setup JAVA_HOME - run: | - echo "JAVA_HOME=/usr/lib/jvm/java-${{env.JAVA_VERSION}}-openjdk-amd64" >> $GITHUB_ENV - - name: Cache Maven dependencies uses: actions/cache@v4 with: @@ -107,9 +103,82 @@ jobs: cd core cargo build - - name: Setup JAVA_HOME + - name: Cache Maven dependencies + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Run Maven compile run: | - echo "JAVA_HOME=/usr/lib/jvm/java-${{env.JAVA_VERSION}}-openjdk-amd64" >> $GITHUB_ENV + ./mvnw compile test-compile scalafix:scalafix -Psemanticdb + + - name: Run tests + run: | + SPARK_HOME=`pwd` ./mvnw clean install + + macos-aarch64-rust-test: + name: Rust test (macos-aarch64) + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust & Java toolchain + uses: ./.github/actions/setup-macos-builder + with: + rust-version: nightly + jdk-version: ${{env.JAVA_VERSION}} + + - name: Check cargo fmt + run: | + cd core + cargo fmt --all -- --check --color=never + + - name: Check cargo clippy + run: | + cd core + cargo clippy --color=never -- -D warnings + + - name: Check compilation + run: | + cd core + cargo check --benches + + - name: Cache Maven dependencies + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build common module (pre-requisite for Rust tests) + run: | + cd common + ../mvnw clean compile -DskipTests + + - name: Run cargo test + run: | + cd core + # This is required to run some JNI related tests on the Rust side + RUST_BACKTRACE=1 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/lib:$JAVA_HOME/lib/server cargo test + + macos-aarch64-java-test: + name: Java test (macos-aarch64) + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust & Java toolchain + uses: ./.github/actions/setup-macos-builder + with: + rust-version: nightly + jdk-version: ${{env.JAVA_VERSION}} + + - name: Run cargo build + run: | + cd core + cargo build - name: Cache Maven dependencies uses: actions/cache@v4