|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +find_isar_core_lib() { |
| 4 | + local isar_core_path |
| 5 | + isar_core_path=$(find "${HOME}/.pub-cache/git" -type d -path "*/isar_core_ffi" -print -quit 2>/dev/null) |
| 6 | + [[ -z "${isar_core_path}" ]] && return 1 |
| 7 | + echo "${isar_core_path}" |
| 8 | +} |
| 9 | + |
| 10 | +detect_isar_version() { |
| 11 | + local version="unknown" |
| 12 | + local lock_file="${APP_PROJECT_ROOT_DIR}/pubspec.lock" |
| 13 | + [[ -f "${lock_file}" ]] && version=$(grep -A1 "isar_community:" "${lock_file}" 2>/dev/null | grep version | awk -F'"' '{print $2}' | head -n1) |
| 14 | + echo "${version:-3.3.0-dev.2}" |
| 15 | +} |
| 16 | + |
| 17 | +copy_isar_lib() { |
| 18 | + local lib_src="$1" |
| 19 | + local lib_dest="$2" |
| 20 | + |
| 21 | + if [[ ! -f "${lib_src}" ]]; then |
| 22 | + echo "Warning: libisar.so not found at ${lib_src}" |
| 23 | + return 1 |
| 24 | + fi |
| 25 | + |
| 26 | + mkdir -p "${lib_dest}" |
| 27 | + cp -f "${lib_src}" "${lib_dest}/" |
| 28 | + echo "Copied libisar.so to ${lib_dest}" |
| 29 | +} |
| 30 | + |
| 31 | +build_isar_core() { |
| 32 | + local isar_core_path="$1" |
| 33 | + local workspace_root="$2" |
| 34 | + |
| 35 | + echo "Building Isar core from: ${isar_core_path}" |
| 36 | + |
| 37 | + if [[ ! -f "${isar_core_path}/Cargo.toml" ]]; then |
| 38 | + echo "Error: Cargo.toml not found" >&2 |
| 39 | + return 1 |
| 40 | + fi |
| 41 | + |
| 42 | + if [[ -f "${workspace_root}/target/release/libisar.so" ]] || \ |
| 43 | + [[ -f "${workspace_root}/target/release/deps/libisar.so" ]]; then |
| 44 | + echo "Note: libisar.so already built, skipping build step" |
| 45 | + return 0 |
| 46 | + fi |
| 47 | + |
| 48 | + (cd "${isar_core_path}" && cargo build --release) || { |
| 49 | + echo "Error: cargo build failed for isar_core_ffi" >&2 |
| 50 | + return 1 |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +find_isar_library() { |
| 55 | + local workspace_root="$1" |
| 56 | + |
| 57 | + if [[ -f "${workspace_root}/target/release/libisar.so" ]]; then |
| 58 | + echo "${workspace_root}/target/release/libisar.so" |
| 59 | + return 0 |
| 60 | + fi |
| 61 | + |
| 62 | + if [[ -f "${workspace_root}/target/release/deps/libisar.so" ]]; then |
| 63 | + echo "${workspace_root}/target/release/deps/libisar.so" |
| 64 | + return 0 |
| 65 | + fi |
| 66 | + |
| 67 | + echo "Error: could not produce libisar.so" >&2 |
| 68 | + return 1 |
| 69 | +} |
| 70 | + |
| 71 | +build_isar_source() { |
| 72 | + echo "------------------------------------------------------------" |
| 73 | + echo "Building Isar database library from source (BUILD_ISAR_FROM_SOURCE=1)" |
| 74 | + echo "------------------------------------------------------------" |
| 75 | + |
| 76 | + local isar_core_path |
| 77 | + isar_core_path=$(find_isar_core_lib) || { |
| 78 | + echo "Error: could not locate isar_core_ffi inside ~/.pub-cache/git." |
| 79 | + return 1 |
| 80 | + } |
| 81 | + |
| 82 | + echo "Found isar_core_ffi at: ${isar_core_path}" |
| 83 | + |
| 84 | + local workspace_root=$(dirname $(dirname "${isar_core_path}")) |
| 85 | + |
| 86 | + build_isar_core "${isar_core_path}" "${workspace_root}" || return 1 |
| 87 | + |
| 88 | + local lib_src |
| 89 | + lib_src=$(find_isar_library "${workspace_root}") || return 1 |
| 90 | + |
| 91 | + local plugin_path="${APP_PROJECT_ROOT_DIR}/linux/flutter/ephemeral/.plugin_symlinks/isar_community_flutter_libs/linux" |
| 92 | + if [[ -d "$(dirname "${plugin_path}")" ]]; then |
| 93 | + copy_isar_lib "${lib_src}" "${plugin_path}" || return 1 |
| 94 | + fi |
| 95 | + |
| 96 | + local bundle_path="${APP_PROJECT_ROOT_DIR}/build/linux/x64/release/bundle/lib" |
| 97 | + if [[ -d "$(dirname "${bundle_path}")" ]]; then |
| 98 | + copy_isar_lib "${lib_src}" "${bundle_path}" || return 1 |
| 99 | + fi |
| 100 | +} |
0 commit comments