Skip to content

Commit

Permalink
feat: switch to compile android from source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Oct 27, 2024
1 parent 9ccc847 commit 16fbe3c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 39 deletions.
4 changes: 2 additions & 2 deletions bridge/rusty_webf_sys/src/custom_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct CustomEventRustMethods {
pub version: c_double,
pub event: *const EventRustMethods,
pub detail: extern "C" fn(ptr: *const OpaquePtr) -> RustValue<ScriptValueRefRustMethods>,
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,
Expand Down Expand Up @@ -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()));
Expand Down
28 changes: 14 additions & 14 deletions bridge/rusty_webf_sys/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventTargetRustMethods>,
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<EventTargetRustMethods>,
pub target: extern "C" fn(ptr: *const OpaquePtr) -> RustValue<EventTargetRustMethods>,
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,
Expand Down Expand Up @@ -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()));
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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()));
Expand Down
13 changes: 11 additions & 2 deletions bridge/scripts/code_generator/src/idl/pluginAPIGenerator/rsGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function generatePublicReturnTypeValue(type: ParameterType) {
return 'RustValue<ScriptValueRefRustMethods>';
}
case FunctionArgumentType.boolean: {
return 'bool';
return 'i32';
}
case FunctionArgumentType.dom_string:
case FunctionArgumentType.legacy_dom_string: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) };
Expand All @@ -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) };
Expand Down
32 changes: 20 additions & 12 deletions webf/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
1 change: 0 additions & 1 deletion webf/android/jniLibs/arm64-v8a/libc++_shared.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/arm64-v8a/libquickjs.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/arm64-v8a/libwebf.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/armeabi-v7a/libc++_shared.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/armeabi-v7a/libquickjs.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/armeabi-v7a/libwebf.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/x86/libc++_shared.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/x86/libquickjs.so

This file was deleted.

1 change: 0 additions & 1 deletion webf/android/jniLibs/x86/libwebf.so

This file was deleted.

0 comments on commit 16fbe3c

Please sign in to comment.