Skip to content
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

feat: basic test runner support for rust plugin. #713

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bridge/core/executing_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ void ExecutingContext::SetRunRustFutureTasks(const std::shared_ptr<WebFNativeFun
}

void ExecutingContext::RunRustFutureTasks() {
if (run_rust_future_tasks_ == nullptr)
return;
dart_isolate_context_->profiler()->StartTrackAsyncEvaluation();
run_rust_future_tasks_->Invoke(this, 0, nullptr);
dart_isolate_context_->profiler()->FinishTrackAsyncEvaluation();
}

void ExecutingContext::DrainPendingPromiseJobs() {
Expand Down
2 changes: 1 addition & 1 deletion bridge/core/native/native_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ ScriptPromise NativeLoader::loadNativeLibrary(const AtomicString& lib_name,
return resolver->Promise();
}

} // namespace webf
} // namespace webf
1 change: 1 addition & 0 deletions integration_tests/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
rust_native_api_tests
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies:
waterfall_flow: ^3.0.1
image_compare: ^1.1.2
card_swiper: ^3.0.1
rust_native_api_tests:
path: rust_builder

dev_dependencies:
flutter_test:
Expand Down
29 changes: 29 additions & 0 deletions integration_tests/rust_builder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
3 changes: 3 additions & 0 deletions integration_tests/rust_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions integration_tests/rust_builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please ignore this folder, which is just glue to build Rust with Flutter.
9 changes: 9 additions & 0 deletions integration_tests/rust_builder/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
54 changes: 54 additions & 0 deletions integration_tests/rust_builder/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// The Android Gradle Plugin builds the native code with the Android NDK.

group 'com.integration_tests.rust_builder'
version '1.0'

buildscript {
repositories {
google()
mavenCentral()
}

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

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

apply plugin: 'com.android.library'

android {
if (project.android.hasProperty("namespace")) {
namespace 'com.integration_tests.rust_native_api_tests'
}

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

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 19
}
}


// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

apply from: "../cargokit/gradle/plugin.gradle"

cargokit {
manifestDir = "../rust"
libname = "rust_native_api_tests"
}
1 change: 1 addition & 0 deletions integration_tests/rust_builder/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'rust_native_api_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.integration_tests.rust_native_api_tests">
</manifest>
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@ee0669bd1cc54295c223e0bb666b733df41de1c5 #v2.7.0
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d #1.6.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: dart test
working-directory: build_tool
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@cc97e1648fff6ca5cc647fa67f47e70f7895510b # 2.11.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 integration_tests/rust_builder/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 integration_tests/rust_builder/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 integration_tests/rust_builder/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 integration_tests/rust_builder/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 integration_tests/rust_builder/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/`.
Loading
Loading