Skip to content

Use cargokit for builds and generate Rust->C FFI bindings #60

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

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
98392ee
test: create_seed()
sneurlax Feb 6, 2025
ff106fc
test: mnemonic()
sneurlax Feb 6, 2025
3e220da
test: _get_mnemonic
sneurlax Feb 6, 2025
ab8cd00
test: test mnemonic uniqueness and reversibility
sneurlax Feb 6, 2025
f049095
test: specific known mnemonic->seed vector
sneurlax Feb 6, 2025
dad8727
chore: initial & WIP library refactor/reorganization
sneurlax Feb 6, 2025
b9fc4f1
chore: remove unused imports
sneurlax Feb 6, 2025
af703f0
test: add mnemonic tests
sneurlax Feb 7, 2025
d8d1e72
chore: WIP library refactor/reorganization, split wallet.rs out
sneurlax Feb 7, 2025
443f379
chore: WIP library refactor/reorganization, split listener.rs out
sneurlax Feb 7, 2025
e0c24d5
chore: WIP library refactor/reorganization, split wallet.rs out
sneurlax Feb 7, 2025
c3ca9b4
feat: library refactor/reorganization, split fns into separate files
sneurlax Feb 7, 2025
7e088fb
test: add more tests
sneurlax Feb 11, 2025
dabcab7
docs: comments throughout
sneurlax Feb 11, 2025
803a9e5
chore: import/clippy-cleanup (warning suppression)
sneurlax Feb 11, 2025
0613327
test: add more tests
sneurlax Feb 11, 2025
6bbae78
feat: add and navigate to wallet info view in example app as appropriate
sneurlax Feb 11, 2025
a7b69ca
feat: add wallet deletion icon and functionality to example app
sneurlax Feb 11, 2025
e4cf5df
feat: fix various bugs surrounding navigating while creating a wallet
sneurlax Feb 12, 2025
7f8a861
feat: move advanced functions view into wallet info view
sneurlax Feb 12, 2025
fd5e2d9
build!: remove lib link in linux example app cmakelists
sneurlax Feb 18, 2025
0e80393
Squashed 'cargokit/' content from commit 918f280
sneurlax Feb 18, 2025
4f3942a
Merge commit '0e8039303c9c7f3b0a9161bd3b4af378ac7cecfd' as 'cargokit'
sneurlax Feb 18, 2025
f592db4
docs: document cargokit updates
sneurlax Feb 18, 2025
cd45c83
build: WIP macos cargokit integration
sneurlax Feb 18, 2025
70ebb12
build: WIP ios cargokit integration
sneurlax Feb 18, 2025
98e6c6c
build: WIP linux cargokit integration
sneurlax Feb 18, 2025
a94d893
build: WIP windows cargokit integration
sneurlax Feb 18, 2025
0f499f2
build: WIP android cargokit integration
sneurlax Feb 18, 2025
a1d6e7f
fix: standardize crate and lib names
sneurlax Feb 18, 2025
b350dde
docs: add license, credit authors
sneurlax Mar 17, 2025
40a14e5
feat: automatically generate C bindings for Rust and document manual gen
sneurlax Mar 17, 2025
98f86f3
fix: update path to debug/test lib
sneurlax Mar 17, 2025
9c98c34
docs: document submodule initialization
sneurlax Mar 17, 2025
60d963d
fix: list cbindgen, glob build dependencies
sneurlax Mar 17, 2025
faf6a66
fix: cargokit gradle reference in example
sneurlax Mar 17, 2025
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
17 changes: 16 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
TODO: Add your license here.
Copyright 2025 Cypher Stack LLC

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.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# `flutter_libepiccash`
## Submodules
Initialize submodules:
```sh
git submodule update --init --recursive
```

## Dependencies
### Rust
Install Rust: https://www.rust-lang.org/tools/install
Expand Down Expand Up @@ -61,10 +67,7 @@ cargo install cbindgen
```

## Build
```sh
cd scripts/ios
./build_all
```
Builds are automatically triggered upon a Flutter build using [cargokit](https://github.com/irondash/cargokit) (see [this guide](https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/)).

# Windows
## Dependencies
Expand All @@ -73,10 +76,18 @@ Run `scripts/windows/deps.sh` in WSL (may need to alter permissions like with `c
sudo apt-get install clang gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
```

## Building for Windows
Run `scripts/windows/build_all.sh`

Libraries will be output to `scripts/windows/build`

## Building on Windows
`build_all.ps1` is not confirmed working and may need work eg. may need some missing dependencies added but has been included as a starting point or example for Windows users

# Development
## Cargokit
Cargokit may be updated using:
```sh
git subtree pull --prefix cargokit https://github.com/irondash/cargokit.git main --squash
```
in the plugin root.

## Bindings generation
To generate `epic_cash_wallet.h` C bindings for Rust, `cbindgen --config cbindgen.toml --crate epic_cash_wallet --output target/epic_cash_wallet.h` or `cargo build` in `rust` to produce headers according to `build.rs`.

[//]: # (To generate `epic_cash_bindings_generated.dart` Dart bindings for C, `flutter pub run ffigen --config ffigen.yaml`.)
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 "[email protected]"
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_11_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.

58 changes: 58 additions & 0 deletions cargokit/build_pod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh
set -e

BASEDIR=$(dirname "$0")

# Workaround for https://github.com/dart-lang/pub/issues/4010
BASEDIR=$(cd "$BASEDIR" ; pwd -P)

# Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project
NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"`

export PATH=${NEW_PATH%?} # remove trailing :

env

# Platform name (macosx, iphoneos, iphonesimulator)
export CARGOKIT_DARWIN_PLATFORM_NAME=$PLATFORM_NAME

# Arctive architectures (arm64, armv7, x86_64), space separated.
export CARGOKIT_DARWIN_ARCHS=$ARCHS

# Current build configuration (Debug, Release)
export CARGOKIT_CONFIGURATION=$CONFIGURATION

# Path to directory containing Cargo.toml.
export CARGOKIT_MANIFEST_DIR=$PODS_TARGET_SRCROOT/$1

# Temporary directory for build artifacts.
export CARGOKIT_TARGET_TEMP_DIR=$TARGET_TEMP_DIR

# Output directory for final artifacts.
export CARGOKIT_OUTPUT_DIR=$PODS_CONFIGURATION_BUILD_DIR/$PRODUCT_NAME

# Directory to store built tool artifacts.
export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool

# Directory inside root project. Not necessarily the top level directory of root project.
export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT

FLUTTER_EXPORT_BUILD_ENVIRONMENT=(
"$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS
"$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS
)

for path in "${FLUTTER_EXPORT_BUILD_ENVIRONMENT[@]}"
do
if [[ -f "$path" ]]; then
source "$path"
fi
done

sh "$BASEDIR/run_build_tool.sh" build-pod "$@"

# Make a symlink from built framework to phony file, which will be used as input to
# build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate
# attribute on custom build phase)
ln -fs "$OBJROOT/XCBuildData/build.db" "${BUILT_PRODUCTS_DIR}/cargokit_phony"
ln -fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony_out"
2 changes: 2 additions & 0 deletions cargokit/build_tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.
31 changes: 31 additions & 0 deletions cargokit/build_tool/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

linter:
rules:
- prefer_relative_imports
- directives_ordering

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
5 changes: 5 additions & 0 deletions cargokit/build_tool/bin/build_tool.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:build_tool/build_tool.dart' as build_tool;

void main(List<String> arguments) {
build_tool.runMain(arguments);
}
5 changes: 5 additions & 0 deletions cargokit/build_tool/lib/build_tool.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'src/build_tool.dart' as build_tool;

Future<void> runMain(List<String> args) async {
return build_tool.runMain(args);
}
Loading