Skip to content

Commit

Permalink
ObjectBox Swift database 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed May 15, 2024
1 parent 5ba1b60 commit b4a5b05
Show file tree
Hide file tree
Showing 54 changed files with 948 additions and 348 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "ObjectBox",
url: "https://github.com/objectbox/objectbox-swift/releases/download/v1.9.2/ObjectBox-xcframework-1.9.2.zip",
checksum: "e70e580fe40ef752fbb29b4cb0a3be1c51f3024020bf1832a73e79e921b42dd3"
url: "https://github.com/objectbox/objectbox-swift/releases/download/v2.0.0/ObjectBox-xcframework-2.0.0.zip",
checksum: "20766ccf880bd66c4246f55536fbd3f33f1e8bb7adf55101a3dd06a8ee043116"
)
]
)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Here's a list of ObjectBox releases, and the Swift versions they were compiled w

| ObjectBox version(s) | Swift version |
|:--------------------:|:-------------:|
| 2.0.0 | 5.9 |
| 1.9.2 | 5.9 |
| 1.9.1 | 5.9 |
| 1.9.0 | 5.8.1 |
Expand Down
57 changes: 43 additions & 14 deletions Source/fetch_dependencies.command
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
#!/usr/bin/env bash

# Script that is used by CI to build the static libs, or by external users to download a build from
# Github. Will do nothing if there already is a copy of the static libs in external.
#
# Adjust the 'version' variable as needed to get the right version for the current code.
# Script that is used to build the static libs, or by external users to download a build from
# Github. Builds are cached in the Library/Caches/ObjectBox directory.
#
# Adjust 'version', 'c_version' and 'build_params' as needed and set the OBX_FEATURES environment
# variable to get the right version for the current code.

set -e

# objectbox-swift release version on GitHub:
# https://github.com/objectbox/objectbox-swift/releases/download/v${version}
version=2.0.0

# C library version attached to the GitHub release:
# ObjectBoxCore-static-${c_version}.zip
c_version=4.0.0

# Params supported by apple-build-static-libs.sh
build_params=""

# Skips building/fetching, only copy header files and print details
if [ "${1:-}" == "--verify-only" ]; then
verify_only=true
shift
else
verify_only=false
fi

# Never builds and downloads release from objectbox-swift-spec-staging GitHub repo instead
if [ "${1:-}" == "--staging" ]; then
staging_repo=true
shift
else
staging_repo=false
fi

# Clean by default: after an update, there were issues with standard C includes not found and cleaning helped
clean_build=true
if [ "${1:-}" == "--dirty" ]; then
clean_build=false
Expand All @@ -40,20 +54,35 @@ if [ "$verify_only" = true ]; then
else

if [ -d "$code_dir" ] && [ "$staging_repo" != "true" ]; then # Do we have an existing code repo? Then build it...
pushd "$code_dir" # note: this also "fixed" building into cbuild dir in "our" objectbox-swift dir

echo "-----------------------------------------"
xcode_version="$(xcodebuild -version | head -n 1 | tr -cd '[a-zA-Z0-9]._-')"
echo "Xcode version: $xcode_version"

pushd "$code_dir" # note: this also "fixed" building into cbuild dir in "our" objectbox-swift dir
build_params="" # must also part of the cache key
# Build cache key: includes commit, XCode version, extra features, build command parameters
commit_id=$(git rev-parse HEAD)
cache_dir="$HOME/Library/Caches/ObjectBox"
mkdir -p "${cache_dir}"
find "${cache_dir}" -name "objectbox-static-*.zip" -type f -mtime +30 # -delete # TODO enable delete once this looks good
cache_key="${commit_id}-$xcode_version"
features=${OBX_FEATURES:-}
if [[ -n "${features}" ]]; then
echo "Info: environment variable OBX_FEATURES is set to \"${features}\""
# replace semicolon with dash, convert to lower case
# like "feature1-feature2"
conf=$(echo "${features//\;/-}" | tr '[:upper:]' '[:lower:]')
cache_key="${cache_key}-${conf}"
fi
if [ -n "$build_params" ]; then
cache_key="${cache_key}-$(echo "$build_params" | tr -cd '[a-zA-Z0-9]._-')"
fi

cache_dir="$HOME/Library/Caches/ObjectBox"
mkdir -p "${cache_dir}"
echo "-----------------------------------------"
echo "Existing cache files:"
find "${cache_dir}" -name "objectbox-static-*.zip" -type f -mtime +30 # -delete # TODO enable delete once this looks good
echo "-----------------------------------------"
cache_zip="${cache_dir}/objectbox-static-${cache_key}.zip"

do_build=true
git_clean=false
git_status=$(git status --porcelain)
Expand All @@ -63,13 +92,13 @@ if [ -d "$code_dir" ] && [ "$staging_repo" != "true" ]; then # Do we have an exi
if [ -z "$git_status" ]; then
git_clean=true
if [ -f "${cache_zip}" ]; then
echo "🟢 ObjectBox core is clean and cache ZIP found for ${cache_key}."
echo "🟢 ObjectBox core is clean and cache ZIP found for key '${cache_key}'."
echo "📦 Extracting..."
sleep 0.5
unzip -o "${cache_zip}" -d "${dest_dir}"
do_build=false
else
echo "⚪ ObjectBox core is clean but no cache ZIP found for ${cache_key}."
echo "⚪ ObjectBox core is clean but no cache ZIP found for key '${cache_key}'."
echo "🏗️ Building..."
sleep 0.5
fi
Expand All @@ -81,11 +110,13 @@ if [ -d "$code_dir" ] && [ "$staging_repo" != "true" ]; then # Do we have an exi
fi
if [ "$do_build" = true ]; then
if [ "$clean_build" == "true" ]; then
# By default, we clean: after an update, we had issues with standard C includes not found and cleaning helped
echo "Cleaning $code_dir/cbuild/ ..."
rm -Rf $code_dir/cbuild/
fi

# Build
"$code_dir/scripts/apple-build-static-libs.sh" $build_params "$dest_dir" release

if [ "$git_clean" = true ] ; then # clean before?
git_status=${git_status#"?? objectbox/src/main/cpp/external/uws-objectbox/"}
if [ -z "$git_status" ]; then # still clean
Expand All @@ -99,8 +130,6 @@ if [ -d "$code_dir" ] && [ "$staging_repo" != "true" ]; then # Do we have an exi
popd
else # Download static public release and unzip into $dest
if [ ! -d "${dest_dir}" ] || [ ! -e "${dest_dir}/libObjectBoxCore-iOS.a" ]; then
version=1.9.2
c_version=0.21.0
archive_path="${my_dir}/external/objectbox-static.zip"
if [ "$staging_repo" == "true" ]; then
release_url_path="https://github.com/objectbox/objectbox-swift-spec-staging/releases/download/v1.x"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,16 @@ fileprivate func cModel() throws -> OpaquePointer {
extension ObjectBox.Store {
/// A store with a fully configured model. Created by the code generator with your model's metadata in place.
///
/// # In-memory database
/// To use a file-less in-memory database, instead of a directory path pass `memory:`
/// together with an identifier string:
/// ```swift
/// let inMemoryStore = try Store(directoryPath: "memory:test-db")
/// ```
///
/// - Parameters:
/// - directoryPath: The directory path in which ObjectBox places its database files for this store.
/// - directoryPath: The directory path in which ObjectBox places its database files for this store,
/// or to use an in-memory database `memory:<identifier>`.
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB).
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`.
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
Expand All @@ -139,8 +147,9 @@ extension ObjectBox.Store {
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers.
/// Note: The internal default is currently around 120.
/// So when hitting this limit, try values around 200-500.
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions.
///
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)`
/// initializer, trigger code generation by building your project.
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,16 @@ fileprivate func cModel() throws -> OpaquePointer {
extension ObjectBox.Store {
/// A store with a fully configured model. Created by the code generator with your model's metadata in place.
///
/// # In-memory database
/// To use a file-less in-memory database, instead of a directory path pass `memory:`
/// together with an identifier string:
/// ```swift
/// let inMemoryStore = try Store(directoryPath: "memory:test-db")
/// ```
///
/// - Parameters:
/// - directoryPath: The directory path in which ObjectBox places its database files for this store.
/// - directoryPath: The directory path in which ObjectBox places its database files for this store,
/// or to use an in-memory database `memory:<identifier>`.
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB).
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`.
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
Expand All @@ -120,8 +128,9 @@ extension ObjectBox.Store {
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers.
/// Note: The internal default is currently around 120.
/// So when hitting this limit, try values around 200-500.
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions.
///
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)`
/// initializer, trigger code generation by building your project.
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,16 @@ fileprivate func cModel() throws -> OpaquePointer {
extension ObjectBox.Store {
/// A store with a fully configured model. Created by the code generator with your model's metadata in place.
///
/// # In-memory database
/// To use a file-less in-memory database, instead of a directory path pass `memory:`
/// together with an identifier string:
/// ```swift
/// let inMemoryStore = try Store(directoryPath: "memory:test-db")
/// ```
///
/// - Parameters:
/// - directoryPath: The directory path in which ObjectBox places its database files for this store.
/// - directoryPath: The directory path in which ObjectBox places its database files for this store,
/// or to use an in-memory database `memory:<identifier>`.
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB).
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`.
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
Expand All @@ -138,8 +146,9 @@ extension ObjectBox.Store {
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers.
/// Note: The internal default is currently around 120.
/// So when hitting this limit, try values around 200-500.
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions.
///
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)`
/// initializer, trigger code generation by building your project.
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,16 @@ fileprivate func cModel() throws -> OpaquePointer {
extension ObjectBox.Store {
/// A store with a fully configured model. Created by the code generator with your model's metadata in place.
///
/// # In-memory database
/// To use a file-less in-memory database, instead of a directory path pass `memory:`
/// together with an identifier string:
/// ```swift
/// let inMemoryStore = try Store(directoryPath: "memory:test-db")
/// ```
///
/// - Parameters:
/// - directoryPath: The directory path in which ObjectBox places its database files for this store.
/// - directoryPath: The directory path in which ObjectBox places its database files for this store,
/// or to use an in-memory database `memory:<identifier>`.
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB).
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`.
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
Expand All @@ -138,8 +146,9 @@ extension ObjectBox.Store {
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers.
/// Note: The internal default is currently around 120.
/// So when hitting this limit, try values around 200-500.
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions.
///
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)`
/// initializer, trigger code generation by building your project.
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,16 @@ fileprivate func cModel() throws -> OpaquePointer {
extension ObjectBox.Store {
/// A store with a fully configured model. Created by the code generator with your model's metadata in place.
///
/// # In-memory database
/// To use a file-less in-memory database, instead of a directory path pass `memory:`
/// together with an identifier string:
/// ```swift
/// let inMemoryStore = try Store(directoryPath: "memory:test-db")
/// ```
///
/// - Parameters:
/// - directoryPath: The directory path in which ObjectBox places its database files for this store.
/// - directoryPath: The directory path in which ObjectBox places its database files for this store,
/// or to use an in-memory database `memory:<identifier>`.
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB).
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`.
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
Expand All @@ -139,8 +147,9 @@ extension ObjectBox.Store {
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers.
/// Note: The internal default is currently around 120.
/// So when hitting this limit, try values around 200-500.
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions.
///
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)`
/// initializer, trigger code generation by building your project.
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,16 @@ fileprivate func cModel() throws -> OpaquePointer {
extension ObjectBox.Store {
/// A store with a fully configured model. Created by the code generator with your model's metadata in place.
///
/// # In-memory database
/// To use a file-less in-memory database, instead of a directory path pass `memory:`
/// together with an identifier string:
/// ```swift
/// let inMemoryStore = try Store(directoryPath: "memory:test-db")
/// ```
///
/// - Parameters:
/// - directoryPath: The directory path in which ObjectBox places its database files for this store.
/// - directoryPath: The directory path in which ObjectBox places its database files for this store,
/// or to use an in-memory database `memory:<identifier>`.
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB).
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`.
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750).
Expand All @@ -157,8 +165,9 @@ extension ObjectBox.Store {
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers.
/// Note: The internal default is currently around 120.
/// So when hitting this limit, try values around 200-500.
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions.
///
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)`
/// initializer, trigger code generation by building your project.
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024,
Expand Down
Loading

0 comments on commit b4a5b05

Please sign in to comment.