|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +# Build and install flatc (the FlatBuffers compiler) at the version Vortex requires, and make sure |
| 19 | +# libclang is present. |
| 20 | +# |
| 21 | +# Vortex compiles its FlatBuffers schemas (.fbs) into Rust at build time, and |
| 22 | +# cmake_modules/ThirdpartyToolchain.cmake requires a flatc whose version matches Vortex's |
| 23 | +# flatbuffers crate (find_program(... flatc REQUIRED)). Distribution packages are too old, so the |
| 24 | +# pinned version is built from source. Separately, Vortex's native dependencies run bindgen in |
| 25 | +# their build scripts, which needs libclang at build time; some CI images do not ship it. |
| 26 | +# flatc and libclang are build-time tools only; neither is needed at runtime. |
| 27 | +# |
| 28 | +# The dev container (see .devcontainer/) already has these preinstalled; this script is for the |
| 29 | +# GitHub Actions runners and is called before ci/scripts/build_paimon.sh. |
| 30 | +# |
| 31 | +# Idempotent: a no-op when a matching flatc is already on PATH and libclang is already present. |
| 32 | + |
| 33 | +set -eux |
| 34 | + |
| 35 | +# Must match the flatbuffers crate version pinned by Vortex (see its Cargo.lock). |
| 36 | +FLATBUFFERS_VERSION=${FLATBUFFERS_VERSION:-25.12.19} |
| 37 | +FLATC_INSTALL_DIR=${FLATC_INSTALL_DIR:-"${HOME}/.local/bin"} |
| 38 | + |
| 39 | +# Vortex's native dependencies invoke bindgen in their build scripts, which loads libclang at |
| 40 | +# build time. Images that only carry GCC (e.g. the gcc8 test container) may lack it. |
| 41 | +if ! ldconfig -p 2>/dev/null | grep -q 'libclang'; then |
| 42 | + if [[ "$(id -u)" -ne 0 ]] && command -v sudo >/dev/null 2>&1; then |
| 43 | + apt_prefix="sudo" |
| 44 | + else |
| 45 | + apt_prefix="" |
| 46 | + fi |
| 47 | + ${apt_prefix} apt-get update -y |
| 48 | + ${apt_prefix} apt-get install -y libclang-dev |
| 49 | +fi |
| 50 | + |
| 51 | +# Skip when a matching flatc is already available. |
| 52 | +if command -v flatc >/dev/null 2>&1 && |
| 53 | + [[ "$(flatc --version 2>/dev/null | awk '{print $NF}')" == "${FLATBUFFERS_VERSION}" ]]; then |
| 54 | + flatc --version |
| 55 | + exit 0 |
| 56 | +fi |
| 57 | + |
| 58 | +workdir="$(mktemp -d)" |
| 59 | +trap 'rm -rf "${workdir}"' EXIT |
| 60 | + |
| 61 | +git clone --depth 1 --branch "v${FLATBUFFERS_VERSION}" \ |
| 62 | + https://github.com/google/flatbuffers.git "${workdir}/flatbuffers" |
| 63 | +cmake -S "${workdir}/flatbuffers" -B "${workdir}/build" \ |
| 64 | + -DCMAKE_BUILD_TYPE=Release \ |
| 65 | + -DFLATBUFFERS_BUILD_TESTS=OFF |
| 66 | +cmake --build "${workdir}/build" --target flatc -j "$(nproc)" |
| 67 | + |
| 68 | +mkdir -p "${FLATC_INSTALL_DIR}" |
| 69 | +install -m 0755 "${workdir}/build/flatc" "${FLATC_INSTALL_DIR}/flatc" |
| 70 | + |
| 71 | +# Make flatc discoverable by later steps: on PATH for find_program, and via FLATC for build_vortex. |
| 72 | +export PATH="${FLATC_INSTALL_DIR}:${PATH}" |
| 73 | +echo "${FLATC_INSTALL_DIR}" >>"${GITHUB_PATH:-/dev/null}" || true |
| 74 | +echo "FLATC=${FLATC_INSTALL_DIR}/flatc" >>"${GITHUB_ENV:-/dev/null}" || true |
| 75 | + |
| 76 | +"${FLATC_INSTALL_DIR}/flatc" --version |
0 commit comments