|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +SOURCE_DIR="${SOURCE_DIR:-/source}" |
| 5 | +if [ ! -d "$SOURCE_DIR" ]; then |
| 6 | + SOURCE_DIR=$(dirname "$(realpath "$0")")/.. |
| 7 | + SOURCE_DIR=$(realpath "$SOURCE_DIR") |
| 8 | +fi |
| 9 | + |
| 10 | +OUTPUT_DIR="${1:-build-deb}" |
| 11 | + |
| 12 | +cd "$SOURCE_DIR" |
| 13 | +mkdir -p "$OUTPUT_DIR" |
| 14 | +OUTPUT_DIR=$(realpath "$OUTPUT_DIR") |
| 15 | + |
| 16 | +export DEBIAN_FRONTEND=noninteractive |
| 17 | +export CCACHE_DIR="${CCACHE_DIR:-/root/.ccache}" |
| 18 | +mkdir -p "$CCACHE_DIR" |
| 19 | + |
| 20 | +if [ "${YDB_DEB_INSTALL_DEPS:-1}" = "1" ]; then |
| 21 | + apt-get update |
| 22 | + apt-get install -y --no-install-recommends \ |
| 23 | + build-essential \ |
| 24 | + ccache \ |
| 25 | + cmake \ |
| 26 | + pkg-config \ |
| 27 | + git \ |
| 28 | + libidn11-dev \ |
| 29 | + libssl-dev \ |
| 30 | + zlib1g-dev \ |
| 31 | + libprotobuf-dev \ |
| 32 | + protobuf-compiler \ |
| 33 | + libgrpc++-dev \ |
| 34 | + protobuf-compiler-grpc \ |
| 35 | + libbrotli-dev \ |
| 36 | + liblz4-dev \ |
| 37 | + libzstd-dev \ |
| 38 | + libbz2-dev \ |
| 39 | + libxxhash-dev \ |
| 40 | + libsnappy-dev \ |
| 41 | + libdouble-conversion-dev \ |
| 42 | + libgtest-dev \ |
| 43 | + libre2-dev \ |
| 44 | + libc-ares-dev \ |
| 45 | + rapidjson-dev \ |
| 46 | + python3 \ |
| 47 | + python3-six \ |
| 48 | + ragel \ |
| 49 | + yasm |
| 50 | +fi |
| 51 | + |
| 52 | +touch_existing_sources() { |
| 53 | + for path in "$@"; do |
| 54 | + if [ -e "$path" ]; then |
| 55 | + find "$path" -type f -exec touch {} + |
| 56 | + fi |
| 57 | + done |
| 58 | +} |
| 59 | + |
| 60 | +rm -f build_googleapis_deb/*.deb build-deb/*.deb "$OUTPUT_DIR"/*.deb 2>/dev/null || true |
| 61 | + |
| 62 | +if command -v ccache >/dev/null 2>&1; then |
| 63 | + ccache --zero-stats >/dev/null || true |
| 64 | + CMAKE_COMPILER_LAUNCHER_ARGS=( |
| 65 | + -DCMAKE_C_COMPILER_LAUNCHER=ccache |
| 66 | + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache |
| 67 | + ) |
| 68 | +else |
| 69 | + CMAKE_COMPILER_LAUNCHER_ARGS=() |
| 70 | +fi |
| 71 | + |
| 72 | +# Restored build-cache archives can have outputs newer than the checkout. |
| 73 | +# Touch package inputs so the incremental build cannot hide source changes. |
| 74 | +touch_existing_sources scripts/googleapis_deb third_party/api-common-protos |
| 75 | +cmake -S scripts/googleapis_deb -B build_googleapis_deb \ |
| 76 | + -DCMAKE_INSTALL_PREFIX=/usr/share/yandex \ |
| 77 | + "${CMAKE_COMPILER_LAUNCHER_ARGS[@]}" |
| 78 | +cmake --build build_googleapis_deb -j"$(nproc)" |
| 79 | +cmake --build build_googleapis_deb --target package |
| 80 | +dpkg -i build_googleapis_deb/*.deb |
| 81 | + |
| 82 | +./scripts/generate-debian-directory.sh |
| 83 | + |
| 84 | +touch_existing_sources \ |
| 85 | + CMakeLists.txt \ |
| 86 | + cmake \ |
| 87 | + contrib \ |
| 88 | + include \ |
| 89 | + library \ |
| 90 | + plugins \ |
| 91 | + scripts/build_cpack_deb_packages.sh \ |
| 92 | + scripts/generate-debian-directory.sh \ |
| 93 | + src \ |
| 94 | + third_party \ |
| 95 | + tools \ |
| 96 | + util |
| 97 | + |
| 98 | +cmake -S . -B build-deb \ |
| 99 | + -DCMAKE_BUILD_TYPE=Release \ |
| 100 | + -DYDB_SDK_INSTALL=ON \ |
| 101 | + -DYDB_SDK_EXAMPLES=OFF \ |
| 102 | + -DYDB_SDK_TESTS=OFF \ |
| 103 | + -DYDB_SDK_ENABLE_OTEL_METRICS=ON \ |
| 104 | + -DYDB_SDK_ENABLE_OTEL_TRACE=ON \ |
| 105 | + -DBUILD_SHARED_LIBS=OFF \ |
| 106 | + -DYDB_SDK_USE_SYSTEM_GOOGLEAPIS=ON \ |
| 107 | + -DCMAKE_INSTALL_PREFIX=/usr/share/yandex \ |
| 108 | + -DCMAKE_PREFIX_PATH="/usr/share/yandex" \ |
| 109 | + "${CMAKE_COMPILER_LAUNCHER_ARGS[@]}" |
| 110 | +cmake --build build-deb --target package -j"$(nproc)" |
| 111 | + |
| 112 | +cp -f build_googleapis_deb/*.deb "$OUTPUT_DIR"/ |
| 113 | +if [ "$(realpath build-deb)" != "$OUTPUT_DIR" ]; then |
| 114 | + cp -f build-deb/*.deb "$OUTPUT_DIR"/ |
| 115 | +fi |
| 116 | + |
| 117 | +if command -v ccache >/dev/null 2>&1; then |
| 118 | + ccache --show-stats || true |
| 119 | +fi |
| 120 | + |
| 121 | +chmod -R a+rwX "$CCACHE_DIR" build_googleapis_deb build-deb "$OUTPUT_DIR" debian 2>/dev/null || true |
| 122 | +ls -la "$OUTPUT_DIR" |
0 commit comments