Skip to content
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ doc/api/
rust/target/

.idea/

example/macos/Flutter/ephemeral/flutter_export_environment.sh

example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig

example/windows/flutter/ephemeral/.plugin_symlinks/monero

example/linux/flutter/ephemeral/

example/ios/Flutter/Generated.xcconfig

example/ios/Flutter/flutter_export_environment.sh
42 changes: 42 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "465e421f53c05f8f33f83a243c10c55f9f6efbc2"
channel: "beta"

project_type: plugin_ffi

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
base_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
- platform: android
create_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
base_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
- platform: ios
create_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
base_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
- platform: linux
create_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
base_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
- platform: macos
create_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
base_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
- platform: windows
create_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2
base_revision: 465e421f53c05f8f33f83a243c10c55f9f6efbc2

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.0.6

- Migrated from native_toolchain_rust to cargokit for Android/iOS support.
- Fixed Android build: resolved OpenSSL dependency issue by using rustls-tls in monero-serai-mirror.
- Added Cargo [replace] directive to use local serai-mirror with Android-compatible TLS backend.
- Requires serai-mirror at `../serai-mirror` with `fix/android-serai` branch for Android builds.

## 0.0.5

- Commandline interface builds Monero from source by default.
Expand Down
64 changes: 29 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
# `monero`
## Library
This is a library for using Monero in Dart. It uses `monero-rust`, whose cargo
build is integrated into the Dart build process by
[`native_toolchain_rust`](https://pub.dev/packages/native_toolchain_rust).
This is a library for using Monero in Dart. It uses `monero-rust`, whose cargo
build is integrated into the Dart build process by
[cargokit](https://github.com/irondash/cargokit).

## Commandline interface (CLI)
The `bin` folder contains a tool for setting up the latest Monero release by
either building it from source (by default) and/or downloading and verifying
binary release archives. This tool is separate from the library and its use
is optional. Its purpose is to set up a Monero node and (optionally) a wallet
RPC server for testing and developing the library. It can be installed as in:
```
dart pub global activate monero
```
## Setup
### Dependencies

and used it as in:
```
monero --help
```
#### Version Requirements
- **Dart SDK**: ^3.10.0-162.1.beta
- **Flutter**: >=3.3.0 (tested with 3.37.0-0.1.pre beta)
- **Rust**: 1.75+ (tested with 1.90.0)

## Setup
### Dart 3.6
The library requires Dart 3.6 for its native assets feature.
#### Repository Dependencies
This library requires the following sibling repositories for building:

### Native assets
Native assets is currently an experimental feature that is available in
Flutter's `master` branch behind an optional Flutter config. Enable it as in:
1. **monero-rust** - Must be located at `../monero-rust` relative to this project.
2. **serai-mirror** - Must be located at `../serai-mirror` relative to this project.
- **Important for Android builds**: Must be on the `fix/android-serai` branch.
- This branch contains a patch to use rustls-tls instead of native-tls for Android compatibility.
- The Rust build uses a `[replace]` directive to substitute the published monero-serai-mirror with this local version.

Directory structure:
```
flutter config --enable-native-assets
parent-dir/
├── monero-dart-cargokit/ (this project)
├── monero-rust/ (required)
└── serai-mirror/ (required, branch: fix/android-serai)
```

See [this tracking issue](https://github.com/flutter/flutter/issues/129757) and
[this milestone](https://github.com/dart-lang/native/milestone/15) for the
eventual inclusion of native assets in a release.

### Quick start
With Dart ^3.6 installed and set as the default:
```
git clone git@github.com:ManyMath/monerodart
cd monerodart
dart pub get
dart --enable-experiment=native-assets run example/monero.dart
git clone git@github.com:ManyMath/monero-dart
git clone git@github.com:ManyMath/monero-rust
git clone -b fix/android-serai git@github.com:ManyMath/serai-mirror
cd monero-dart/example
flutter pub get
flutter run -d <device>
```
and wait a moment as the native assets are built.

## Development
- To generate `monero-rust_bindings_generated.dart` Dart bindings for C:
```
dart --enable-experiment=native-assets run ffigen --config ffigen.yaml
dart run ffigen --config ffigen.yaml
```
- If bindings are generated for a new (not previously supported/included in
`lib/monero_base.dart`) function, a wrapper must be written for it by hand
Expand Down
5 changes: 4 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include: package:lints/recommended.yaml
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
9 changes: 9 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
54 changes: 54 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// The Android Gradle Plugin builds the native code with the Android NDK.

group = "com.example.monero"
version = "1.0"

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
// The Android Gradle Plugin knows how to build native code with the NDK.
classpath("com.android.tools.build:gradle:8.9.1")
}
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: "com.android.library"
apply from: "../cargokit/gradle/plugin.gradle"

android {
namespace = "com.example.monero"

// Bumping the plugin compileSdk version requires all clients of this plugin
// to bump the version in their app.
compileSdk = 36

// Use the NDK version
// declared in /android/app/build.gradle file of the Flutter project.
// Replace it with a version number if this plugin requires a specific NDK version.
// (e.g. ndkVersion "23.1.7779620")
ndkVersion = android.ndkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

defaultConfig {
minSdk = 24
}
}

cargokit {
libname = "monero"
manifestDir = "../rust"
}
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'monero'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.monero">
</manifest>
26 changes: 26 additions & 0 deletions cargokit/.github/workflows/check_and_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
pull_request:
push:
branches:
- main

name: Check and Lint

jobs:
Flutter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # 4.1.0
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
- name: Pub Get
run: dart pub get --no-precompile
working-directory: build_tool
- name: Dart Format
run: dart format . --output=none --set-exit-if-changed
working-directory: build_tool
- name: Analyze
run: dart analyze
working-directory: build_tool
- name: Test
run: flutter test
working-directory: build_tool
86 changes: 86 additions & 0 deletions cargokit/.github/workflows/test_example_plugin_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
on:
pull_request:
push:
branches:
- main

name: Test Example Plugin

jobs:
Build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
build_mode:
- debug
- profile
- release
env:
EXAMPLE_DIR: "a b/hello_rust_ffi_plugin/example"
CARGOKIT_VERBOSE: 1
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Setup Repository
shell: bash
run: |
mkdir "a b" # Space is intentional
cd "a b"
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
# "advanced" branch has extra iOS flavor and uses rust nightly for release builds
git clone -b advanced https://github.com/irondash/hello_rust_ffi_plugin
cd hello_rust_ffi_plugin
git subtree pull --prefix cargokit https://github.com/${{ github.event.pull_request.head.repo.full_name || github.repository }} ${{ steps.extract_branch.outputs.branch }} --squash
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
with:
channel: "stable"
- name: Install GTK
if: (matrix.os == 'ubuntu-latest')
run: sudo apt-get update && sudo apt-get install libgtk-3-dev
- name: Install ninja-build
if: (matrix.os == 'ubuntu-latest')
run: sudo apt-get update && sudo apt-get install ninja-build
- name: Build Linux (${{ matrix.build_mode }})
if: matrix.os == 'ubuntu-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build linux --${{ matrix.build_mode }} -v
- name: Build macOS (${{ matrix.build_mode }})
if: matrix.os == 'macos-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build macos --${{ matrix.build_mode }} -v
- name: Build iOS (${{ matrix.build_mode }})
if: matrix.os == 'macos-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build ios --${{ matrix.build_mode }} --no-codesign -v
- name: Build iOS (${{ matrix.build_mode }}) - flavor1
if: matrix.os == 'macos-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build ios --flavor flavor1 --${{ matrix.build_mode }} --no-codesign -v
- name: Build Windows (${{ matrix.build_mode }})
if: matrix.os == 'windows-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build windows --${{ matrix.build_mode }} -v
- name: Build Android (${{ matrix.build_mode }})
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: |
if [[ $(sysctl hw.optional.arm64) == *"hw.optional.arm64: 1"* ]]; then
export JAVA_HOME=$JAVA_HOME_17_arm64
else
export JAVA_HOME=$JAVA_HOME_17_X64
fi
flutter build apk --${{ matrix.build_mode }} -v

4 changes: 4 additions & 0 deletions cargokit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
.dart_tool
*.iml
!pubspec.lock
39 changes: 39 additions & 0 deletions cargokit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Copyright 2022 Matej Knopp

================================================================================

MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

================================================================================

APACHE LICENSE, VERSION 2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

8 changes: 8 additions & 0 deletions cargokit/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Experimental repository to provide glue for seamlessly integrating cargo build
with flutter plugins and packages.

See https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/
for a tutorial on how to use Cargokit.

Example plugin available at https://github.com/irondash/hello_rust_ffi_plugin.

Loading