diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41cc7d81..599c4cf6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## 0.1.0
+
+* Build the Rust core with Flutter native assets instead of cargokit.
+ Requires Flutter 3.47.2 or later, `rustup` on the build machine, and
+ NDK 27 or later for Android.
+* Remove `NotSupportedPlatform`; `Tor.throwRustException` no longer takes
+ a bindings argument.
+* Fix `Tor.start` never detecting a failed `tor_start`.
+
## 0.0.1
* TODO: Describe initial release.
diff --git a/README.md b/README.md
index fb7cf4fb..be6d0ea4 100644
--- a/README.md
+++ b/README.md
@@ -12,30 +12,19 @@ SPDX-License-Identifier: GPL-3.0-or-later
### [Install rust](https://www.rust-lang.org/tools/install)
-Use `rustup`, not `homebrew`. Install toolchain 1.74.
+Use `rustup`, not `homebrew`. The toolchain and cross-compilation targets pinned in `rust/rust-toolchain.toml` are installed automatically on first build.
-### Install cargo ndk
+### Building
-```sh
-cargo install cargo-ndk
-```
-
-### Cargokit
-
-[Cargokit](https://github.com/irondash/cargokit) handles building, just `flutter run` it or run it in Android Studio or VS Code (untested).
-
-To update Cargokit in the future, use:
-```sh
-git subtree pull --prefix cargokit https://github.com/irondash/cargokit.git main --squash
-```
+The Rust library is built and bundled by Flutter's native assets support (see `hook/build.dart`), so just `flutter run` or build as usual. Requires Flutter 3.47.2 or later; Android builds need NDK 27 or later.
## Development
-To generate `tor_ffi_plugin.h` C bindings for Rust, `cbindgen --config cbindgen.toml --crate tor-ffi --output target/tor_ffi_plugin.h` or `cargo build` in `native/tor-ffi` to produce headers according to `build.rs`.
-To generate `tor_bindings_generated.dart` Dart bindings for C, `flutter pub run ffigen --config ffigen.yaml`. You will probably need to manually edit the `Tor` class to be `final`.
+To generate `tor_ffi_plugin.h` C bindings for Rust, `cargo build` in `rust` to produce headers according to `build.rs`.
+To generate `tor_ffi_plugin_bindings_generated.dart` Dart bindings for C, `dart run ffigen --config ffigen.yaml`.
## Example app
`flutter run` in `example` to run the example app
-See `example/lib/main.dart` for usage. Must run the build script for your platform first.
+See `example/lib/main.dart` for usage.
diff --git a/analysis_options.yaml b/analysis_options.yaml
index a5744c1c..e46654b9 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,3 +1,6 @@
+analyzer:
+ exclude:
+ - build/**
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
diff --git a/android/.gitignore b/android/.gitignore
deleted file mode 100644
index 161bdcda..00000000
--- a/android/.gitignore
+++ /dev/null
@@ -1,9 +0,0 @@
-*.iml
-.gradle
-/local.properties
-/.idea/workspace.xml
-/.idea/libraries
-.DS_Store
-/build
-/captures
-.cxx
diff --git a/android/build.gradle b/android/build.gradle
deleted file mode 100644
index b12d70e0..00000000
--- a/android/build.gradle
+++ /dev/null
@@ -1,77 +0,0 @@
-// The Android Gradle Plugin builds the native code with the Android NDK.
-
-group 'com.cypherstack.tor_ffi_plugin'
-version '1.0'
-
-buildscript {
- ext.kotlin_version = '1.8.0'
- repositories {
- google()
- mavenCentral()
- }
-
- dependencies {
- classpath("com.android.tools.build:gradle:8.1.0")
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
- }
-}
-
-allprojects {
- repositories {
- google()
- mavenCentral()
- }
-}
-
-apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android'
-
-android {
- if (project.android.hasProperty("namespace")) {
- namespace 'com.cypherstack.tor_ffi_plugin'
- }
-
- compileSdk = 34
-
- compileOptions {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
- }
-
- kotlinOptions {
- jvmTarget = JavaVersion.VERSION_1_8
- }
-
- sourceSets {
- main.java.srcDirs += "src/main/kotlin"
- test.java.srcDirs += "src/test/kotlin"
- }
-
- defaultConfig {
- minSdk = 21
- }
-
- dependencies {
- testImplementation("org.jetbrains.kotlin:kotlin-test")
- testImplementation("org.mockito:mockito-core:5.0.0")
- }
-
- testOptions {
- unitTests.all {
- useJUnitPlatform()
-
- testLogging {
- events "passed", "skipped", "failed", "standardOut", "standardError"
- outputs.upToDateWhen {false}
- showStandardStreams = true
- }
- }
- }
-}
-
-apply from: "../cargokit/gradle/plugin.gradle"
-
-cargokit {
- manifestDir = "../rust"
- libname = "tor_ffi_plugin"
-}
\ No newline at end of file
diff --git a/android/settings.gradle b/android/settings.gradle
deleted file mode 100644
index 92109959..00000000
--- a/android/settings.gradle
+++ /dev/null
@@ -1 +0,0 @@
-rootProject.name = 'tor_ffi_plugin'
diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
deleted file mode 100644
index 99163d87..00000000
--- a/android/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
diff --git a/cargokit/.github/workflows/check_and_lint.yml b/cargokit/.github/workflows/check_and_lint.yml
deleted file mode 100644
index d8979f0e..00000000
--- a/cargokit/.github/workflows/check_and_lint.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-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
diff --git a/cargokit/.github/workflows/test_example_plugin_build.yml b/cargokit/.github/workflows/test_example_plugin_build.yml
deleted file mode 100644
index fb975384..00000000
--- a/cargokit/.github/workflows/test_example_plugin_build.yml
+++ /dev/null
@@ -1,86 +0,0 @@
-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
-
diff --git a/cargokit/.gitignore b/cargokit/.gitignore
deleted file mode 100644
index cf7bb868..00000000
--- a/cargokit/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-target
-.dart_tool
-*.iml
-!pubspec.lock
diff --git a/cargokit/LICENSE b/cargokit/LICENSE
deleted file mode 100644
index 54a7d589..00000000
--- a/cargokit/LICENSE
+++ /dev/null
@@ -1,39 +0,0 @@
-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.
-
diff --git a/cargokit/README b/cargokit/README
deleted file mode 100644
index 8ae4a073..00000000
--- a/cargokit/README
+++ /dev/null
@@ -1,8 +0,0 @@
-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.
-
diff --git a/cargokit/build_pod.sh b/cargokit/build_pod.sh
deleted file mode 100755
index ed0e0d98..00000000
--- a/cargokit/build_pod.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/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"
diff --git a/cargokit/build_tool/README.md b/cargokit/build_tool/README.md
deleted file mode 100644
index 3816eca3..00000000
--- a/cargokit/build_tool/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-A sample command-line application with an entrypoint in `bin/`, library code
-in `lib/`, and example unit test in `test/`.
diff --git a/cargokit/build_tool/analysis_options.yaml b/cargokit/build_tool/analysis_options.yaml
deleted file mode 100644
index a1aad5b3..00000000
--- a/cargokit/build_tool/analysis_options.yaml
+++ /dev/null
@@ -1,31 +0,0 @@
-# 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
diff --git a/cargokit/build_tool/bin/build_tool.dart b/cargokit/build_tool/bin/build_tool.dart
deleted file mode 100644
index f27ec75c..00000000
--- a/cargokit/build_tool/bin/build_tool.dart
+++ /dev/null
@@ -1,5 +0,0 @@
-import 'package:build_tool/build_tool.dart' as build_tool;
-
-void main(List arguments) {
- build_tool.runMain(arguments);
-}
diff --git a/cargokit/build_tool/lib/build_tool.dart b/cargokit/build_tool/lib/build_tool.dart
deleted file mode 100644
index b329c01a..00000000
--- a/cargokit/build_tool/lib/build_tool.dart
+++ /dev/null
@@ -1,5 +0,0 @@
-import 'src/build_tool.dart' as build_tool;
-
-Future runMain(List args) async {
- return build_tool.runMain(args);
-}
diff --git a/cargokit/build_tool/lib/src/android_environment.dart b/cargokit/build_tool/lib/src/android_environment.dart
deleted file mode 100644
index 9342964b..00000000
--- a/cargokit/build_tool/lib/src/android_environment.dart
+++ /dev/null
@@ -1,192 +0,0 @@
-import 'dart:io';
-import 'dart:isolate';
-import 'dart:math' as math;
-
-import 'package:collection/collection.dart';
-import 'package:path/path.dart' as path;
-import 'package:version/version.dart';
-
-import 'target.dart';
-import 'util.dart';
-
-class AndroidEnvironment {
- AndroidEnvironment({
- required this.sdkPath,
- required this.ndkVersion,
- required this.minSdkVersion,
- required this.targetTempDir,
- required this.target,
- });
-
- static void clangLinkerWrapper(List args) {
- final clang = Platform.environment['_CARGOKIT_NDK_LINK_CLANG'];
- if (clang == null) {
- throw Exception(
- "cargo-ndk rustc linker: didn't find _CARGOKIT_NDK_LINK_CLANG env var");
- }
- final target = Platform.environment['_CARGOKIT_NDK_LINK_TARGET'];
- if (target == null) {
- throw Exception(
- "cargo-ndk rustc linker: didn't find _CARGOKIT_NDK_LINK_TARGET env var");
- }
-
- runCommand(clang, [
- target,
- ...args,
- ]);
- }
-
- /// Full path to Android SDK.
- final String sdkPath;
-
- /// Full version of Android NDK.
- final String ndkVersion;
-
- /// Minimum supported SDK version.
- final int minSdkVersion;
-
- /// Target directory for build artifacts.
- final String targetTempDir;
-
- /// Target being built.
- final Target target;
-
- bool ndkIsInstalled() {
- final ndkPath = path.join(sdkPath, 'ndk', ndkVersion);
- final ndkPackageXml = File(path.join(ndkPath, 'package.xml'));
- return ndkPackageXml.existsSync();
- }
-
- void installNdk({
- required String javaHome,
- }) {
- final sdkManagerExtension = Platform.isWindows ? '.bat' : '';
- final sdkManager = path.join(
- sdkPath,
- 'cmdline-tools',
- 'latest',
- 'bin',
- 'sdkmanager$sdkManagerExtension',
- );
-
- log.info('Installing NDK $ndkVersion');
- runCommand(sdkManager, [
- '--install',
- 'ndk;$ndkVersion',
- ], environment: {
- 'JAVA_HOME': javaHome,
- });
- }
-
- Future