Skip to content

Commit 7de5728

Browse files
committed
Add Flutter multi-platform package; add Android 16kb page size support; fix broken npmjs packages workflow
1 parent 6032d3e commit 7de5728

File tree

16 files changed

+372
-10
lines changed

16 files changed

+372
-10
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: publish flutter package
2+
on:
3+
push:
4+
tags:
5+
- '*.*.*'
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-22.04
14+
name: publish to pub.dev
15+
16+
steps:
17+
18+
- uses: actions/checkout@v4.2.2
19+
20+
- name: download release assets
21+
run: |
22+
VERSION=${GITHUB_REF#refs/tags/}
23+
echo "VERSION=$VERSION" >> $GITHUB_ENV
24+
25+
mkdir -p artifacts
26+
cd artifacts
27+
28+
# Download all platform binaries from the GitHub release
29+
gh release download "$VERSION" --pattern "ai-*.tar.gz"
30+
31+
# Extract all archives
32+
for archive in ai-*.tar.gz; do
33+
name=$(basename "$archive" "-$VERSION.tar.gz")
34+
mkdir -p "$name"
35+
tar -xzf "$archive" -C "$name"
36+
rm "$archive"
37+
done
38+
39+
ls -la
40+
env:
41+
GH_TOKEN: ${{ github.token }}
42+
43+
- uses: dart-lang/setup-dart@v1.7.1
44+
45+
- name: assemble and publish flutter package
46+
run: |
47+
FLUTTER_DIR=packages/flutter
48+
49+
# Android (only arm64 and x64, no arm)
50+
mkdir -p $FLUTTER_DIR/native_libraries/android
51+
cp artifacts/ai-android-arm64-v8a/ai.so $FLUTTER_DIR/native_libraries/android/ai_android_arm64.so
52+
cp artifacts/ai-android-x86_64/ai.so $FLUTTER_DIR/native_libraries/android/ai_android_x64.so
53+
54+
# iOS device
55+
mkdir -p $FLUTTER_DIR/native_libraries/ios
56+
cp artifacts/ai-ios/ai.dylib $FLUTTER_DIR/native_libraries/ios/ai_ios_arm64.dylib
57+
58+
# iOS simulator (keep universal/fat binary as-is)
59+
mkdir -p $FLUTTER_DIR/native_libraries/ios-sim
60+
cp artifacts/ai-ios-sim/ai.dylib $FLUTTER_DIR/native_libraries/ios-sim/ai_ios-sim.dylib
61+
62+
# macOS (separate arch-specific dylibs)
63+
mkdir -p $FLUTTER_DIR/native_libraries/mac
64+
cp artifacts/ai-macos-arm64/ai.dylib $FLUTTER_DIR/native_libraries/mac/ai_mac_arm64.dylib
65+
cp artifacts/ai-macos-x86_64/ai.dylib $FLUTTER_DIR/native_libraries/mac/ai_mac_x64.dylib
66+
67+
# Linux
68+
mkdir -p $FLUTTER_DIR/native_libraries/linux
69+
cp artifacts/ai-linux-cpu-x86_64/ai.so $FLUTTER_DIR/native_libraries/linux/ai_linux_x64.so
70+
cp artifacts/ai-linux-cpu-arm64/ai.so $FLUTTER_DIR/native_libraries/linux/ai_linux_arm64.so
71+
72+
# Windows
73+
mkdir -p $FLUTTER_DIR/native_libraries/windows
74+
cp artifacts/ai-windows-cpu-x86_64/ai.dll $FLUTTER_DIR/native_libraries/windows/ai_windows_x64.dll
75+
76+
# Update version
77+
sed -i "s/^version: .*/version: $VERSION/" $FLUTTER_DIR/pubspec.yaml
78+
79+
# Publish to pub.dev
80+
cd $FLUTTER_DIR
81+
dart pub get
82+
dart pub publish --dry-run
83+
dart pub publish --force

.github/workflows/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Build, Test and Release
22
on:
33
push:
4+
branches:
5+
- '**'
6+
tags-ignore:
7+
- '**'
48
workflow_dispatch:
59

610
permissions:
@@ -526,13 +530,9 @@ jobs:
526530
- uses: actions/setup-node@v4
527531
if: steps.tag.outputs.version != ''
528532
with:
529-
node-version: '20'
533+
node-version: '24'
530534
registry-url: 'https://registry.npmjs.org'
531535

532-
- name: update npm
533-
if: steps.tag.outputs.version != ''
534-
run: npm install -g npm@11.5.1
535-
536536
- name: build and publish npm packages
537537
if: steps.tag.outputs.version != ''
538538
run: |
@@ -589,9 +589,11 @@ jobs:
589589
- uses: softprops/action-gh-release@v2.2.1
590590
if: steps.tag.outputs.version != ''
591591
with:
592+
token: ${{ secrets.RELEASE_PAT }}
592593
body: |
593594
# Packages
594595
596+
[**Flutter/Dart**](https://pub.dev/packages/sqlite_ai): `flutter pub add sqlite_ai:${{ steps.tag.outputs.version }}` or `dart pub add sqlite_ai:${{ steps.tag.outputs.version }}`
595597
[**Node**](https://www.npmjs.com/package/@sqliteai/sqlite-ai): `npm install @sqliteai/sqlite-ai`
596598
[**Android**](https://central.sonatype.com/artifact/ai.sqlite/ai): `ai.sqlite:ai:${{ steps.tag.outputs.version }}`
597599
[**Python**](https://pypi.org/project/sqlite-ai): `pip install sqlite-ai`

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ packages/node/test-platform-packages/
4444

4545
# System
4646
.DS_Store
47-
Thumbs.db
47+
Thumbs.db
48+
49+
# Dart/Flutter
50+
.dart_tool/
51+
pubspec.lock
52+
.flutter-plugins
53+
.flutter-plugins-dependencies
54+
packages/flutter/native_libraries/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ else ifeq ($(PLATFORM),android)
119119
CC = $(BIN)/$(ARCH)-linux-android26-clang
120120
CXX = $(CC)++
121121
TARGET := $(DIST_DIR)/ai.so
122-
LDFLAGS += -static-libstdc++ -shared
122+
LDFLAGS += -static-libstdc++ -shared -Wl,-z,max-page-size=16384
123123
ANDROID_OPTIONS = -DCMAKE_TOOLCHAIN_FILE=$(ANDROID_NDK)/build/cmake/android.toolchain.cmake -DANDROID_ABI=$(if $(filter aarch64,$(ARCH)),arm64-v8a,$(ARCH)) -DANDROID_PLATFORM=android-26 -DCMAKE_C_FLAGS="-march=$(if $(filter aarch64,$(ARCH)),armv8.7a,x86-64)" -DCMAKE_CXX_FLAGS="-march=$(if $(filter aarch64,$(ARCH)),armv8.7a,x86-64)" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DGGML_OPENMP=OFF -DGGML_LLAMAFILE=OFF
124124
ifneq (,$(filter $(ARCH),aarch64))
125125
ANDROID_OPTIONS += -DGGML_CPU_ARM_ARCH=armv8.2-a+dotprod

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ pip install sqlite-ai
9696

9797
For usage details and examples, see the [Python package documentation](./packages/python/README.md).
9898

99+
### Flutter Package
100+
101+
Add the [sqlite_ai](https://pub.dev/packages/sqlite_ai) package to your project:
102+
103+
```bash
104+
flutter pub add sqlite_ai # Flutter projects
105+
dart pub add sqlite_ai # Dart projects
106+
```
107+
108+
Usage with `sqlite3` package:
109+
```dart
110+
import 'package:sqlite3/sqlite3.dart';
111+
import 'package:sqlite_ai/sqlite_ai.dart';
112+
113+
sqlite3.loadSqliteAiExtension();
114+
final db = sqlite3.openInMemory();
115+
print(db.select('SELECT ai_version()'));
116+
```
117+
118+
For a complete example, see the [Flutter example](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/examples/flutter/README.md).
119+
99120
## Getting Started
100121

101122
Here's a quick example to get started with SQLite Sync:

packages/flutter/.pubignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Only ignore development files, NOT native_libraries
2+
.dart_tool/
3+
pubspec.lock
4+
5+
# Explicitly include native_libraries (override any parent .gitignore)
6+
!native_libraries/
7+
!native_libraries/**

packages/flutter/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## 0.7.59
4+
5+
- Initial Flutter package release
6+
- Added support for Android 16kb page size devices

packages/flutter/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE.md

packages/flutter/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# sqlite_ai
2+
3+
SQLite-AI is an extension for SQLite that brings artificial intelligence capabilities directly into the database. It enables developers to run, fine-tune, and serve AI models from within SQLite using simple SQL queries — ideal for on-device and edge applications where low-latency and offline inference are critical.
4+
5+
## Installation
6+
7+
```
8+
dart pub add sqlite_ai
9+
```
10+
11+
Requires Dart 3.10+ / Flutter 3.38+.
12+
13+
## Usage
14+
15+
### With `sqlite3`
16+
17+
```dart
18+
import 'package:sqlite3/sqlite3.dart';
19+
import 'package:sqlite_ai/sqlite_ai.dart';
20+
21+
void main() {
22+
// Load once at startup.
23+
sqlite3.loadSqliteAiExtension();
24+
25+
final db = sqlite3.openInMemory();
26+
27+
// Check version.
28+
final result = db.select('SELECT ai_version() AS version');
29+
print(result.first['version']);
30+
31+
// Load a GGUF model.
32+
db.execute("SELECT llm_model_load('./models/llama.gguf', 'gpu_layers=99')");
33+
34+
// Run inference.
35+
final response = db.select("SELECT llm_chat_respond('What is 2+2?') AS answer");
36+
print(response.first['answer']);
37+
38+
db.dispose();
39+
}
40+
```
41+
42+
### With `drift`
43+
44+
```dart
45+
import 'package:sqlite3/sqlite3.dart';
46+
import 'package:sqlite_ai/sqlite_ai.dart';
47+
import 'package:drift/native.dart';
48+
49+
Sqlite3 loadExtensions() {
50+
sqlite3.loadSqliteAiExtension();
51+
return sqlite3;
52+
}
53+
54+
// Use when creating the database:
55+
NativeDatabase.createInBackground(
56+
File(path),
57+
sqlite3: loadExtensions,
58+
);
59+
```
60+
61+
## Supported platforms
62+
63+
| Platform | Architectures |
64+
|----------|---------------|
65+
| Android | arm64, x64 |
66+
| iOS | arm64 (device + simulator) |
67+
| macOS | arm64, x64 |
68+
| Linux | arm64, x64 |
69+
| Windows | x64 |
70+
71+
## API
72+
73+
See the full [sqlite-ai API documentation](https://github.com/sqliteai/sqlite-ai/blob/main/API.md).
74+
75+
## License
76+
77+
See [LICENSE](LICENSE).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

0 commit comments

Comments
 (0)