Skip to content

Commit 5dc6814

Browse files
committed
Add optional flag to build Isar from source.
1 parent 086eb30 commit 5dc6814

File tree

4 files changed

+147
-3
lines changed

4 files changed

+147
-3
lines changed

scripts/app_config/templates/configure_template_files.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ for TF in "${TEMPLATE_FILES[@]}"; do
6565
rm "${FILE}"
6666
fi
6767
cp -rp "${TEMPLATES_DIR}/${TF}" "${FILE}"
68-
done
68+
done
69+
70+
if [ "$BUILD_ISAR_FROM_SOURCE" -eq 1 ]; then
71+
source "${APP_PROJECT_ROOT_DIR}/scripts/app_config/templates/isar_build.sh"
72+
build_isar_source
73+
fi
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
enable_isar_source_build() {
72+
local isar_version="$1"
73+
local git_ref="${isar_version#v}"
74+
75+
git_ref=$(printf '%s\n' "${git_ref}" | sed -e 's:[\/&]:\\&:g')
76+
77+
echo "Enabling Isar source build section in pubspec.yaml (ref: ${git_ref})"
78+
79+
dart "${APP_PROJECT_ROOT_DIR}/tool/process_pubspec_deps.dart" "${ACTUAL_PUBSPEC}" ISAR
80+
81+
if [[ "$(uname)" == 'Darwin' ]]; then
82+
sed -i '' -E "/(isar_community|isar_community_flutter_libs|isar_community_generator)/,+3 s|(ref:).*|\1 ${git_ref}|" "${ACTUAL_PUBSPEC}"
83+
else
84+
sed -i -E "/(isar_community|isar_community_flutter_libs|isar_community_generator)/,+3 s|(ref:).*|\1 ${git_ref}|" "${ACTUAL_PUBSPEC}"
85+
fi
86+
}
87+
88+
build_isar_source() {
89+
echo "------------------------------------------------------------"
90+
echo "Building Isar database library from source (BUILD_ISAR_FROM_SOURCE=1)"
91+
echo "------------------------------------------------------------"
92+
93+
local isar_core_path
94+
isar_core_path=$(find_isar_core_lib) || {
95+
echo "Error: could not locate isar_core_ffi inside ~/.pub-cache/git."
96+
return 1
97+
}
98+
99+
echo "Found isar_core_ffi at: ${isar_core_path}"
100+
101+
local workspace_root=$(dirname $(dirname "${isar_core_path}"))
102+
103+
build_isar_core "${isar_core_path}" "${workspace_root}" || return 1
104+
105+
local lib_src
106+
lib_src=$(find_isar_library "${workspace_root}") || return 1
107+
108+
local plugin_path="${APP_PROJECT_ROOT_DIR}/linux/flutter/ephemeral/.plugin_symlinks/isar_community_flutter_libs/linux"
109+
if [[ -d "$(dirname "${plugin_path}")" ]]; then
110+
copy_isar_lib "${lib_src}" "${plugin_path}" || return 1
111+
fi
112+
113+
local bundle_path="${APP_PROJECT_ROOT_DIR}/build/linux/x64/release/bundle/lib"
114+
if [[ -d "$(dirname "${bundle_path}")" ]]; then
115+
copy_isar_lib "${lib_src}" "${bundle_path}" || return 1
116+
fi
117+
}

scripts/app_config/templates/pubspec.template.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@ dependency_overrides:
318318
pinenacl: ^0.6.0
319319
http: ^0.13.0
320320

321+
# %%ENABLE_ISAR%%
322+
# isar_community:
323+
# git:
324+
# url: https://github.com/isar-community/isar-community.git
325+
# path: packages/isar_community
326+
# ref: 39ea19ff035518aef4d0e776206d96a428f57789
327+
# isar_community_flutter_libs:
328+
# git:
329+
# url: https://github.com/isar-community/isar-community.git
330+
# path: packages/isar_community_flutter_libs
331+
# ref: 39ea19ff035518aef4d0e776206d96a428f57789
332+
# isar_community_generator:
333+
# git:
334+
# url: https://github.com/isar-community/isar-community.git
335+
# path: packages/isar_community_generator
336+
# ref: 39ea19ff035518aef4d0e776206d96a428f57789
337+
# %%END_ENABLE_ISAR%%
338+
321339
# For information on the generic Dart part of this file, see the
322340
# following page: https://dart.dev/tools/pub/pubspec
323341

scripts/build_app.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ APP_NAMED_IDS=("stack_wallet" "stack_duo" "campfire")
99

1010
# Function to display usage.
1111
usage() {
12-
echo "Usage: $0 -v <version> -b <build_number> -p <platform> -a <app>"
12+
echo "Usage: $0 -v <version> -b <build_number> -p <platform> -a <app> [-i] [-f]"
1313
exit 1
1414
}
1515

@@ -33,15 +33,17 @@ unset -v APP_NAMED_ID
3333

3434
# optional args (with defaults)
3535
BUILD_CRYPTO_PLUGINS=0
36+
BUILD_ISAR_FROM_SOURCE=0
3637

3738
# Parse command-line arguments.
38-
while getopts "v:b:p:a:i" opt; do
39+
while getopts "v:b:p:a:i:f" opt; do
3940
case "${opt}" in
4041
v) APP_VERSION_STRING="$OPTARG" ;;
4142
b) APP_BUILD_NUMBER="$OPTARG" ;;
4243
p) APP_BUILD_PLATFORM="$OPTARG" ;;
4344
a) APP_NAMED_ID="$OPTARG" ;;
4445
i) BUILD_CRYPTO_PLUGINS=1 ;;
46+
f) BUILD_ISAR_FROM_SOURCE=1 ;;
4547
*) usage ;;
4648
esac
4749
done
@@ -71,6 +73,8 @@ set -x
7173

7274
source "${APP_PROJECT_ROOT_DIR}/scripts/app_config/templates/configure_template_files.sh"
7375

76+
export BUILD_ISAR_FROM_SOURCE
77+
7478
# checks for the correct platform dir and pushes it for later
7579
if printf '%s\0' "${APP_PLATFORMS[@]}" | grep -Fxqz -- "${APP_BUILD_PLATFORM}"; then
7680
pushd "${APP_PROJECT_ROOT_DIR}/scripts/${APP_BUILD_PLATFORM}"

0 commit comments

Comments
 (0)