Skip to content

Custom prefab build for Android / v0.2.1 #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,26 @@ rustflags = [
"-C", "link-arg=-mmacosx-version-min=10.13",
]


# For Android, it is important to set the soname.
# Otherwise, the linker hardcodes the path in the lib,
# which breaks loading.
[target.aarch64-linux-android]
rustflags = [
"-C", "link-arg=-Wl,-soname,libpowersync.so",
]

[target.armv7-linux-androideabi]
rustflags = [
"-C", "link-arg=-Wl,-soname,libpowersync.so",
]

[target.x86_64-linux-android]
rustflags = [
"-C", "link-arg=-Wl,-soname,libpowersync.so",
]

[target.i686-linux-android]
rustflags = [
"-C", "link-arg=-Wl,-soname,libpowersync.so",
]
6 changes: 0 additions & 6 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
on:
push:
tags:
- "*"
name: "android"
jobs:
build:
Expand All @@ -17,10 +15,6 @@ jobs:
distribution: "temurin"
java-version: "17"

- uses: nttld/setup-ndk@v1
with:
ndk-version: r26

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
on:
push:
tags:
- "*"
name: "ios"
jobs:
build:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
on:
push:
tags:
- "*"
workflow_dispatch:
name: "linux"
jobs:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ jobs:
distribution: "temurin"
java-version: "17"

- uses: nttld/setup-ndk@v1
with:
ndk-version: r26

- name: Setup
run: |
rustup toolchain install nightly-2024-05-18-x86_64-unknown-linux-gnu
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on:
push:
name: "linux"
jobs:
build_wasm:
name: Basic WASM build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install Rust Nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-05-18
components: rust-src

- name: Build WASM bytecode
run: RUSTFLAGS="--emit=llvm-bc -C linker=/bin/true" cargo build -p powersync_loadable --profile wasm --no-default-features --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/static sqlite_nostd/omit_load_extension" -Z build-std=panic_abort,core,alloc --target wasm32-unknown-emscripten
2 changes: 0 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
on:
push:
tags:
- "*"
name: "windows"
jobs:
build_windows:
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inherits = "release"
lto = false

[workspace.package]
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["JourneyApps"]
keywords = ["sqlite", "powersync"]
Expand Down
5 changes: 3 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Bump the version number in these places:
1. Cargo.toml
2. powersync-sqlite-core.podspec.
3. android/build.gradle.kts
4. build-pod.sh - CFBundleVersion and CFBundleShortVersionString.
5. `cargo build` to update Cargo.lock
4. android/src/prefab/prefab.json
5. build-pod.sh - CFBundleVersion and CFBundleShortVersionString.
6. `cargo build` to update Cargo.lock

Create a tag:

Expand Down
62 changes: 37 additions & 25 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import java.util.Base64

plugins {
id("com.android.library") version "8.0.1"
id("maven-publish")
id("signing")
}

group = "co.powersync"
version = "0.2.0"
version = "0.2.1"
description = "PowerSync Core SQLite Extension"

repositories {
mavenCentral()
google()
}

val buildRust = tasks.register("buildRust", Exec::class.java) {
val buildRust = tasks.register<Exec>("buildRust") {
workingDir("..")
commandLine(
"cargo",
Expand All @@ -38,36 +37,39 @@ val buildRust = tasks.register("buildRust", Exec::class.java) {
)
}

android {
compileSdk = 33

namespace = "co.powersync.sqlitecore"
val prefabAar = tasks.register<Zip>("prefabAar") {
dependsOn(buildRust)

defaultConfig {
minSdk = 21
from("build/intermediates/jniLibs") {
include("**/*")
into("jni")
}

sourceSets {
getByName("main") {
jniLibs.srcDir("build/intermediates/jniLibs")
}
from("src/") {
include("**/*")
}

buildTypes {
release {
isMinifyEnabled = false
}
}
val architectures = listOf(
"armeabi-v7a",
"arm64-v8a",
"x86",
"x86_64"
)

publishing {
singleVariant("release") {
withSourcesJar()
architectures.forEach { architecture ->
from("build/intermediates/jniLibs/$architecture/") {
include("libpowersync.so")
into("prefab/modules/powersync/libs/android.$architecture/")
}
}

archiveFileName.set("build/outputs/aar/powersync-sqlite-core.aar")
destinationDirectory.set(file("./"))
}

tasks.named("preBuild") {
dependsOn(buildRust)
val sourcesJar = tasks.register<Jar>("sourcesJar") {
// We don't have any actual java sources to bundle
archiveClassifier.set("sources")
}

publishing {
Expand All @@ -78,7 +80,13 @@ publishing {
version = project.version.toString()

afterEvaluate {
from(components["release"])
artifact(prefabAar) {
extension = "aar"
}

artifact(sourcesJar) {
classifier = "sources"
}
}

pom {
Expand Down Expand Up @@ -147,5 +155,9 @@ signing {
}

tasks.withType<AbstractPublishToMaven>() {
dependsOn("assembleRelease")
dependsOn(prefabAar)
}

tasks.named("build") {
dependsOn(prefabAar)
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 7 additions & 0 deletions android/src/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.powersync.sqlitecore" >

<uses-sdk android:minSdkVersion="21" />

</manifest>
9 changes: 9 additions & 0 deletions android/src/prefab/modules/powersync/include/powersync.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef POWERSYNC_H
#define POWERSYNC_H

#include "sqlite3.h"

extern "C" int sqlite3_powersync_init(sqlite3 *db, char **pzErrMsg,
const sqlite3_api_routines *pApi);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"abi": "arm64-v8a",
"api": 21,
"ndk": 25,
"stl": "none",
"static": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"abi": "armeabi-v7a",
"api": 21,
"ndk": 25,
"stl": "none",
"static": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"abi": "x86",
"api": 21,
"ndk": 25,
"stl": "none",
"static": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"abi": "x86_64",
"api": 21,
"ndk": 25,
"stl": "none",
"static": false
}
4 changes: 4 additions & 0 deletions android/src/prefab/modules/powersync/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"export_libraries": [],
"android": {}
}
6 changes: 6 additions & 0 deletions android/src/prefab/prefab.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "powersync_sqlite_core",
"schema_version": 2,
"dependencies": [],
"version": "0.2.1"
}
4 changes: 2 additions & 2 deletions build-pod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function createXcframework() {
<key>MinimumOSVersion</key>
<string>11.0</string>
<key>CFBundleVersion</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<string>0.2.1</string>
</dict>
</plist>
EOF
Expand Down
2 changes: 1 addition & 1 deletion powersync-sqlite-core.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'powersync-sqlite-core'
s.version = '0.2.0'
s.version = '0.2.1'
s.summary = 'PowerSync SQLite Extension'
s.description = <<-DESC
PowerSync extension for SQLite.
Expand Down
Loading