Skip to content

Commit

Permalink
Merge pull request #118 from LtbLightning/v0.29.3-minor-fixes
Browse files Browse the repository at this point in the history
V0.29.3 minor fixes
  • Loading branch information
BitcoinZavior authored Dec 6, 2023
2 parents 2c540bc + cf9d9ce commit cd3c570
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ migrate_working_dir/
.dart_tool/
.packages
build/
bdk_flutter_*/
frameworks/
bdk.*/
*.xcframework
android/src/main/jniLibs/
rust/target/
rust/Cargo.lock
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ final internalAddress =
The latest API documentation is available [here](https://pub.dev/documentation/bdk_flutter/latest/bdk_flutter/bdk_flutter-library.html)

### Example Projects
**BDK Flutter Demo App:** The [BDK Flutter QuickStart](https://github.com/LtbLightning/bdk-flutter-quickstart) is a simple bitcoin app built in flutter to serve as a reference app to demonstrate `bdk-flutter` api usage.

- **\*BDK Flutter Demo App:** The [BDK Flutter Demo App](https://github.com/LtbLightning/bdk-flutter-quickstart)
is a simple bitcoin app built in flutter to serve as a reference app to demonstrate `bdk-flutter` api usage.

### How to build

Expand All @@ -187,9 +189,10 @@ _Note that Flutter version `3.0` or later is required to build the plugin._
The easiest way to get Cargo is to install the current stable release of Rust by using [rustup](https://doc.rust-lang.org/cargo/getting-started/installation.html). Installing Rust using rustup will also install cargo.

2. Clone this repository
```shell
git clone https://github.com/LtbLightning/bdk-flutter.git
```

```shell
git clone https://github.com/LtbLightning/bdk-flutter
```

3. Activate dart `ffigen`

Expand Down
21 changes: 17 additions & 4 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
cmake_minimum_required(VERSION 3.18.1)
project(bdk_flutter)
get_filename_component(CMAKE_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)
set(LIB_VERSION "0.29.3")
set(LIB_NAME "bdk_flutter_${LIB_VERSION}")
set(URL "https://github.com/LtbLightning/bdk-flutter/releases/download/${LIB_VERSION}/${LIB_NAME}.zip")
set(OUTPUT_PATH "${CMAKE_PARENT_DIR}/${LIB_NAME}.zip")
set(TEXT_FILE_PATH "${CMAKE_PARENT_DIR}/assets/release.config.txt")
file(STRINGS ${TEXT_FILE_PATH} lines)
foreach(line IN LISTS lines)
string(REGEX MATCH "TAG_VERSION=(.*)" _ ${line})
if(CMAKE_MATCH_1)
set(TAG_VERSION ${CMAKE_MATCH_1})
endif()

string(REGEX MATCH "REPOSITORY_URL=(.*)" _ ${line})
if(CMAKE_MATCH_1)
set(REPOSITORY_URL ${CMAKE_MATCH_1})
endif()
endforeach()


set(LIB_NAME "bdk.${TAG_VERSION}")
set(URL "${REPOSITORY_URL}${TAG_VERSION}/${LIB_NAME}.zip")
set(OUTPUT_PATH "${CMAKE_PARENT_DIR}/${LIB_NAME}.zip")
if(NOT EXISTS "${CMAKE_PARENT_DIR}/${LIB_NAME}")
file(DOWNLOAD ${URL} ${OUTPUT_PATH}
STATUS DOWNLOAD_STATUS
Expand Down
4 changes: 0 additions & 4 deletions assets/config.json

This file was deleted.

2 changes: 2 additions & 0 deletions assets/release.config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TAG_VERSION=0.29.3
REPOSITORY_URL=https://github.com/LtbLightning/test-pub/releases/download/
38 changes: 26 additions & 12 deletions ios/bdk_flutter.podspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
release_tag = '0.29.3'

read_key_value_pairs = lambda do |file_path|
pairs = {}
File.foreach(file_path) do |line|
key, value = line.chomp.split('=')
pairs[key] = value
end
pairs
end
podspec_dir = File.dirname(__FILE__)
assets_dir = File.join(podspec_dir, '..', 'assets')
config_file_path = File.join(assets_dir, 'release.config.txt')
config = read_key_value_pairs.call(config_file_path)

tag_version = "#{config['TAG_VERSION']}"
framework = 'rust_bdk_ffi.xcframework'
binary = "bdk_flutter_#{release_tag}"
url = "https://github.com/LtbLightning/bdk-flutter/releases/download/#{release_tag}/#{binary}.zip"
frameworks_dir = "frameworks/#{release_tag}"
lib_name = "bdk.#{tag_version}"
url = "#{config['REPOSITORY_URL']}#{tag_version}/#{lib_name}.zip"
frameworks_dir = "ios"

`
cd ../
if [ ! -d #{binary} ]; then
curl -L #{url} -o #{binary}.zip
unzip #{binary}.zip
if [ ! -d #{lib_name} ]; then
curl -L #{url} -o #{lib_name}.zip
unzip #{lib_name}.zip
rm -rf __MACOSX
rm #{binary}.zip
rm #{lib_name}.zip
fi
if [ ! -d #{frameworks_dir} ]; then
mkdir -p #{frameworks_dir}
mv #{binary}/#{framework} #{frameworks_dir}
if [ ! -d #{frameworks_dir}/#{framework} ]; then
cp -R #{lib_name}/#{framework} #{frameworks_dir}
fi
`

Pod::Spec.new do |s|
s.name = 'bdk_flutter'
s.version = '0.29.3'
s.version = "#{config['TAG_VERSION']}"
s.summary = 'A Flutter library for the Bitcoin Development Kit (https://bitcoindevkit.org/)'
s.description = <<-DESC
A new Flutter project.
Expand Down
29 changes: 19 additions & 10 deletions lib/src/utils/loader.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:convert' as convert;
import 'dart:ffi';
import 'dart:io';

Expand Down Expand Up @@ -27,8 +26,7 @@ DynamicLibrary _open() {
}

String getTestBinaryUrl(Directory dir) {
final assetsDir =
'${dir.path}/build/unit_test_assets/${AppConfig.testBinDir}';
final assetsDir = '${dir.path}/build/unit_test_assets/${AppConfig.libName}';
if (Platform.isMacOS) {
return "$assetsDir/macos/librust_bdk_ffi.dylib";
} else {
Expand All @@ -41,16 +39,26 @@ final bdkFfi = RustBdkFfiImpl(_open());
class AppConfig {
static Map<String, dynamic>? _config;
static Future<void> _loadJsonAsset() async {
final String jsonString =
await rootBundle.loadString("packages/bdk_flutter/assets/config.json");
_config = convert.jsonDecode(jsonString);
final String content = await rootBundle
.loadString("packages/bdk_flutter/assets/release.config.txt");
Map<String, dynamic> configMap = {};
List<String> lines = content.split('\n');

for (String line in lines) {
List<String> keyVal = line.split('=');
if (keyVal.length == 2) {
String key = keyVal[0].trim();
dynamic value = keyVal[1].trim();
configMap[key] = value;
}
}
_config = configMap;
}

static Future<void> setBuildDirectory(String dir) async {
await _loadJsonAsset();
final assetsDir = '$dir/unit_test_assets';

if (!(await Directory('$assetsDir/$testBinDir').exists())) {
if (!(await Directory('$assetsDir/$libName').exists())) {
try {
final response = await http.get(Uri.parse(remoteUrl));
if (response.statusCode == 200) {
Expand All @@ -74,6 +82,7 @@ class AppConfig {
}
}

static String get remoteUrl => _config!['remote_url'];
static String get testBinDir => _config!['test_bin_dir'];
static String get libName => "unittest.bdk.${_config!['TAG_VERSION']}";
static String get remoteUrl =>
"${_config!['REPOSITORY_URL']}${_config!['TAG_VERSION']}/$libName.zip";
}
34 changes: 34 additions & 0 deletions macos/bdk_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@ if [ ! -d #{frameworks_dir} ]; then
fi
`

read_key_value_pairs = lambda do |file_path|
pairs = {}
File.foreach(file_path) do |line|
key, value = line.chomp.split('=')
pairs[key] = value
end
pairs
end
podspec_dir = File.dirname(__FILE__)
assets_dir = File.join(podspec_dir, '..', 'assets')
config_file_path = File.join(assets_dir, 'release.config.txt')
config = read_key_value_pairs.call(config_file_path)

tag_version = "#{config['TAG_VERSION']}"
framework = 'rust_bdk_ffi.xcframework'
lib_name = "bdk.#{tag_version}"
url = "#{config['REPOSITORY_URL']}#{tag_version}/#{lib_name}.zip"
frameworks_dir = "macos"


`
cd ../
if [ ! -d #{lib_name} ]; then
curl -L #{url} -o #{lib_name}.zip
unzip #{lib_name}.zip
rm -rf __MACOSX
rm #{lib_name}.zip
fi
if [ ! -d #{frameworks_dir}/#{framework} ]; then
cp -R #{lib_name}/#{framework} #{frameworks_dir}
fi
`

Pod::Spec.new do |s|
s.name = 'bdk_flutter'
s.version = '0.29.3'
Expand Down
29 changes: 29 additions & 0 deletions rust/android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Setup
BUILD_DIR=bdk.0.29.3
mkdir -p $BUILD_DIR
cd $BUILD_DIR

# Create the jniLibs build directory
JNI_DIR=jniLibs
mkdir -p $JNI_DIR

# Set up cargo-ndk
cargo install cargo-ndk
rustup target add \
aarch64-linux-android \
armv7-linux-androideabi \
x86_64-linux-android \
i686-linux-android

# Build the android libraries in the jniLibs directory
cargo ndk -o $JNI_DIR \
--manifest-path ../Cargo.toml \
-t armeabi-v7a \
-t arm64-v8a \
-t x86 \
-t x86_64 \
build --release


7 changes: 4 additions & 3 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use lib_flutter_rust_bridge_codegen::{
const RUST_INPUT: &str = "src/r_api.rs";
/// Path of output generated Dart code
const DART_OUTPUT: &str = "../lib/src/generated/bindings.dart";
const DARWIN_OUTPUT: &str = "../darwin/Classes/bindings.h";
const IOS_OUTPUT: &str = "../ios/Classes/bindings.h";
const MACOS_OUTPUT: &str = "../macos/Classes/";
const DECL_OUTPUT: &str = "../lib/src/generated/bridge_definitions.dart";

fn main() {
Expand All @@ -25,8 +26,8 @@ fn main() {
// for other options use defaults
wasm: false,
dart_decl_output: Some(DECL_OUTPUT.into()),

c_output: Some(vec![DARWIN_OUTPUT.to_string()]),
c_output: Some(vec![IOS_OUTPUT.to_string()]),
extra_c_output_path: Some(vec![MACOS_OUTPUT.to_string()]),
inline_rust: true,
dart_format_line_length: 120,

Expand Down
9 changes: 9 additions & 0 deletions rust/compress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

for TARGET in \
bdk.0.29.3 unittest.bdk.0.29.3
do
zip -r $TARGET.zip $TARGET
done
rm unittest.bdk.0.29.3

14 changes: 8 additions & 6 deletions rust/copy.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
if [ -d "../android/src/main/jniLibs" ]; then rm -r ../android/src/main/jniLibs
fi
if [ -d "../frameworks/rust_bdk_ffi.xcframework" ]; then rm -r ../frameworks/rust_bdk_ffi.xcframework
if [ -d "../ios/rust_bdk_ffi.xcframework" ]; then rm -r ../ios/rust_bdk_ffi.xcframework
fi
if [ -d "../macos/rust_bdk_ffi.xcframework" ]; then rm -r ../macos/rust_bdk_ffi.xcframework
fi

mkdir -p ../android/src/main/jniLibs/arm64-v8a
mkdir -p ../android/src/main/jniLibs/armeabi-v7a
mkdir -p ../android/src/main/jniLibs/x86
mkdir -p ../android/src/main/jniLibs/x86_86

cp target/aarch64-linux-android/release/librust_bdk_ffi.so ../android/src/main/jniLibs/arm64-v8a
cp target/armv7-linux-androideabi/release/librust_bdk_ffi.so ../android/src/main/jniLibs/armeabi-v7a
cp target/i686-linux-android/release/librust_bdk_ffi.so ../android/src/main/jniLibs/x86
cp -r platform-build/rust_bdk_ffi.xcframework ../frameworks
cd platform-build
zip -r ../bdk_bin_0.29.3.zip bdk_bin_0.29.3
cd ../
rm -rf platform-build
cp target/x86_64-linux-android/release/librust_bdk_ffi.so ../android/src/main/jniLibs/x86_86
cp -r bdk.0.29.3/rust_bdk_ffi.xcframework ../macos/
cp -r bdk.0.29.3/rust_bdk_ffi.xcframework ../macos/



15 changes: 5 additions & 10 deletions rust/darwin.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Setup
BUILD_DIR=platform-build
mkdir $BUILD_DIR
BUILD_DIR=bdk.0.29.3
mkdir -p $BUILD_DIR
cd $BUILD_DIR

# Build static libs
Expand All @@ -17,12 +17,12 @@ done
# Create XCFramework zip
FRAMEWORK="rust_bdk_ffi.xcframework"
LIBNAME=librust_bdk_ffi.a
TEST_LIBNAME=librust_bdk_ffi.dylib
mkdir -p mac-lipo ios-sim-lipo bdk_bin_0.29.3/macos/

mkdir -p mac-lipo ios-sim-lipo

IOS_SIM_LIPO=ios-sim-lipo/$LIBNAME
MAC_LIPO=mac-lipo/$LIBNAME
MAC_TEST_LIPO=bdk_bin_0.29.3/macos/$TEST_LIBNAME


lipo -create -output $IOS_SIM_LIPO \
../target/aarch64-apple-ios-sim/release/$LIBNAME \
Expand All @@ -31,16 +31,11 @@ lipo -create -output $MAC_LIPO \
../target/aarch64-apple-darwin/release/$LIBNAME \
../target/x86_64-apple-darwin/release/$LIBNAME

lipo -create -output $MAC_TEST_LIPO \
../target/aarch64-apple-darwin/release/$TEST_LIBNAME \
../target/x86_64-apple-darwin/release/$TEST_LIBNAME

xcodebuild -create-xcframework \
-library $IOS_SIM_LIPO \
-library $MAC_LIPO \
-library ../target/aarch64-apple-ios/release/$LIBNAME \
-output $FRAMEWORK


## Cleanup
rm -rf ios-sim-lipo mac-lipo
Loading

0 comments on commit cd3c570

Please sign in to comment.