Skip to content

Commit 0153c8e

Browse files
authored
feat(flutter/catalyst_key_derivation): Setup for flutter_rust_bridge in catalyst_key_derivation package (#1054)
* feat: key derivation in rust bridge * feat: convert to async (wip) * chore: remove unused stuff * chore: update rust sample to block main thread, generate code * docs: add example how to run the app * docs: fix how to instructions * chore: drop unused files * chore: drop unused files * chore: add script * chore: fix script * chore: fix script * chore: run heave computation in a thread pool * chore: cleanup code, extract dependencies, add docs * chore: cleanup * chore: ignore pubspec.lock * chore: ignore pubspec.lock * chore: fix spelling * chore: fix markdown * chore: temporarily disable publishing for catalyst_key_derivation package
1 parent 91335f7 commit 0153c8e

File tree

187 files changed

+7430
-767
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+7430
-767
lines changed

.config/dictionaries/project.dic

+13-1
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,16 @@ xctestrun
303303
xcworkspace
304304
xvfb
305305
yoroi
306-
Pbkdf2
306+
Pbkdf2
307+
Embedder
308+
Podspec
309+
podspec
310+
ARCHS
311+
iphonesimulator
312+
cargokit
313+
SRCROOT
314+
libcatalyst
315+
staticlib
316+
addrof
317+
Lifetimeable
318+
cbindgen

.markdownlint-cli2.jsonc

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"catalyst-gateway/target/**",
1313
"CHANGELOG.md",
1414
"catalyst_voices_packages/**/CHANGELOG.md",
15+
"catalyst_voices_packages/**/cargokit/**",
1516
"catalyst_voices/macos/Pods/**",
1617
"**/node_modules/**",
1718
"**/.dart_tool/**"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
**/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
build/
30+
/web/pkg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "5874a72aa4c779a02553007c47dacbefba2374dc"
8+
channel: "stable"
9+
10+
project_type: plugin_ffi
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
17+
base_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
18+
- platform: android
19+
create_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
20+
base_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
21+
- platform: ios
22+
create_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
23+
base_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
24+
- platform: macos
25+
create_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
26+
base_revision: 5874a72aa4c779a02553007c47dacbefba2374dc
27+
28+
# User provided section
29+
30+
# List of Local paths (relative to this file) that should be
31+
# ignored by the migrate tool.
32+
#
33+
# Files that are not part of the templates will be ignored by default.
34+
unmanaged_files:
35+
- 'lib/main.dart'
36+
- 'ios/Runner.xcodeproj/project.pbxproj'

catalyst_voices_packages/catalyst_key_derivation/catalyst_key_derivation/README.md catalyst_voices_packages/catalyst_key_derivation/README.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* [Features](#features)
55
* [Requirements](#requirements)
66
* [Install](#install)
7-
* [Web setup](#web-setup)
7+
* [How to run](#how-to-run)
88
* [Example](#example)
99
* [Support](#support)
1010
* [License](#license)
@@ -23,16 +23,12 @@ This package exposes a CIP-1852 Cardano HD Key Derivation.
2323
```yaml
2424
dependencies:
2525
catalyst_key_derivation: any # or the latest version on Pub
26-
catalyst_key_derivation_web: any # or the latest version on Pub
2726
```
2827
29-
## Web setup
28+
## How to run
3029
31-
Add the following line at the end of `<head>` section in web/index.html:
32-
33-
```html
34-
<script type="module" src="/assets/packages/catalyst_key_derivation_web/assets/js/catalyst_key_derivation.js"></script>
35-
```
30+
1. cd catalyst_key_derivation
31+
2. ./run.sh
3632
3733
## Example
3834
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include: package:catalyst_analysis/analysis_options.yaml
2+
3+
analyzer:
4+
exclude: [build/**, lib/*.g.dart, lib/generated/**, lib/src/rust/**]
5+
errors:
6+
public_member_api_docs: ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// The Android Gradle Plugin builds the native code with the Android NDK.
2+
3+
group 'com.flutter_rust_bridge.catalyst_key_derivation'
4+
version '1.0'
5+
6+
buildscript {
7+
repositories {
8+
google()
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
// The Android Gradle Plugin knows how to build native code with the NDK.
14+
classpath 'com.android.tools.build:gradle:7.3.0'
15+
}
16+
}
17+
18+
rootProject.allprojects {
19+
repositories {
20+
google()
21+
mavenCentral()
22+
}
23+
}
24+
25+
apply plugin: 'com.android.library'
26+
27+
android {
28+
if (project.android.hasProperty("namespace")) {
29+
namespace 'com.flutter_rust_bridge.catalyst_key_derivation'
30+
}
31+
32+
// Bumping the plugin compileSdkVersion requires all clients of this plugin
33+
// to bump the version in their app.
34+
compileSdkVersion 33
35+
36+
// Use the NDK version
37+
// declared in /android/app/build.gradle file of the Flutter project.
38+
// Replace it with a version number if this plugin requires a specific NDK version.
39+
// (e.g. ndkVersion "23.1.7779620")
40+
ndkVersion android.ndkVersion
41+
42+
compileOptions {
43+
sourceCompatibility JavaVersion.VERSION_1_8
44+
targetCompatibility JavaVersion.VERSION_1_8
45+
}
46+
47+
defaultConfig {
48+
minSdkVersion 19
49+
}
50+
}
51+
52+
apply from: "../cargokit/gradle/plugin.gradle"
53+
cargokit {
54+
manifestDir = "../rust"
55+
libname = "catalyst_key_derivation"
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'catalyst_key_derivation'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.flutter_rust_bridge.catalyst_key_derivation">
3+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
.dart_tool
3+
*.iml
4+
!pubspec.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
Copyright 2022 Matej Knopp
5+
6+
================================================================================
7+
8+
MIT LICENSE
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14+
of the Software, and to permit persons to whom the Software is furnished to do
15+
so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
23+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
25+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
================================================================================
28+
29+
APACHE LICENSE, VERSION 2.0
30+
31+
Licensed under the Apache License, Version 2.0 (the "License");
32+
you may not use this file except in compliance with the License.
33+
You may obtain a copy of the License at
34+
35+
http://www.apache.org/licenses/LICENSE-2.0
36+
37+
Unless required by applicable law or agreed to in writing, software
38+
distributed under the License is distributed on an "AS IS" BASIS,
39+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40+
See the License for the specific language governing permissions and
41+
limitations under the License.
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
Experimental repository to provide glue for seamlessly integrating cargo build
5+
with flutter plugins and packages.
6+
7+
See https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/
8+
for a tutorial on how to use Cargokit.
9+
10+
Example plugin available at https://github.com/irondash/hello_rust_ffi_plugin.
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
set -e
3+
4+
BASEDIR=$(dirname "$0")
5+
6+
# Workaround for https://github.com/dart-lang/pub/issues/4010
7+
BASEDIR=$(cd "$BASEDIR" ; pwd -P)
8+
9+
# Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project
10+
NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"`
11+
12+
export PATH=${NEW_PATH%?} # remove trailing :
13+
14+
env
15+
16+
# Platform name (macosx, iphoneos, iphonesimulator)
17+
export CARGOKIT_DARWIN_PLATFORM_NAME=$PLATFORM_NAME
18+
19+
# Arctive architectures (arm64, armv7, x86_64), space separated.
20+
export CARGOKIT_DARWIN_ARCHS=$ARCHS
21+
22+
# Current build configuration (Debug, Release)
23+
export CARGOKIT_CONFIGURATION=$CONFIGURATION
24+
25+
# Path to directory containing Cargo.toml.
26+
export CARGOKIT_MANIFEST_DIR=$PODS_TARGET_SRCROOT/$1
27+
28+
# Temporary directory for build artifacts.
29+
export CARGOKIT_TARGET_TEMP_DIR=$TARGET_TEMP_DIR
30+
31+
# Output directory for final artifacts.
32+
export CARGOKIT_OUTPUT_DIR=$PODS_CONFIGURATION_BUILD_DIR/$PRODUCT_NAME
33+
34+
# Directory to store built tool artifacts.
35+
export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool
36+
37+
# Directory inside root project. Not necessarily the top level directory of root project.
38+
export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT
39+
40+
FLUTTER_EXPORT_BUILD_ENVIRONMENT=(
41+
"$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS
42+
"$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS
43+
)
44+
45+
for path in "${FLUTTER_EXPORT_BUILD_ENVIRONMENT[@]}"
46+
do
47+
if [[ -f "$path" ]]; then
48+
source "$path"
49+
fi
50+
done
51+
52+
sh "$BASEDIR/run_build_tool.sh" build-pod "$@"
53+
54+
# Make a symlink from built framework to phony file, which will be used as input to
55+
# build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate
56+
# attribute on custom build phase)
57+
ln -fs "$OBJROOT/XCBuildData/build.db" "${BUILT_PRODUCTS_DIR}/cargokit_phony"
58+
ln -fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony_out"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pubspec.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
A sample command-line application with an entrypoint in `bin/`, library code
5+
in `lib/`, and example unit test in `test/`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This is copied from Cargokit (which is the official way to use it currently)
2+
# Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
# This file configures the static analysis results for your project (errors,
5+
# warnings, and lints).
6+
#
7+
# This enables the 'recommended' set of lints from `package:lints`.
8+
# This set helps identify many issues that may lead to problems when running
9+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
10+
# style and format.
11+
#
12+
# If you want a smaller set of lints you can change this to specify
13+
# 'package:lints/core.yaml'. These are just the most critical lints
14+
# (the recommended set includes the core lints).
15+
# The core lints are also what is used by pub.dev for scoring packages.
16+
17+
include: package:lints/recommended.yaml
18+
19+
# Uncomment the following section to specify additional rules.
20+
21+
linter:
22+
rules:
23+
- prefer_relative_imports
24+
- directives_ordering
25+
26+
# analyzer:
27+
# exclude:
28+
# - path/to/excluded/files/**
29+
30+
# For more information about the core and recommended set of lints, see
31+
# https://dart.dev/go/core-lints
32+
33+
# For additional information about configuring this file, see
34+
# https://dart.dev/guides/language/analysis-options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
import 'package:build_tool/build_tool.dart' as build_tool;
5+
6+
void main(List<String> arguments) {
7+
build_tool.runMain(arguments);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
import 'src/build_tool.dart' as build_tool;
5+
6+
Future<void> runMain(List<String> args) async {
7+
return build_tool.runMain(args);
8+
}

0 commit comments

Comments
 (0)