diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..d92da849 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +# +# SPDX-License-Identifier: MIT + +use flake diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies new file mode 100644 index 00000000..dbd1c10d --- /dev/null +++ b/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/home/icota/.pub-cache/hosted/pub.dev/path_provider_foundation-2.5.1/","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"rust_lib_tor","path":"/home/icota/Code/tor/rust_builder/","native_build":true,"dependencies":[],"dev_dependency":false}],"android":[{"name":"path_provider_android","path":"/home/icota/.pub-cache/hosted/pub.dev/path_provider_android-2.2.22/","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"rust_lib_tor","path":"/home/icota/Code/tor/rust_builder/","native_build":true,"dependencies":[],"dev_dependency":false}],"macos":[{"name":"path_provider_foundation","path":"/home/icota/.pub-cache/hosted/pub.dev/path_provider_foundation-2.5.1/","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"rust_lib_tor","path":"/home/icota/Code/tor/rust_builder/","native_build":true,"dependencies":[],"dev_dependency":false}],"linux":[{"name":"path_provider_linux","path":"/home/icota/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[],"dev_dependency":false},{"name":"rust_lib_tor","path":"/home/icota/Code/tor/rust_builder/","native_build":true,"dependencies":[],"dev_dependency":false}],"windows":[{"name":"path_provider_windows","path":"/home/icota/.pub-cache/hosted/pub.dev/path_provider_windows-2.3.0/","native_build":false,"dependencies":[],"dev_dependency":false},{"name":"rust_lib_tor","path":"/home/icota/Code/tor/rust_builder/","native_build":true,"dependencies":[],"dev_dependency":false}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"rust_lib_tor","dependencies":[]}],"date_created":"2026-02-19 09:24:05.451601","version":"3.35.7","swift_package_manager_enabled":{"ios":false,"macos":false}} \ No newline at end of file diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 00000000..7a4add7c --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: 2022 Foundation Devices Inc. +# +# SPDX-License-Identifier: MIT + +name: Check + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: REUSE Compliance Check + uses: fsfe/reuse-action@v1 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt, clippy + + - uses: subosito/flutter-action@v2 + with: + channel: 'stable' + flutter-version: '3.35.1' + + - name: Install dependencies + run: flutter pub get + + - name: Verify Dart formatting + run: dart format --output=none --set-exit-if-changed . + + - name: Verify Rust formatting + run: cargo fmt --manifest-path rust/Cargo.toml --all -- --check + + - name: Run Rust tests + run: cargo test --manifest-path rust/Cargo.toml + + - name: Analyze Dart project source + run: flutter analyze + +# - name: Run Dart tests +# run: flutter test diff --git a/.gitignore b/.gitignore index faa341d4..0a3097f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +# +# SPDX-License-Identifier: MIT + # Miscellaneous *.class *.log @@ -30,5 +34,7 @@ migrate_working_dir/ build/ rust/target/.rustc_info.json -rust/target/debug/ -rust/target/CACHEDIR.TAG +rust/target/debug + +# direnv +.direnv/ diff --git a/.reuse/dep5 b/.reuse/dep5 new file mode 100644 index 00000000..e541a3da --- /dev/null +++ b/.reuse/dep5 @@ -0,0 +1,56 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: tor_ffi_plugin +Upstream-Contact: Igor Cota +Source: https://github.com/cypherstack/tor + +Files: cargokit/* +Copyright: 2022 Matej Knopp +License: MIT + +Files: lib/generated* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: lib/src/rust/* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: rust/src/frb_generated.rs +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: .flutter-plugins-dependencies +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: example/linux/flutter/generated* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: example/macos/Flutter/Generated* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: example/windows/flutter/generated* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: example/android/* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: rust/target/* +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: CHANGELOG.md +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: flake.lock +Copyright: 2024 Foundation Devices Inc. +License: MIT + +Files: android/.gradle/* +Copyright: 2024 Foundation Devices Inc. +License: MIT diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc7d81..adc6ff3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,41 @@ + + +## 0.0.9 + +* Bumped arti to version 1.4.3 + +## 0.0.8 + +* Bumped arti to version 1.2.7 + +## 0.0.7 + +* Relicensed to MIT + +## 0.0.6 + +* Pinned 'time' to a specific version + +## 0.0.5 + +* Added rust-toolchain file + +## 0.0.4 + +* Bumped arti to version 1.2.4 + +## 0.0.3 + +* Added functions to stop and restart the proxy. + +## 0.0.2 + +* Fixed the Windows build. + ## 0.0.1 -* TODO: Describe initial release. +* Initial release. diff --git a/LICENSE.license b/LICENSE.license new file mode 100644 index 00000000..7b44746f --- /dev/null +++ b/LICENSE.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2024 Foundation Devices Inc. + +SPDX-License-Identifier: MIT diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 00000000..15a5c944 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024 Foundation Devices Inc. + +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. diff --git a/README.md b/README.md index fb7cf4fb..957e973b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # tor @@ -12,7 +13,7 @@ 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`. ### Install cargo ndk @@ -31,11 +32,10 @@ git subtree pull --prefix cargokit https://github.com/irondash/cargokit.git main ## 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 (re)generate Dart bindings run `just generate` ## 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..8db9afb3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,12 @@ +# SPDX-FileCopyrightText: 2022 Foundation Devices Inc. +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +# +# SPDX-License-Identifier: MIT + include: package:flutter_lints/flutter.yaml -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +analyzer: + exclude: + - 'lib/generated*' + - 'lib/src/rust/**' + - 'cargokit/**' \ No newline at end of file diff --git a/android/.gitignore b/android/.gitignore index 161bdcda..52d44cbf 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc +# +# SPDX-License-Identifier: MIT + *.iml .gradle /local.properties diff --git a/android/build.gradle b/android/build.gradle index b12d70e0..2024b34d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,22 +1,25 @@ +// SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +// +// SPDX-License-Identifier: MIT + // 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") + // The Android Gradle Plugin knows how to build native code with the NDK. + classpath 'com.android.tools.build:gradle:7.3.0' } } -allprojects { +rootProject.allprojects { repositories { google() mavenCentral() @@ -24,54 +27,34 @@ allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' android { if (project.android.hasProperty("namespace")) { namespace 'com.cypherstack.tor_ffi_plugin' } - compileSdk = 34 + // Bumping the plugin compileSdkVersion requires all clients of this plugin + // to bump the version in their app. + compileSdkVersion 33 - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } + // 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 specfic NDK version. + // (e.g. ndkVersion "23.1.7779620") + ndkVersion android.ndkVersion - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 - } - - sourceSets { - main.java.srcDirs += "src/main/kotlin" - test.java.srcDirs += "src/test/kotlin" + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } 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 - } - } + minSdkVersion 19 } } apply from: "../cargokit/gradle/plugin.gradle" - cargokit { manifestDir = "../rust" - libname = "tor_ffi_plugin" -} \ No newline at end of file + libname = "rust_lib_tor" +} diff --git a/android/settings.gradle b/android/settings.gradle index 92109959..4e552c0a 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1 +1,5 @@ +// SPDX-FileCopyrightText: 2024 Foundation Devices Inc +// +// SPDX-License-Identifier: MIT + rootProject.name = 'tor_ffi_plugin' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 99163d87..508449c9 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,8 @@ - + + + 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/LICENSE b/cargokit/LICENSE index 54a7d589..d33a5fea 100644 --- a/cargokit/LICENSE +++ b/cargokit/LICENSE @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + Copyright 2022 Matej Knopp ================================================================================ diff --git a/cargokit/README b/cargokit/README index 8ae4a073..398474db 100644 --- a/cargokit/README +++ b/cargokit/README @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + Experimental repository to provide glue for seamlessly integrating cargo build with flutter plugins and packages. diff --git a/cargokit/build_tool/README.md b/cargokit/build_tool/README.md index 3816eca3..a878c279 100644 --- a/cargokit/build_tool/README.md +++ b/cargokit/build_tool/README.md @@ -1,2 +1,5 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + 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 index a1aad5b3..0e16a8b0 100644 --- a/cargokit/build_tool/analysis_options.yaml +++ b/cargokit/build_tool/analysis_options.yaml @@ -1,3 +1,6 @@ +# This is copied from Cargokit (which is the official way to use it currently) +# Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + # This file configures the static analysis results for your project (errors, # warnings, and lints). # diff --git a/cargokit/build_tool/bin/build_tool.dart b/cargokit/build_tool/bin/build_tool.dart index f27ec75c..268eb524 100644 --- a/cargokit/build_tool/bin/build_tool.dart +++ b/cargokit/build_tool/bin/build_tool.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'package:build_tool/build_tool.dart' as build_tool; void main(List arguments) { diff --git a/cargokit/build_tool/lib/build_tool.dart b/cargokit/build_tool/lib/build_tool.dart index b329c01a..7c1bb750 100644 --- a/cargokit/build_tool/lib/build_tool.dart +++ b/cargokit/build_tool/lib/build_tool.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'src/build_tool.dart' as build_tool; Future runMain(List args) async { diff --git a/cargokit/build_tool/lib/src/android_environment.dart b/cargokit/build_tool/lib/src/android_environment.dart index 9342964b..15fc9eed 100644 --- a/cargokit/build_tool/lib/src/android_environment.dart +++ b/cargokit/build_tool/lib/src/android_environment.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'dart:isolate'; import 'dart:math' as math; diff --git a/cargokit/build_tool/lib/src/artifacts_provider.dart b/cargokit/build_tool/lib/src/artifacts_provider.dart index ef655a9e..e608cece 100644 --- a/cargokit/build_tool/lib/src/artifacts_provider.dart +++ b/cargokit/build_tool/lib/src/artifacts_provider.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:ed25519_edwards/ed25519_edwards.dart'; diff --git a/cargokit/build_tool/lib/src/build_cmake.dart b/cargokit/build_tool/lib/src/build_cmake.dart index 9154371e..6f3b2a4e 100644 --- a/cargokit/build_tool/lib/src/build_cmake.dart +++ b/cargokit/build_tool/lib/src/build_cmake.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:path/path.dart' as path; diff --git a/cargokit/build_tool/lib/src/build_gradle.dart b/cargokit/build_tool/lib/src/build_gradle.dart index 469c8b2d..7e61fcbb 100644 --- a/cargokit/build_tool/lib/src/build_gradle.dart +++ b/cargokit/build_tool/lib/src/build_gradle.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:logging/logging.dart'; diff --git a/cargokit/build_tool/lib/src/build_pod.dart b/cargokit/build_tool/lib/src/build_pod.dart index f01401e1..8a9c0db5 100644 --- a/cargokit/build_tool/lib/src/build_pod.dart +++ b/cargokit/build_tool/lib/src/build_pod.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:path/path.dart' as path; diff --git a/cargokit/build_tool/lib/src/build_tool.dart b/cargokit/build_tool/lib/src/build_tool.dart index 6415f234..c8f36981 100644 --- a/cargokit/build_tool/lib/src/build_tool.dart +++ b/cargokit/build_tool/lib/src/build_tool.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:args/command_runner.dart'; @@ -127,10 +130,6 @@ class PrecompileBinariesCommand extends Command { 'temp-dir', help: 'Directory to store temporary build artifacts', ) - ..addOption( - 'glibc-version', - help: 'GLIBC version to use for linux builds', - ) ..addFlag( "verbose", abbr: "v", @@ -199,7 +198,6 @@ class PrecompileBinariesCommand extends Command { androidNdkVersion: argResults!['android-ndk-version'] as String?, androidMinSdkVersion: androidMinSdkVersion, tempDir: argResults!['temp-dir'] as String?, - glibcVersion: argResults!['glibc-version'] as String?, ); await precompileBinaries.run(); diff --git a/cargokit/build_tool/lib/src/builder.dart b/cargokit/build_tool/lib/src/builder.dart index 894a9ecb..84c46e4f 100644 --- a/cargokit/build_tool/lib/src/builder.dart +++ b/cargokit/build_tool/lib/src/builder.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as path; @@ -51,8 +54,6 @@ class BuildEnvironment { final int? androidMinSdkVersion; final String? javaHome; - final String? glibcVersion; - BuildEnvironment({ required this.configuration, required this.crateOptions, @@ -64,7 +65,6 @@ class BuildEnvironment { this.androidNdkVersion, this.androidMinSdkVersion, this.javaHome, - this.glibcVersion, }); static BuildConfiguration parseBuildConfiguration(String value) { @@ -128,9 +128,6 @@ class RustBuilder { if (!rustup.installedTargets(toolchain)!.contains(target.rust)) { rustup.installTarget(target.rust, toolchain: toolchain); } - if (environment.glibcVersion != null) { - rustup.installZigBuild(toolchain); - } } CargoBuildOptions? get _buildOptions => @@ -148,9 +145,7 @@ class RustBuilder { 'run', _toolchain, 'cargo', - (target.android == null && environment.glibcVersion != null) - ? 'zigbuild' - : 'build', + 'build', ...extraArgs, '--manifest-path', manifestPath, @@ -158,10 +153,7 @@ class RustBuilder { environment.crateInfo.packageName, if (!environment.configuration.isDebug) '--release', '--target', - target.rust + - ((target.android == null && environment.glibcVersion != null) - ? '.${environment.glibcVersion!}' - : ""), + target.rust, '--target-dir', environment.targetTempDir, ], diff --git a/cargokit/build_tool/lib/src/cargo.dart b/cargokit/build_tool/lib/src/cargo.dart index 0d4483ff..0d8958ff 100644 --- a/cargokit/build_tool/lib/src/cargo.dart +++ b/cargokit/build_tool/lib/src/cargo.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:path/path.dart' as path; diff --git a/cargokit/build_tool/lib/src/crate_hash.dart b/cargokit/build_tool/lib/src/crate_hash.dart index e58c37ff..0c4d88d1 100644 --- a/cargokit/build_tool/lib/src/crate_hash.dart +++ b/cargokit/build_tool/lib/src/crate_hash.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; diff --git a/cargokit/build_tool/lib/src/environment.dart b/cargokit/build_tool/lib/src/environment.dart index 1d267edb..996483a1 100644 --- a/cargokit/build_tool/lib/src/environment.dart +++ b/cargokit/build_tool/lib/src/environment.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; extension on String { diff --git a/cargokit/build_tool/lib/src/logging.dart b/cargokit/build_tool/lib/src/logging.dart index 06392b99..5edd4fd1 100644 --- a/cargokit/build_tool/lib/src/logging.dart +++ b/cargokit/build_tool/lib/src/logging.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:logging/logging.dart'; diff --git a/cargokit/build_tool/lib/src/options.dart b/cargokit/build_tool/lib/src/options.dart index 7937dcac..22aef1d3 100644 --- a/cargokit/build_tool/lib/src/options.dart +++ b/cargokit/build_tool/lib/src/options.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:collection/collection.dart'; diff --git a/cargokit/build_tool/lib/src/precompile_binaries.dart b/cargokit/build_tool/lib/src/precompile_binaries.dart index 201874bc..c27f4195 100644 --- a/cargokit/build_tool/lib/src/precompile_binaries.dart +++ b/cargokit/build_tool/lib/src/precompile_binaries.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:ed25519_edwards/ed25519_edwards.dart'; @@ -26,7 +29,6 @@ class PrecompileBinaries { this.androidNdkVersion, this.androidMinSdkVersion, this.tempDir, - this.glibcVersion, }); final PrivateKey privateKey; @@ -38,7 +40,6 @@ class PrecompileBinaries { final String? androidNdkVersion; final int? androidMinSdkVersion; final String? tempDir; - final String? glibcVersion; static String fileName(Target target, String name) { return '${target.rust}_$name'; @@ -95,7 +96,6 @@ class PrecompileBinaries { androidSdkPath: androidSdkLocation, androidNdkVersion: androidNdkVersion, androidMinSdkVersion: androidMinSdkVersion, - glibcVersion: glibcVersion, ); final rustup = Rustup(); diff --git a/cargokit/build_tool/lib/src/rustup.dart b/cargokit/build_tool/lib/src/rustup.dart index 715b6d05..0ac8d086 100644 --- a/cargokit/build_tool/lib/src/rustup.dart +++ b/cargokit/build_tool/lib/src/rustup.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:collection/collection.dart'; @@ -33,27 +36,14 @@ class Rustup { required String toolchain, }) { log.info("Installing Rust target: $target"); - runCommand("rustup", ['target', 'add', '--toolchain', toolchain, target]); - _installedTargets(toolchain)?.add(target); - } - - bool _didInstallZigBuild = false; - - void installZigBuild(String toolchain) { - if (_didInstallZigBuild) { - return; - } - - log.info("Installing Zig build"); runCommand("rustup", [ - 'run', + 'target', + 'add', + '--toolchain', toolchain, - 'cargo', - 'install', - '--locked', - 'cargo-zigbuild', + target, ]); - _didInstallZigBuild = true; + _installedTargets(toolchain)?.add(target); } final List<_Toolchain> _installedToolchains; diff --git a/cargokit/build_tool/lib/src/target.dart b/cargokit/build_tool/lib/src/target.dart index a5c25fce..6fbc58b6 100644 --- a/cargokit/build_tool/lib/src/target.dart +++ b/cargokit/build_tool/lib/src/target.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:collection/collection.dart'; @@ -43,10 +46,6 @@ class Target { rust: 'x86_64-pc-windows-msvc', flutter: 'windows-x64', ), - Target( - rust: 'aarch64-pc-windows-msvc', - flutter: 'windows-arm64', - ), Target( rust: 'x86_64-unknown-linux-gnu', flutter: 'linux-x64', @@ -55,7 +54,6 @@ class Target { rust: 'aarch64-unknown-linux-gnu', flutter: 'linux-arm64', ), - Target(rust: 'riscv64gc-unknown-linux-gnu', flutter: 'linux-riscv64'), Target( rust: 'x86_64-apple-darwin', darwinPlatform: 'macosx', @@ -111,11 +109,9 @@ class Target { if (Platform.isLinux) { // Right now we don't support cross-compiling on Linux. So we just return // the host target. - final arch = (runCommand('arch', []).stdout as String).trim(); - if (arch == 'aarch64') { + final arch = runCommand('arch', []).stdout as String; + if (arch.trim() == 'aarch64') { return [Target.forRustTriple('aarch64-unknown-linux-gnu')!]; - } else if (arch == 'riscv64') { - return [Target.forRustTriple('riscv64gc-unknown-linux-gnu')!]; } else { return [Target.forRustTriple('x86_64-unknown-linux-gnu')!]; } diff --git a/cargokit/build_tool/lib/src/util.dart b/cargokit/build_tool/lib/src/util.dart index d8e30196..8bb6a872 100644 --- a/cargokit/build_tool/lib/src/util.dart +++ b/cargokit/build_tool/lib/src/util.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:convert'; import 'dart:io'; diff --git a/cargokit/build_tool/lib/src/verify_binaries.dart b/cargokit/build_tool/lib/src/verify_binaries.dart index 0094c644..2366b57b 100644 --- a/cargokit/build_tool/lib/src/verify_binaries.dart +++ b/cargokit/build_tool/lib/src/verify_binaries.dart @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import 'dart:io'; import 'package:ed25519_edwards/ed25519_edwards.dart'; diff --git a/cargokit/build_tool/pubspec.yaml b/cargokit/build_tool/pubspec.yaml index e01aa0ae..18c61e33 100644 --- a/cargokit/build_tool/pubspec.yaml +++ b/cargokit/build_tool/pubspec.yaml @@ -1,3 +1,6 @@ +# This is copied from Cargokit (which is the official way to use it currently) +# Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + name: build_tool description: Cargokit build_tool. Facilitates the build of Rust crate during Flutter application build. publish_to: none diff --git a/cargokit/build_tool/test/builder_test.dart b/cargokit/build_tool/test/builder_test.dart deleted file mode 100644 index e92852e5..00000000 --- a/cargokit/build_tool/test/builder_test.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:build_tool/src/builder.dart'; -import 'package:test/test.dart'; - -void main() { - test('parseBuildConfiguration', () { - var b = BuildEnvironment.parseBuildConfiguration('debug'); - expect(b, BuildConfiguration.debug); - - b = BuildEnvironment.parseBuildConfiguration('profile'); - expect(b, BuildConfiguration.profile); - - b = BuildEnvironment.parseBuildConfiguration('release'); - expect(b, BuildConfiguration.release); - - b = BuildEnvironment.parseBuildConfiguration('debug-dev'); - expect(b, BuildConfiguration.debug); - - b = BuildEnvironment.parseBuildConfiguration('profile'); - expect(b, BuildConfiguration.profile); - - b = BuildEnvironment.parseBuildConfiguration('profile-prod'); - expect(b, BuildConfiguration.profile); - - // fallback to release - b = BuildEnvironment.parseBuildConfiguration('unknown'); - expect(b, BuildConfiguration.release); - }); -} diff --git a/cargokit/build_tool/test/cargo_test.dart b/cargokit/build_tool/test/cargo_test.dart deleted file mode 100644 index 00afe29f..00000000 --- a/cargokit/build_tool/test/cargo_test.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:build_tool/src/cargo.dart'; -import 'package:test/test.dart'; - -final _cargoToml = """ -[workspace] - -[profile.release] -lto = true -panic = "abort" -opt-level = "z" -# strip = "symbols" - -[package] -name = "super_native_extensions" -version = "0.1.0" -edition = "2021" -resolver = "2" - -[lib] -crate-type = ["cdylib", "staticlib"] -"""; - -void main() { - test('parseCargoToml', () { - final info = CrateInfo.parseManifest(_cargoToml); - expect(info.packageName, 'super_native_extensions'); - }); -} diff --git a/cargokit/build_tool/test/options_test.dart b/cargokit/build_tool/test/options_test.dart deleted file mode 100644 index 25a85b6a..00000000 --- a/cargokit/build_tool/test/options_test.dart +++ /dev/null @@ -1,75 +0,0 @@ -import 'package:build_tool/src/builder.dart'; -import 'package:build_tool/src/options.dart'; -import 'package:hex/hex.dart'; -import 'package:test/test.dart'; -import 'package:yaml/yaml.dart'; - -void main() { - test('parseCargoBuildOptions', () { - final yaml = """ -toolchain: nightly -extra_flags: - - -Z - # Comment here - - build-std=panic_abort,std -"""; - final node = loadYamlNode(yaml); - final options = CargoBuildOptions.parse(node); - expect(options.toolchain, Toolchain.nightly); - expect(options.flags, ['-Z', 'build-std=panic_abort,std']); - }); - - test('parsePrecompiledBinaries', () { - final yaml = """ -url_prefix: https://url-prefix -public_key: a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445 -"""; - final precompiledBinaries = PrecompiledBinaries.parse(loadYamlNode(yaml)); - final key = HEX.decode( - 'a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445'); - expect(precompiledBinaries.uriPrefix, 'https://url-prefix'); - expect(precompiledBinaries.publicKey.bytes, key); - }); - - test('parseCargokitOptions', () { - const yaml = ''' -cargo: - # For smalles binaries rebuilt the standard library with panic=abort - debug: - toolchain: nightly - extra_flags: - - -Z - # Comment here - - build-std=panic_abort,std - release: - toolchain: beta - -precompiled_binaries: - url_prefix: https://url-prefix - public_key: a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445 -'''; - final options = CargokitCrateOptions.parse(loadYamlNode(yaml)); - expect(options.precompiledBinaries?.uriPrefix, 'https://url-prefix'); - final key = HEX.decode( - 'a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445'); - expect(options.precompiledBinaries?.publicKey.bytes, key); - - final debugOptions = options.cargo[BuildConfiguration.debug]!; - expect(debugOptions.toolchain, Toolchain.nightly); - expect(debugOptions.flags, ['-Z', 'build-std=panic_abort,std']); - - final releaseOptions = options.cargo[BuildConfiguration.release]!; - expect(releaseOptions.toolchain, Toolchain.beta); - expect(releaseOptions.flags, []); - }); - - test('parseCargokitUserOptions', () { - const yaml = ''' -use_precompiled_binaries: false -verbose_logging: true -'''; - final options = CargokitUserOptions.parse(loadYamlNode(yaml)); - expect(options.usePrecompiledBinaries, false); - expect(options.verboseLogging, true); - }); -} diff --git a/cargokit/build_tool/test/rustup_test.dart b/cargokit/build_tool/test/rustup_test.dart deleted file mode 100644 index af95303c..00000000 --- a/cargokit/build_tool/test/rustup_test.dart +++ /dev/null @@ -1,66 +0,0 @@ -import 'package:build_tool/src/rustup.dart'; -import 'package:build_tool/src/util.dart'; -import 'package:test/test.dart'; - -void main() { - test('rustup with no toolchains', () { - bool didListToolchains = false; - bool didInstallStable = false; - bool didListTargets = false; - testRunCommandOverride = (args) { - expect(args.executable, 'rustup'); - switch (args.arguments) { - case ['toolchain', 'list']: - didListToolchains = true; - return TestRunCommandResult(stdout: 'no installed toolchains\n'); - case ['toolchain', 'install', 'stable']: - didInstallStable = true; - return TestRunCommandResult(); - case ['target', 'list', '--toolchain', 'stable', '--installed']: - didListTargets = true; - return TestRunCommandResult( - stdout: 'x86_64-unknown-linux-gnu\nx86_64-apple-darwin\n'); - default: - throw Exception('Unexpected call: ${args.arguments}'); - } - }; - final rustup = Rustup(); - rustup.installToolchain('stable'); - expect(didInstallStable, true); - expect(didListToolchains, true); - expect(didListTargets, true); - expect(rustup.installedTargets('stable'), [ - 'x86_64-unknown-linux-gnu', - 'x86_64-apple-darwin', - ]); - testRunCommandOverride = null; - }); - - test('rustup with esp toolchain', () { - final targetsQueried = []; - testRunCommandOverride = (args) { - expect(args.executable, 'rustup'); - switch (args.arguments) { - case ['toolchain', 'list']: - return TestRunCommandResult( - stdout: 'stable-aarch64-apple-darwin (default)\n' - 'nightly-aarch64-apple-darwin\n' - 'esp\n'); - case ['target', 'list', '--toolchain', String toolchain, '--installed']: - targetsQueried.add(toolchain); - return TestRunCommandResult(stdout: '$toolchain:target\n'); - default: - throw Exception('Unexpected call: ${args.arguments}'); - } - }; - final rustup = Rustup(); - expect(targetsQueried, [ - 'stable-aarch64-apple-darwin', - 'nightly-aarch64-apple-darwin', - ]); - expect(rustup.installedTargets('stable'), - ['stable-aarch64-apple-darwin:target']); - expect(rustup.installedTargets('nightly'), - ['nightly-aarch64-apple-darwin:target']); - }); -} diff --git a/cargokit/docs/architecture.md b/cargokit/docs/architecture.md deleted file mode 100644 index d9bcf4e2..00000000 --- a/cargokit/docs/architecture.md +++ /dev/null @@ -1,104 +0,0 @@ -# Cargokit Architecture - -Note: This is mostly relevant for plugins authors that want to see a bit under the hood rather then just following a tutorial. - -In ideal conditions the end-developer using the plugin should not even be aware of Cargokit existence. - -## Integration - -Cargokit is meant to be included in Flutter plugin (or application) that contains the Rust crate to be built during the Flutter build process. - -Cargokit can be either incuded as git submodule or git subtree (required for plugins - as pub does not support submodules for git dependencies). - -For a step by step tutorial on integrating Cargokit with a Flutter plugin see https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/. - -## build_tool - -Build tool is the core of cargokit. It is a Dart command line package that facilitates the build of Rust crate. It is invoked during the Flutter build process to build (or download) Rust artifacts, but it can be also used as a standalone tool. - -It handles the following commands: - -### build-cmake - -This is invoked from `cargokit.cmake` and it is used to build the Rust crate into a dynamic library on Linux and Windows (which use CMake as build system). - -The command takes no additional arguments, everything is controlled during environment variables set by `cargokit.cmake`. - -### build-gradle - -This is invoked from `plugin.gradle` and it is used to build the Rust crate into a dynamic library on Android. The command takes no additional arguments, everything is controlled during environment variables set by `plugin.gradle`. - -The build_tool installs NDK if needed, configures the Rust environment for cross compilation and then invokes `cargo build` with appropriate arguments and environment variables. - -The build-tool also acts a linker driver. - -### build-pod - -This is invoked from plugin's podspec `script_phase` through `build_pod.sh`. Bundle tool will build the Rust crate into a static library that gets linked into the plugin Framework. In this case must have `:execution_position` set to `:before_compile`. - -Cargokit will build binaries for all active architectures from XCode build and lipo them togherer. - -When using Cargokit to integrate Rust code with an application (not a plugin) you can also configure the `Cargo.toml` to just build a dynamic library. When Cargokit finds that the crate only built a dylib and no static lib, it will attempt to replace the Cocoapod framework binary with the dylib. In this case the script `:execution_position` must be set to `:after_compile`. This is *not* recommended for plugins and it's quite experimental. - -### gen-key, precompile-binaries, verify-binaries - -These are used as when providing precompiled binaries for Plugin. See [precompiled_binaries.md](precompiled_binaries.md) for more information. - -## Launching the build_tool during build. - -During Flutter build, the build tool can not be launched directly using `dart run`. Rather it is launched through `run_build_tool.sh` and `run_build_tool.cmd`. Because the `build_tool` is shipped as part of plugin, we generally don't want to write into the plugin directory during build, which would happen if the `build_tool` was simply invoked through `dart run` (For example the `.dart_tool/package_config.json` file would get written inside the `build_tool` directory). - -Instead the `run_build_tool` script creates a minimal Dart command line package in the build directory and references the `build_tool` as package. That way the `.dart_tool/package_config.json` file is created in the temporary build folder and not in the plugin itself. The script also precompiles the Dart code to speed up subsequent invocations. - -## Configuring Cargokit - -### Configuration for the Rust crate - -Cargokit can be configured through a `cargokit.yaml` file, which can be used to control the build of the Rust package and is placed into the Rust crate next to `Cargo.toml`. - -Here is an example `cargokit.yaml` with comments: -```yaml -cargo: - debug: # Configuration of cargo execution during debug builds - toolchain: stable # default - release: # Configuration of cargo execution for release builds - toolchain: nightly # rustup will be invoked with nightly toolchain - extra_flags: # extra arguments passed to cargo build - - -Z - - build-std=panic_abort,std - -# If crate ships with precompiled binaries, they can be configured here. -precompiled_binaries: - # Uri prefix used when downloading precompiled binaries. - url_prefix: https://github.com/superlistapp/super_native_extensions/releases/download/precompiled_ - - # Public key for verifying downloaded precompiled binaries. - public_key: 3a257ef1c7d72d84225ac4658d24812ada50a7a7a8a2138c2a91353389fdc514 -``` - -### Configuration for the application consuming the plugin - -A `cargokit_options.yaml` file can also be placed by developer using plugin to the root of the application package. In which case the file can be used to specify following options: - -```yaml -# Enables verbose logging of Cargokit during build -verbose_logging: true - -# Opts out of using precompiled binaries. If crate has configured -# and deployed precompiled binaries, these will be by default used whenever Rustup -# is not installed. With `use_precompiled_binaries` set to false, the build will -# instead be aborted prompting user to install Rustup. -use_precompiled_binaries: false -``` - -## Detecting Rustup - -When the plugin doesn't come with precompiled libraries (or user opt-out), `build_tool` will need to invoke Rustup during build to ensure that required Rust targets and toolchain are installed for current build and to build the Rust crate. - -Cargokit will attempt to detect Rustup in the default Rustup installation location (`~/.cargo/rustup`) as well as in PATH. This is done so that if user install Rustup but doesn't properly configure PATH, Cargokit will still work. - -If `build_tool` doesn't find Rustup, it will about the build with a message showing instructions to install Rustup specific to current platform. - -On macOS it will also detect a homebrew Rust installation in PATH and will prompt user to call `brew unlink rust` first to remove homebrew Rust installation from PATH, because it may interfere with Rustup. - -Homebrew Rust installation can not be used by Cargokit, because it can only build for host platform. Cargokit needs to be able to cross compile the Rust crate for iOS and Android and thus needs full Rustup installation. diff --git a/cargokit/docs/precompiled_binaries.md b/cargokit/docs/precompiled_binaries.md deleted file mode 100644 index 2026e867..00000000 --- a/cargokit/docs/precompiled_binaries.md +++ /dev/null @@ -1,95 +0,0 @@ -# Precompiled Binaries - -Because Cargokit builds the Rust crate during Flutter build, it is inherently -dependend on the Rust toolchain being installed on the developer's machine. - -To decrease the friction, it is possible for Cargokit to use precompiled binaries instead. - -This is how the process of using precompiled binaries looks from the perspective of the build on developer machine: - -1. Cargokit checks if there is `cargokit_options.yaml` file in the root folder of target application. If there is one, it will be checked for `use_precompiled_binaries` options to see if user opted out of using precompiled binaries. In which case Cargokit will insist on building from source. Cargokit will also build from source if the configuration file is absent, but user has Rustup installed. - -2. Cargokit checks if there is `cargokit.yaml` file placed in the Rust crate. If there is one, it will be checked for `precompiled_binaries` section to see if crate supports precompiled binaries. The configuration section must contain a public key and URL prefix. - -3. Cargokit computes a `crate-hash`. This is a SHA256 hash value computed from all Rust files inside crate, `Cargo.toml`, `Cargo.lock` and `cargokit.yaml`. This uniquely identifies the crate and it is used to find the correct precompiled binaries. - -4. Cargokit will attempt to download the precompiled binaries for target platform and `crate_hash` combination and a signature file for each downloaded binary. If download succeeds, the binary content will be verified against the signature and public key included in `cargokit.yaml` (which is part of Rust crate and thus part of published Flutter package). - -5. If the verification succeeds, the precompiled binaries will be used. Otherwise the binary will be discarded and Cargokit will insist on building from source. - -## Providing precompiled binaries - -Note that this assumes that precompiled binaries will be generated during github actions and deployed as github releases. - -### Use `build_tool` to generate a key-pair: - -``` -dart run build_tool gen-key -``` - -This will print the private key and public key. Store the private key securely. It needs to be provided as a secret to github action. - -The public key should be included in `cargokit.yaml` file in the Rust crate. - -### Provide a `cargokit.yaml` file in the Rust crate - -The file must be placed alongside Cargo.toml. - -```yaml -precompiled_binaries: - # Uri prefix used when downloading precompiled binaries. - url_prefix: https://github.com///releases/download/precompiled_ - - # Public key for verifying downloaded precompiled binaries. - public_key: -``` - -### Configure a github action to build and upload precompiled binaries. - -The github action should be run at every commit to main branch (and possibly other branches). - -The action needs two secrets - private key for signing binaries and GitHub token for uploading binaries as releases. Here is example action that precompiles and uploads binaries for all supported targets. - -```yaml -on: - push: - branches: [ main ] - -name: Precompile Binaries - -jobs: - Precompile: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - macOS-latest - - windows-latest - steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v1 - - name: Install GTK - if: (matrix.os == 'ubuntu-latest') - run: sudo apt-get update && sudo apt-get install libgtk-3-dev - - name: Precompile - if: (matrix.os == 'macOS-latest') || (matrix.os == 'windows-latest') - run: dart run build_tool precompile-binaries -v --manifest-dir=../../rust --repository=superlistapp/super_native_extensions - working-directory: super_native_extensions/cargokit/build_tool - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} - PRIVATE_KEY: ${{ secrets.RELEASE_PRIVATE_KEY }} - - name: Precompile (with Android) - if: (matrix.os == 'ubuntu-latest') - run: dart run build_tool precompile-binaries -v --manifest-dir=../../rust --repository=superlistapp/super_native_extensions --android-sdk-location=/usr/local/lib/android/sdk --android-ndk-version=24.0.8215888 --android-min-sdk-version=23 - working-directory: super_native_extensions/cargokit/build_tool - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} - PRIVATE_KEY: ${{ secrets.RELEASE_PRIVATE_KEY }} -``` - -By default the `built_tool precompile-binaries` commands build and uploads the binaries for all targets buildable from current host. This can be overriden using the `--target ` argument. - -Android binaries will be built when `--android-sdk-location` and `--android-ndk-version` arguments are provided. - diff --git a/cargokit/gradle/plugin.gradle b/cargokit/gradle/plugin.gradle index fdf94c43..4af35ee0 100644 --- a/cargokit/gradle/plugin.gradle +++ b/cargokit/gradle/plugin.gradle @@ -1,3 +1,6 @@ +/// This is copied from Cargokit (which is the official way to use it currently) +/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin + import java.nio.file.Paths import org.apache.tools.ant.taskdefs.condition.Os diff --git a/cargokit/run_build_tool.cmd b/cargokit/run_build_tool.cmd old mode 100644 new mode 100755 diff --git a/example/.gitignore b/example/.gitignore index 24476c5d..0b4fe0d7 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +# +# SPDX-License-Identifier: MIT + # Miscellaneous *.class *.log @@ -5,9 +9,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/example/README.md b/example/README.md index de9b2739..5155013e 100644 --- a/example/README.md +++ b/example/README.md @@ -1,3 +1,9 @@ + + # tor_example Demonstrates how to use the tor plugin. diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 61b6c4de..bc3ec341 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -1,29 +1,9 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc. # -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. +# SPDX-License-Identifier: MIT -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. include: package:flutter_lints/flutter.yaml linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options + avoid_print: false \ No newline at end of file diff --git a/example/android/.gitignore b/example/android/.gitignore index 6f568019..483a5401 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +# +# SPDX-License-Identifier: MIT + gradle-wrapper.jar /.gradle /captures/ diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 7d61b73e..389801c5 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,46 +1,71 @@ +// SPDX-FileCopyrightText: 2024 Foundation Devices Inc. +// +// SPDX-License-Identifier: MIT plugins { id "com.android.application" id "kotlin-android" - // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id "dev.flutter.flutter-gradle-plugin" } +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} android { - namespace "com.cypherstack.tor_ffi_plugin_example" - compileSdk = flutter.compileSdkVersion - ndkVersion = flutter.ndkVersion + namespace "com.foundationdevices.tor_example" + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.cypherstack.tor_ffi_plugin_example" + applicationId "com.foundationdevices.tor_example" // You can update the following values to match your application needs. - // For more information, see: https://flutter.dev/to/review-gradle-config. - minSdk = flutter.minSdkVersion - targetSdk = flutter.targetSdkVersion - versionCode = flutter.versionCode - versionName = flutter.versionName + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig = signingConfigs.debug + signingConfig signingConfigs.debug } } } flutter { - source = "../.." + source '../..' } - +dependencies { +} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index 399f6981..99ba96c1 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,3 +1,9 @@ + + + + + + diff --git a/example/android/app/src/main/res/drawable/launch_background.xml b/example/android/app/src/main/res/drawable/launch_background.xml index 304732f8..1a70aa77 100644 --- a/example/android/app/src/main/res/drawable/launch_background.xml +++ b/example/android/app/src/main/res/drawable/launch_background.xml @@ -1,4 +1,11 @@ + + + diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml index 06952be7..f22a0f6c 100644 --- a/example/android/app/src/main/res/values-night/styles.xml +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -1,4 +1,11 @@ + + +