diff --git a/scripts/app_config/templates/configure_template_files.sh b/scripts/app_config/templates/configure_template_files.sh index b4731683d..24a4195cf 100755 --- a/scripts/app_config/templates/configure_template_files.sh +++ b/scripts/app_config/templates/configure_template_files.sh @@ -65,4 +65,9 @@ for TF in "${TEMPLATE_FILES[@]}"; do rm "${FILE}" fi cp -rp "${TEMPLATES_DIR}/${TF}" "${FILE}" -done \ No newline at end of file +done + +if [ "$BUILD_ISAR_FROM_SOURCE" -eq 1 ]; then + source "${APP_PROJECT_ROOT_DIR}/scripts/app_config/templates/isar_build.sh" + build_isar_source +fi diff --git a/scripts/app_config/templates/isar_build.sh b/scripts/app_config/templates/isar_build.sh new file mode 100644 index 000000000..d1d53d7f9 --- /dev/null +++ b/scripts/app_config/templates/isar_build.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +find_isar_core_lib() { + local isar_core_path + isar_core_path=$(find "${HOME}/.pub-cache/git" -type d -path "*/isar_core_ffi" -print -quit 2>/dev/null) + [[ -z "${isar_core_path}" ]] && return 1 + echo "${isar_core_path}" +} + +detect_isar_version() { + local version="unknown" + local lock_file="${APP_PROJECT_ROOT_DIR}/pubspec.lock" + [[ -f "${lock_file}" ]] && version=$(grep -A1 "isar_community:" "${lock_file}" 2>/dev/null | grep version | awk -F'"' '{print $2}' | head -n1) + echo "${version:-3.3.0-dev.2}" +} + +copy_isar_lib() { + local lib_src="$1" + local lib_dest="$2" + + if [[ ! -f "${lib_src}" ]]; then + echo "Warning: libisar.so not found at ${lib_src}" + return 1 + fi + + mkdir -p "${lib_dest}" + cp -f "${lib_src}" "${lib_dest}/" + echo "Copied libisar.so to ${lib_dest}" +} + +build_isar_core() { + local isar_core_path="$1" + local workspace_root="$2" + + echo "Building Isar core from: ${isar_core_path}" + + if [[ ! -f "${isar_core_path}/Cargo.toml" ]]; then + echo "Error: Cargo.toml not found" >&2 + return 1 + fi + + if [[ -f "${workspace_root}/target/release/libisar.so" ]] || \ + [[ -f "${workspace_root}/target/release/deps/libisar.so" ]]; then + echo "Note: libisar.so already built, skipping build step" + return 0 + fi + + (cd "${isar_core_path}" && cargo build --release) || { + echo "Error: cargo build failed for isar_core_ffi" >&2 + return 1 + } +} + +find_isar_library() { + local workspace_root="$1" + + if [[ -f "${workspace_root}/target/release/libisar.so" ]]; then + echo "${workspace_root}/target/release/libisar.so" + return 0 + fi + + if [[ -f "${workspace_root}/target/release/deps/libisar.so" ]]; then + echo "${workspace_root}/target/release/deps/libisar.so" + return 0 + fi + + echo "Error: could not produce libisar.so" >&2 + return 1 +} + +build_isar_source() { + echo "------------------------------------------------------------" + echo "Building Isar database library from source (BUILD_ISAR_FROM_SOURCE=1)" + echo "------------------------------------------------------------" + + local isar_core_path + isar_core_path=$(find_isar_core_lib) || { + echo "Error: could not locate isar_core_ffi inside ~/.pub-cache/git." + return 1 + } + + echo "Found isar_core_ffi at: ${isar_core_path}" + + local workspace_root=$(dirname $(dirname "${isar_core_path}")) + + build_isar_core "${isar_core_path}" "${workspace_root}" || return 1 + + local lib_src + lib_src=$(find_isar_library "${workspace_root}") || return 1 + + local plugin_path="${APP_PROJECT_ROOT_DIR}/linux/flutter/ephemeral/.plugin_symlinks/isar_community_flutter_libs/linux" + if [[ -d "$(dirname "${plugin_path}")" ]]; then + copy_isar_lib "${lib_src}" "${plugin_path}" || return 1 + fi + + local bundle_path="${APP_PROJECT_ROOT_DIR}/build/linux/x64/release/bundle/lib" + if [[ -d "$(dirname "${bundle_path}")" ]]; then + copy_isar_lib "${lib_src}" "${bundle_path}" || return 1 + fi +} diff --git a/scripts/app_config/templates/pubspec.template.yaml b/scripts/app_config/templates/pubspec.template.yaml index 564948796..a0212608e 100644 --- a/scripts/app_config/templates/pubspec.template.yaml +++ b/scripts/app_config/templates/pubspec.template.yaml @@ -318,6 +318,24 @@ dependency_overrides: pinenacl: ^0.6.0 http: ^0.13.0 +# %%ENABLE_ISAR%% +# isar_community: +# git: +# url: https://github.com/isar-community/isar-community.git +# path: packages/isar_community +# ref: 39ea19ff035518aef4d0e776206d96a428f57789 +# isar_community_flutter_libs: +# git: +# url: https://github.com/isar-community/isar-community.git +# path: packages/isar_community_flutter_libs +# ref: 39ea19ff035518aef4d0e776206d96a428f57789 +# isar_community_generator: +# git: +# url: https://github.com/isar-community/isar-community.git +# path: packages/isar_community_generator +# ref: 39ea19ff035518aef4d0e776206d96a428f57789 +# %%END_ENABLE_ISAR%% + # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/scripts/build_app.sh b/scripts/build_app.sh index fc56a2bc1..30bbc8215 100755 --- a/scripts/build_app.sh +++ b/scripts/build_app.sh @@ -9,7 +9,7 @@ APP_NAMED_IDS=("stack_wallet" "stack_duo" "campfire") # Function to display usage. usage() { - echo "Usage: $0 -v -b -p -a " + echo "Usage: $0 -v -b -p -a [-i] [-f]" exit 1 } @@ -33,15 +33,17 @@ unset -v APP_NAMED_ID # optional args (with defaults) BUILD_CRYPTO_PLUGINS=0 +BUILD_ISAR_FROM_SOURCE=0 # Parse command-line arguments. -while getopts "v:b:p:a:i" opt; do +while getopts "v:b:p:a:i:f" opt; do case "${opt}" in v) APP_VERSION_STRING="$OPTARG" ;; b) APP_BUILD_NUMBER="$OPTARG" ;; p) APP_BUILD_PLATFORM="$OPTARG" ;; a) APP_NAMED_ID="$OPTARG" ;; i) BUILD_CRYPTO_PLUGINS=1 ;; + f) BUILD_ISAR_FROM_SOURCE=1 ;; *) usage ;; esac done @@ -71,6 +73,8 @@ set -x source "${APP_PROJECT_ROOT_DIR}/scripts/app_config/templates/configure_template_files.sh" +export BUILD_ISAR_FROM_SOURCE + # checks for the correct platform dir and pushes it for later if printf '%s\0' "${APP_PLATFORMS[@]}" | grep -Fxqz -- "${APP_BUILD_PLATFORM}"; then pushd "${APP_PROJECT_ROOT_DIR}/scripts/${APP_BUILD_PLATFORM}"