Skip to content

Commit b43882e

Browse files
committed
nostr-sdk-ffi: fix uniffi and add bindings-android
1 parent c523686 commit b43882e

22 files changed

+539
-143
lines changed

bindings/nostr-sdk-ffi/.gitignore

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1 @@
1-
/target
2-
3-
# Byte-compiled / optimized / DLL files
4-
__pycache__/
5-
.pytest_cache/
6-
*.py[cod]
7-
8-
# C extensions
9-
*.so
10-
11-
# Distribution / packaging
12-
.Python
13-
.venv/
14-
env/
15-
bin/
16-
build/
17-
develop-eggs/
18-
dist/
19-
eggs/
20-
lib/
21-
lib64/
22-
parts/
23-
sdist/
24-
var/
25-
include/
26-
man/
27-
venv/
28-
*.egg-info/
29-
.installed.cfg
30-
*.egg
31-
32-
# Installer logs
33-
pip-log.txt
34-
pip-delete-this-directory.txt
35-
pip-selfcheck.json
36-
37-
# Unit test / coverage reports
38-
htmlcov/
39-
.tox/
40-
.coverage
41-
.cache
42-
nosetests.xml
43-
coverage.xml
44-
45-
# Translations
46-
*.mo
47-
48-
# Mr Developer
49-
.mr.developer.cfg
50-
.project
51-
.pydevproject
52-
53-
# Rope
54-
.ropeproject
55-
56-
# Django stuff:
57-
*.log
58-
*.pot
59-
60-
.DS_Store
61-
62-
# Sphinx documentation
63-
docs/_build/
64-
65-
# PyCharm
66-
.idea/
67-
68-
# VSCode
69-
.vscode/
70-
71-
# Pyenv
72-
.python-version
1+
ffi/

bindings/nostr-sdk-ffi/Cargo.toml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@ homepage.workspace = true
77
repository.workspace = true
88
license.workspace = true
99
rust-version.workspace = true
10-
keywords = ["nostr", "sdk", "rust", "ffi"]
10+
keywords = ["nostr", "sdk", "ffi"]
1111

1212
[lib]
13-
name = "nostrsdk"
13+
name = "nostr_sdk_ffi"
1414
crate-type = ["cdylib", "staticlib"]
1515

16+
[[bin]]
17+
name = "uniffi-bindgen"
18+
path = "uniffi-bindgen.rs"
19+
1620
[dependencies]
1721
log = "0.4"
1822
nostr = { path = "../../crates/nostr" }
1923
nostr-ffi = { path = "../nostr-ffi" }
2024
nostr-sdk = { path = "../../crates/nostr-sdk", default-features = false, features = ["all-nips", "blocking"] }
21-
parking_lot = "0.12.1"
22-
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "b50a66fb95ca1f9cf69b25e020f7c3382c0ce528" }
23-
uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "b50a66fb95ca1f9cf69b25e020f7c3382c0ce528" }
25+
parking_lot = "0.12"
26+
uniffi = { version = "0.23", features = ["cli"] }
27+
uniffi_bindgen = "0.23"
28+
uniffi_macros = "0.23"
2429

2530
[target.'cfg(target_os = "android")'.dependencies]
2631
android_logger = "0.13"
2732

2833
[build-dependencies]
29-
uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "b50a66fb95ca1f9cf69b25e020f7c3382c0ce528", features = ["builtin-bindgen"] }
34+
uniffi = { version = "0.23", features = ["build"] }

bindings/nostr-sdk-ffi/Makefile

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
1-
# Use 'verbose=1' to echo all commands, for example 'make help verbose=1'.
2-
ifdef verbose
3-
Q :=
4-
else
5-
Q := @
6-
endif
1+
SOURCES=$(sort $(wildcard ./src/*.rs ./src/**/*.rs))
72

8-
uniffideps:
9-
$(Q)cargo install uniffi_bindgen --version 0.23
3+
.PHONY: init
4+
init:
5+
rustup target add aarch64-apple-ios x86_64-apple-ios
6+
rustup target add aarch64-apple-darwin x86_64-apple-darwin
7+
rustup target add aarch64-apple-ios-sim
8+
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
9+
@if [ $$(uname) == "Darwin" ] ; then cargo install cargo-lipo ; fi
10+
cargo install cbindgen
11+
cargo install cargo-ndk
1012

11-
publish-python: uniffideps python-deps
12-
$(Q)maturin publish
13+
.PHONY: ndk-home
14+
ndk-home:
15+
@if [ ! -d "${ANDROID_NDK_HOME}" ] ; then \
16+
echo "Error: Please, set the ANDROID_NDK_HOME env variable to point to your NDK folder" ; \
17+
exit 1 ; \
18+
fi
1319

14-
python-deps:
15-
$(Q)cargo install --locked maturin
20+
.PHONY: sdk-root
21+
sdk-root:
22+
@if [ ! -d "${ANDROID_SDK_ROOT}" ] ; then \
23+
echo "Error: Please, set the ANDROID_SDK_ROOT env variable to point to your SDK folder" ; \
24+
exit 1 ; \
25+
fi
26+
27+
kotlin: android
28+
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/nostr_sdk.udl --language kotlin --no-format -o ffi/kotlin
29+
30+
android: aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
31+
32+
aarch64-linux-android: $(SOURCES) ndk-home
33+
cargo ndk -t aarch64-linux-android -o ffi/kotlin/jniLibs build --release
34+
35+
armv7-linux-androideabi: $(SOURCES) ndk-home
36+
cargo ndk -t armv7-linux-androideabi -o ffi/kotlin/jniLibs build --release
37+
38+
i686-linux-android: $(SOURCES) ndk-home
39+
cargo ndk -t i686-linux-android -o ffi/kotlin/jniLibs build --release
40+
41+
x86_64-linux-android: $(SOURCES) ndk-home
42+
cargo ndk -t x86_64-linux-android -o ffi/kotlin/jniLibs build --release
43+
44+
bindings-android: sdk-root kotlin
45+
cp -r ffi/kotlin/jniLibs bindings-android/lib/src/main
46+
cp -r ffi/kotlin/nostr_sdk bindings-android/lib/src/main/kotlin/
47+
cd bindings-android && ./gradlew assemble
48+
mkdir -p ffi/android
49+
cp bindings-android/lib/build/outputs/aar/lib-release.aar ffi/android

bindings/nostr-sdk-ffi/README.python.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/android
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=android
3+
4+
### Android ###
5+
# Gradle files
6+
.gradle/
7+
build/
8+
9+
# Local configuration file (sdk path, etc)
10+
local.properties
11+
12+
# Log/OS Files
13+
*.log
14+
15+
# Android Studio generated files and folders
16+
captures/
17+
.externalNativeBuild/
18+
.cxx/
19+
*.apk
20+
output.json
21+
22+
# IntelliJ
23+
*.iml
24+
.idea/
25+
misc.xml
26+
deploymentTargetDropDown.xml
27+
render.experimental.xml
28+
29+
# Keystore files
30+
*.jks
31+
*.keystore
32+
33+
# Google Services (e.g. APIs or Firebase)
34+
google-services.json
35+
36+
# Android Profiling
37+
*.hprof
38+
39+
### Android Patch ###
40+
gen-external-apklibs
41+
42+
# Replacement of .externalNativeBuild directories introduced
43+
# with Android Studio 3.5.
44+
45+
# End of https://www.toptal.com/developers/gitignore/api/android
46+
47+
lib/src/main/jniLibs/
48+
lib/src/main/kotlin/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
dependencies {
7+
classpath("com.android.tools.build:gradle:7.1.2")
8+
}
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
org.gradle.jvmargs=-Xmx1536m
2+
android.useAndroidX=true
3+
android.enableJetifier=true
4+
kotlin.code.style=official
5+
libraryVersion=0.0.1
58.1 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)