From 16fbe3c41707444fcd64e50f558c2592693271b1 Mon Sep 17 00:00:00 2001 From: andycall Date: Sun, 27 Oct 2024 18:30:42 +0800 Subject: [PATCH] feat: switch to compile android from source code. --- bridge/rusty_webf_sys/src/custom_event.rs | 4 +-- bridge/rusty_webf_sys/src/event.rs | 28 ++++++++-------- .../src/idl/pluginAPIGenerator/rsGen.ts | 13 ++++++-- webf/android/build.gradle | 32 ++++++++++++------- .../jniLibs/arm64-v8a/libc++_shared.so | 1 - webf/android/jniLibs/arm64-v8a/libquickjs.so | 1 - webf/android/jniLibs/arm64-v8a/libwebf.so | 1 - .../jniLibs/armeabi-v7a/libc++_shared.so | 1 - .../android/jniLibs/armeabi-v7a/libquickjs.so | 1 - webf/android/jniLibs/armeabi-v7a/libwebf.so | 1 - webf/android/jniLibs/x86/libc++_shared.so | 1 - webf/android/jniLibs/x86/libquickjs.so | 1 - webf/android/jniLibs/x86/libwebf.so | 1 - 13 files changed, 47 insertions(+), 39 deletions(-) delete mode 120000 webf/android/jniLibs/arm64-v8a/libc++_shared.so delete mode 120000 webf/android/jniLibs/arm64-v8a/libquickjs.so delete mode 120000 webf/android/jniLibs/arm64-v8a/libwebf.so delete mode 120000 webf/android/jniLibs/armeabi-v7a/libc++_shared.so delete mode 120000 webf/android/jniLibs/armeabi-v7a/libquickjs.so delete mode 120000 webf/android/jniLibs/armeabi-v7a/libwebf.so delete mode 120000 webf/android/jniLibs/x86/libc++_shared.so delete mode 120000 webf/android/jniLibs/x86/libquickjs.so delete mode 120000 webf/android/jniLibs/x86/libwebf.so diff --git a/bridge/rusty_webf_sys/src/custom_event.rs b/bridge/rusty_webf_sys/src/custom_event.rs index 9d3a4591b7..a4457b1cda 100644 --- a/bridge/rusty_webf_sys/src/custom_event.rs +++ b/bridge/rusty_webf_sys/src/custom_event.rs @@ -10,7 +10,7 @@ pub struct CustomEventRustMethods { pub version: c_double, pub event: *const EventRustMethods, pub detail: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub init_custom_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, bool, bool, *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, + pub init_custom_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, } pub struct CustomEvent { pub event: Event, @@ -47,7 +47,7 @@ impl CustomEvent { } pub fn init_custom_event(&self, type_: &str, canBubble: bool, cancelable: bool, detail: &ScriptValueRef, exception_state: &ExceptionState) -> Result<(), String> { unsafe { - ((*self.method_pointer).init_custom_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), canBubble, cancelable, detail.ptr, exception_state.ptr); + ((*self.method_pointer).init_custom_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(canBubble), i32::from(cancelable), detail.ptr, exception_state.ptr); }; if exception_state.has_exception() { return Err(exception_state.stringify(self.context())); diff --git a/bridge/rusty_webf_sys/src/event.rs b/bridge/rusty_webf_sys/src/event.rs index 4cfdb9d9bd..705ec1c193 100644 --- a/bridge/rusty_webf_sys/src/event.rs +++ b/bridge/rusty_webf_sys/src/event.rs @@ -8,18 +8,18 @@ use crate::*; #[repr(C)] pub struct EventRustMethods { pub version: c_double, - pub bubbles: extern "C" fn(ptr: *const OpaquePtr) -> bool, - pub cancel_bubble: extern "C" fn(ptr: *const OpaquePtr) -> bool, - pub set_cancel_bubble: extern "C" fn(ptr: *const OpaquePtr, value: bool, exception_state: *const OpaquePtr) -> bool, - pub cancelable: extern "C" fn(ptr: *const OpaquePtr) -> bool, + pub bubbles: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub cancel_bubble: extern "C" fn(ptr: *const OpaquePtr) -> i32, + pub set_cancel_bubble: extern "C" fn(ptr: *const OpaquePtr, value: i32, exception_state: *const OpaquePtr) -> bool, + pub cancelable: extern "C" fn(ptr: *const OpaquePtr) -> i32, pub current_target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub default_prevented: extern "C" fn(ptr: *const OpaquePtr) -> bool, + pub default_prevented: extern "C" fn(ptr: *const OpaquePtr) -> i32, pub src_element: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, pub target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue, - pub is_trusted: extern "C" fn(ptr: *const OpaquePtr) -> bool, + pub is_trusted: extern "C" fn(ptr: *const OpaquePtr) -> i32, pub time_stamp: extern "C" fn(ptr: *const OpaquePtr) -> c_double, pub type_: extern "C" fn(ptr: *const OpaquePtr) -> *const c_char, - pub init_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, bool, bool, exception_state: *const OpaquePtr) -> c_void, + pub init_event: extern "C" fn(ptr: *const OpaquePtr, *const c_char, i32, i32, exception_state: *const OpaquePtr) -> c_void, pub prevent_default: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, pub stop_immediate_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, pub stop_propagation: extern "C" fn(ptr: *const OpaquePtr, exception_state: *const OpaquePtr) -> c_void, @@ -51,17 +51,17 @@ impl Event { let value = unsafe { ((*self.method_pointer).bubbles)(self.ptr()) }; - value + value != 0 } pub fn cancel_bubble(&self) -> bool { let value = unsafe { ((*self.method_pointer).cancel_bubble)(self.ptr()) }; - value + value != 0 } pub fn set_cancel_bubble(&self, value: bool, exception_state: &ExceptionState) -> Result<(), String> { unsafe { - ((*self.method_pointer).set_cancel_bubble)(self.ptr(), value, exception_state.ptr) + ((*self.method_pointer).set_cancel_bubble)(self.ptr(), i32::from(value), exception_state.ptr) }; if exception_state.has_exception() { return Err(exception_state.stringify(self.context())); @@ -72,7 +72,7 @@ impl Event { let value = unsafe { ((*self.method_pointer).cancelable)(self.ptr()) }; - value + value != 0 } pub fn current_target(&self) -> EventTarget { let value = unsafe { @@ -84,7 +84,7 @@ impl Event { let value = unsafe { ((*self.method_pointer).default_prevented)(self.ptr()) }; - value + value != 0 } pub fn src_element(&self) -> EventTarget { let value = unsafe { @@ -102,7 +102,7 @@ impl Event { let value = unsafe { ((*self.method_pointer).is_trusted)(self.ptr()) }; - value + value != 0 } pub fn time_stamp(&self) -> f64 { let value = unsafe { @@ -119,7 +119,7 @@ impl Event { } pub fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool, exception_state: &ExceptionState) -> Result<(), String> { unsafe { - ((*self.method_pointer).init_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), bubbles, cancelable, exception_state.ptr); + ((*self.method_pointer).init_event)(self.ptr(), CString::new(type_).unwrap().as_ptr(), i32::from(bubbles), i32::from(cancelable), exception_state.ptr); }; if exception_state.has_exception() { return Err(exception_state.stringify(self.context())); diff --git a/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/rsGen.ts b/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/rsGen.ts index ad947118f8..c7da913404 100644 --- a/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/rsGen.ts +++ b/bridge/scripts/code_generator/src/idl/pluginAPIGenerator/rsGen.ts @@ -36,7 +36,7 @@ function generatePublicReturnTypeValue(type: ParameterType) { return 'RustValue'; } case FunctionArgumentType.boolean: { - return 'bool'; + return 'i32'; } case FunctionArgumentType.dom_string: case FunctionArgumentType.legacy_dom_string: { @@ -100,7 +100,7 @@ function generatePublicParameterType(type: ParameterType): string { return '*const OpaquePtr'; } case FunctionArgumentType.boolean: { - return 'bool'; + return 'i32'; } case FunctionArgumentType.dom_string: case FunctionArgumentType.legacy_dom_string: { @@ -196,6 +196,9 @@ function generateMethodParametersName(parameters: FunctionArguments[]): string { case FunctionArgumentType.legacy_dom_string: { return `CString::new(${generateValidRustIdentifier(param.name)}).unwrap().as_ptr()`; } + case FunctionArgumentType.boolean: { + return `i32::from(${generateValidRustIdentifier(param.name)})`; + } case FunctionArgumentType.any: return `${param.name}.ptr`; default: @@ -255,6 +258,9 @@ function generateMethodReturnStatements(type: ParameterType) { return `Ok(${pointerType}::initialize(value.value, self.context(), value.method_pointer, value.status))`; } switch (type.value) { + case FunctionArgumentType.boolean: { + return 'Ok(value != 0)'; + } case FunctionArgumentType.dom_string: case FunctionArgumentType.legacy_dom_string: { return `let value = unsafe { std::ffi::CStr::from_ptr(value) }; @@ -271,6 +277,9 @@ function generatePropReturnStatements(type: ParameterType) { return `${pointerType}::initialize(value.value, self.context(), value.method_pointer, value.status)`; } switch (type.value) { + case FunctionArgumentType.boolean: { + return 'value != 0'; + } case FunctionArgumentType.dom_string: case FunctionArgumentType.legacy_dom_string: { return `let value = unsafe { std::ffi::CStr::from_ptr(value) }; diff --git a/webf/android/build.gradle b/webf/android/build.gradle index 98b660c5e4..029507cc3f 100644 --- a/webf/android/build.gradle +++ b/webf/android/build.gradle @@ -39,26 +39,34 @@ android { compileSdkVersion 29 defaultConfig { - minSdkVersion 16 + minSdkVersion 18 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - ndk { - abiFilters 'armeabi-v7a', 'arm64-v8a' - } - externalNativeBuild { cmake { - abiFilters 'armeabi-v7a', 'arm64-v8a' + arguments "-DANDROID_STL=c++_shared", "-DIS_ANDROID=TRUE" } } } - lintOptions { - disable 'InvalidPackage' - } - sourceSets { - main { - jniLibs.srcDirs = ['jniLibs'] + // Use the NDK version + ndkVersion = "22.1.7171670" + + // Invoke the shared CMake build with the Android Gradle Plugin. + externalNativeBuild { + cmake { + path = "../src/CMakeLists.txt" + // The default CMake version for the Android Gradle Plugin is 3.10.2. + // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake + // + // The Flutter tooling requires that developers have CMake 3.10 or later + // installed. You should not increase this version, as doing so will cause + // the plugin to fail to compile for some customers of the plugin. + // version "3.10.2" } } + + lintOptions { + disable 'InvalidPackage' + } } diff --git a/webf/android/jniLibs/arm64-v8a/libc++_shared.so b/webf/android/jniLibs/arm64-v8a/libc++_shared.so deleted file mode 120000 index 32812e6de1..0000000000 --- a/webf/android/jniLibs/arm64-v8a/libc++_shared.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/arm64-v8a/libc++_shared.so \ No newline at end of file diff --git a/webf/android/jniLibs/arm64-v8a/libquickjs.so b/webf/android/jniLibs/arm64-v8a/libquickjs.so deleted file mode 120000 index 9991c5f376..0000000000 --- a/webf/android/jniLibs/arm64-v8a/libquickjs.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/arm64-v8a/libquickjs.so \ No newline at end of file diff --git a/webf/android/jniLibs/arm64-v8a/libwebf.so b/webf/android/jniLibs/arm64-v8a/libwebf.so deleted file mode 120000 index 3f24cbcd80..0000000000 --- a/webf/android/jniLibs/arm64-v8a/libwebf.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/arm64-v8a/libwebf.so \ No newline at end of file diff --git a/webf/android/jniLibs/armeabi-v7a/libc++_shared.so b/webf/android/jniLibs/armeabi-v7a/libc++_shared.so deleted file mode 120000 index acf0703444..0000000000 --- a/webf/android/jniLibs/armeabi-v7a/libc++_shared.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/armeabi-v7a/libc++_shared.so \ No newline at end of file diff --git a/webf/android/jniLibs/armeabi-v7a/libquickjs.so b/webf/android/jniLibs/armeabi-v7a/libquickjs.so deleted file mode 120000 index 604b3fdad2..0000000000 --- a/webf/android/jniLibs/armeabi-v7a/libquickjs.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/armeabi-v7a/libquickjs.so \ No newline at end of file diff --git a/webf/android/jniLibs/armeabi-v7a/libwebf.so b/webf/android/jniLibs/armeabi-v7a/libwebf.so deleted file mode 120000 index bb2435fab6..0000000000 --- a/webf/android/jniLibs/armeabi-v7a/libwebf.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/armeabi-v7a/libwebf.so \ No newline at end of file diff --git a/webf/android/jniLibs/x86/libc++_shared.so b/webf/android/jniLibs/x86/libc++_shared.so deleted file mode 120000 index f541ad7f39..0000000000 --- a/webf/android/jniLibs/x86/libc++_shared.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/x86/libc++_shared.so \ No newline at end of file diff --git a/webf/android/jniLibs/x86/libquickjs.so b/webf/android/jniLibs/x86/libquickjs.so deleted file mode 120000 index a7e4f03071..0000000000 --- a/webf/android/jniLibs/x86/libquickjs.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/x86/libquickjs.so \ No newline at end of file diff --git a/webf/android/jniLibs/x86/libwebf.so b/webf/android/jniLibs/x86/libwebf.so deleted file mode 120000 index 1513bec19f..0000000000 --- a/webf/android/jniLibs/x86/libwebf.so +++ /dev/null @@ -1 +0,0 @@ -../../../../bridge/build/android/lib/x86/libwebf.so \ No newline at end of file