187 lines
6.7 KiB
YAML
187 lines
6.7 KiB
YAML
name: Build & Test
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUSTFLAGS: "-D warnings"
|
|
CROSS_DEBUG: 1
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
inputs:
|
|
ref:
|
|
default: ${{ github.ref }}
|
|
type: string
|
|
|
|
jobs:
|
|
build:
|
|
name: ${{ matrix.runtime }} (${{ matrix.target }}) (${{ matrix.os }})
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
runtime:
|
|
- linux-aarch64 #
|
|
- linux-arm #
|
|
- linux-x64 #
|
|
- linux-x86 #
|
|
- windows-x64 # <-- No C library build - requires an additional adapted Makefile for `cl.exe` compiler
|
|
- windows-x86 # -- // --
|
|
- macos-arm64 # <-- MacOS M1/M2 - no tests, only CLI build to be published on release artifacts
|
|
- macos-x64 #
|
|
|
|
include:
|
|
- { runtime: linux-aarch64 , target: aarch64-unknown-linux-gnu , os: ubuntu-latest , use-cross: true }
|
|
- { runtime: linux-arm , target: arm-unknown-linux-gnueabihf , os: ubuntu-latest , use-cross: true }
|
|
- { runtime: linux-x64 , target: x86_64-unknown-linux-gnu , os: ubuntu-latest }
|
|
- { runtime: linux-x86 , target: i686-unknown-linux-gnu , os: ubuntu-latest , use-cross: true }
|
|
- { runtime: windows-x64 , target: x86_64-pc-windows-msvc , os: windows-latest }
|
|
- { runtime: windows-x86 , target: i686-pc-windows-msvc , os: windows-latest }
|
|
- { runtime: macos-arm64 , target: aarch64-apple-darwin , os: macos-latest }
|
|
- { runtime: macos-x64 , target: x86_64-apple-darwin , os: macos-latest }
|
|
|
|
# Cross compilers for C library
|
|
- { runtime: linux-aarch64 , cc: aarch64-linux-gnu-gcc , ar: aarch64-linux-gnu-ar }
|
|
- { runtime: linux-arm , cc: arm-unknown-linux-gnueabihf-gcc , ar: arm-unknown-linux-gnueabihf-gcc-ar }
|
|
- { runtime: linux-x86 , cc: i686-linux-gnu-gcc , ar: i686-linux-gnu-ar }
|
|
|
|
# See #2041 tree-sitter issue
|
|
- { runtime: windows-x64 , rust_test_threads: 1 }
|
|
- { runtime: windows-x86 , rust_test_threads: 1 }
|
|
|
|
env:
|
|
BUILD_CMD: cargo
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
|
|
steps:
|
|
- name: Checkout source code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: ${{ inputs.ref }}
|
|
|
|
- name: Read Emscripten version
|
|
run: |
|
|
echo "EMSCRIPTEN_VERSION=$(cat cli/emscripten-version)" >> $GITHUB_ENV
|
|
|
|
- name: Install Emscripten
|
|
uses: mymindstorm/setup-emsdk@v12
|
|
with:
|
|
version: ${{ env.EMSCRIPTEN_VERSION }}
|
|
|
|
- name: Install Rust toolchain
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
targets: ${{ matrix.target }}
|
|
|
|
- name: Install cross
|
|
if: matrix.use-cross
|
|
uses: taiki-e/install-action@v2
|
|
with:
|
|
tool: cross
|
|
|
|
- name: Build custom cross image
|
|
if: ${{ matrix.use-cross && matrix.os == 'ubuntu-latest' }}
|
|
run: |
|
|
cd ..
|
|
|
|
target="${{ matrix.target }}"
|
|
image=ghcr.io/cross-rs/$target:custom
|
|
echo "CROSS_IMAGE=$image" >> $GITHUB_ENV
|
|
|
|
echo "[target.$target]" >> Cross.toml
|
|
echo "image = \"$image\"" >> Cross.toml
|
|
echo "CROSS_CONFIG=$PWD/Cross.toml" >> $GITHUB_ENV
|
|
|
|
echo "FROM ghcr.io/cross-rs/$target:edge" >> Dockerfile
|
|
echo "ENV DEBIAN_FRONTEND=noninteractive" >> Dockerfile
|
|
echo "RUN apt-get update && apt-get install -y nodejs" >> Dockerfile
|
|
docker build -t $image .
|
|
docker images
|
|
docker run --rm $image env
|
|
|
|
cd -
|
|
|
|
- name: Setup env extras
|
|
env:
|
|
RUST_TEST_THREADS: ${{ matrix.rust_test_threads }}
|
|
USE_CROSS: ${{ matrix.use-cross }}
|
|
CC: ${{ matrix.cc }}
|
|
AR: ${{ matrix.ar }}
|
|
run: |
|
|
PATH="$PWD/.github/scripts:$PATH"
|
|
echo "PATH=$PATH" >> $GITHUB_ENV
|
|
echo "ROOT=$PWD" >> $GITHUB_ENV
|
|
echo "TREE_SITTER=tree-sitter.sh" >> $GITHUB_ENV
|
|
|
|
export TARGET=${{ matrix.target }}
|
|
echo "TARGET=$TARGET" >> $GITHUB_ENV
|
|
|
|
[ -n "$RUST_TEST_THREADS" ] && \
|
|
echo "RUST_TEST_THREADS=$RUST_TEST_THREADS" >> $GITHUB_ENV
|
|
|
|
[ -n "$CC" ] && echo "CC=$CC" >> $GITHUB_ENV
|
|
[ -n "$AR" ] && echo "AR=$AR" >> $GITHUB_ENV
|
|
|
|
if [ "$USE_CROSS" == "true" ]; then
|
|
echo "BUILD_CMD=cross" >> $GITHUB_ENV
|
|
export CROSS=1; echo "CROSS=1" >> $GITHUB_ENV
|
|
runner=$(cross.sh bash -c "env | sed -nr '/^CARGO_TARGET_.*_RUNNER=/s///p'")
|
|
[ -n "$runner" ] && echo "CROSS_RUNNER=$runner" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Build C library
|
|
if: ${{ !contains(matrix.os, 'windows') }} # Requires an additional adapted Makefile for `cl.exe` compiler
|
|
run: make.sh CFLAGS="-Werror" -j
|
|
|
|
- name: Build wasm library
|
|
if: ${{ !matrix.use-cross && matrix.runtime != 'macos-arm64' }} # Not used
|
|
run: script/build-wasm
|
|
|
|
- name: Build CLI
|
|
run: $BUILD_CMD build --release --target=${{ matrix.target }}
|
|
|
|
- name: Fetch fixtures
|
|
if: ${{ matrix.runtime != 'macos-arm64' }} # Not used
|
|
run: script/fetch-fixtures
|
|
|
|
- name: Generate fixtures
|
|
if: ${{ matrix.runtime != 'macos-arm64' }} # Can't natively run CLI on runner's host
|
|
run: script/generate-fixtures
|
|
|
|
- name: Generate WASM fixtures
|
|
if: ${{ !matrix.use-cross && matrix.runtime != 'macos-arm64' }} # Not used
|
|
run: script/generate-fixtures-wasm
|
|
|
|
- name: Run main tests
|
|
if: ${{ matrix.runtime != 'macos-arm64' }} # Can't natively run CLI on runner's host
|
|
run: $BUILD_CMD test --target=${{ matrix.target }}
|
|
|
|
- name: Run wasm tests
|
|
if: ${{ !matrix.use-cross && matrix.runtime != 'macos-arm64' }} # Not used
|
|
run: script/test-wasm
|
|
|
|
- name: Run benchmarks
|
|
if: ${{ !matrix.use-cross && matrix.runtime != 'macos-arm64' }} # Cross-compiled benchmarks make no sense
|
|
run: $BUILD_CMD bench benchmark -p tree-sitter-cli --target=${{ matrix.target }}
|
|
|
|
- name: Upload CLI artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: tree-sitter.${{ matrix.runtime }}
|
|
path: target/${{ matrix.target }}/release/tree-sitter${{ contains(matrix.target, 'windows') && '.exe' || '' }}
|
|
if-no-files-found: error
|
|
retention-days: 7
|
|
|
|
- name: Upload WASM artifacts
|
|
if: ${{ matrix.runtime == 'linux-x64' }}
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: tree-sitter.wasm
|
|
path: |
|
|
lib/binding_web/tree-sitter.js
|
|
lib/binding_web/tree-sitter.wasm
|
|
if-no-files-found: error
|
|
retention-days: 7
|