Skip to content

Commit

Permalink
Merge pull request #2329 from patmuk/fixes-cfg-wasm-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy authored Sep 30, 2024
2 parents 0e7071f + bb37ed7 commit 09d3194
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 68 deletions.
10 changes: 5 additions & 5 deletions frb_rust/src/codec/dco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ impl Rust2DartMessageTrait for Rust2DartMessageDco {
}

unsafe fn from_raw_wire_sync(raw: Self::WireSyncRust2DartType) -> Self {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
return Self(*crate::for_generated::box_from_leak_ptr(raw));

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
return Self(raw);
}

fn into_raw_wire_sync(self) -> Self::WireSyncRust2DartType {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
return crate::for_generated::new_leak_box_ptr(self.0);

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
return self.0;
}
}
Expand All @@ -78,7 +78,7 @@ where
#[cfg(test)]
mod tests {

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[test]
fn test_simplest() {
use crate::codec::Rust2DartMessageTrait;
Expand Down
12 changes: 6 additions & 6 deletions frb_rust/src/codec/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ impl Rust2DartMessageTrait for Rust2DartMessageSse {
}

unsafe fn from_raw_wire_sync(raw: Self::WireSyncRust2DartType) -> Self {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
{
let WireSyncRust2DartSse { ptr, len } = raw;
Self(crate::for_generated::vec_from_leak_ptr(ptr, len))
}

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
Self(js_sys::Uint8Array::new(&raw).to_vec())
}

fn into_raw_wire_sync(self) -> Self::WireSyncRust2DartType {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
{
let (ptr, len) = crate::for_generated::into_leak_vec_ptr(self.0);
WireSyncRust2DartSse { ptr, len }
}

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
return <js_sys::Uint8Array>::from(self.0.as_slice()).into();
}
}
Expand All @@ -101,9 +101,9 @@ impl Dart2RustMessageSse {
rust_vec_len: i32,
data_len: i32,
) -> Self {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
let vec = crate::for_generated::vec_from_leak_ptr(ptr, rust_vec_len);
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
let vec = js_sys::Uint8Array::new(&ptr).to_vec();

Self { vec, data_len }
Expand Down
2 changes: 1 addition & 1 deletion frb_rust/src/dart_opaque/boxes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub(crate) mod dart_isolate_box;
pub(crate) mod guarded_box;
pub(crate) mod thread_box;
2 changes: 1 addition & 1 deletion frb_rust/src/dart_opaque/boxes/thread_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl GuardedBoxContext for GuardedBoxContextThread {
}
}

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[cfg(test)]
mod tests {
use crate::dart_opaque::boxes::thread_box::ThreadBox;
Expand Down
10 changes: 5 additions & 5 deletions frb_rust/src/dart_opaque/dart2rust.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{DartOpaque, GeneralizedDartHandle};
use crate::platform_types::{message_port_to_handle, MessagePort};
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
use wasm_bindgen::prelude::*;

/// # Safety
///
/// This should never be called manually.
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub unsafe fn cst_decode_dart_opaque(raw: wasm_bindgen::JsValue) -> DartOpaque {
#[cfg(target_pointer_width = "64")]
{
Expand All @@ -19,7 +19,7 @@ pub unsafe fn cst_decode_dart_opaque(raw: wasm_bindgen::JsValue) -> DartOpaque {
/// # Safety
///
/// This should never be called manually.
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub unsafe fn cst_decode_dart_opaque(raw: usize) -> DartOpaque {
DartOpaque::from_raw(raw as _)
}
Expand All @@ -34,7 +34,7 @@ pub unsafe fn sse_decode_dart_opaque(raw: usize) -> DartOpaque {
/// # Safety
///
/// This should never be called manually.
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
#[wasm_bindgen]
pub unsafe fn dart_opaque_dart2rust_encode(
handle: GeneralizedDartHandle,
Expand All @@ -46,7 +46,7 @@ pub unsafe fn dart_opaque_dart2rust_encode(
/// # Safety
///
/// This should never be called manually.
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[no_mangle]
pub unsafe extern "C" fn dart_opaque_dart2rust_encode(
handle: GeneralizedDartHandle,
Expand Down
10 changes: 5 additions & 5 deletions frb_rust/src/dart_opaque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use crate::platform_types::SendableMessagePortHandle;
use std::sync::Arc;

/// cbindgen:ignore
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
mod web;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use web::*;

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
mod io;

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub use io::*;

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
mod auto_drop_dart_persistent_handle;

pub(crate) mod action;
Expand Down
6 changes: 3 additions & 3 deletions frb_rust/src/dart_opaque/non_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::generalized_isolate::Channel;
use crate::generalized_isolate::IntoDart;
use crate::misc::logs::log_warn_or_println;
use crate::platform_types::{handle_to_message_port, SendableMessagePortHandle};
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
use wasm_bindgen::prelude::*;

#[derive(Debug)]
Expand Down Expand Up @@ -91,13 +91,13 @@ fn drop_thread_box_persistent_handle_via_port(
};
}

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[no_mangle]
pub unsafe extern "C" fn dart_opaque_drop_thread_box_persistent_handle(ptr: usize) {
dart_opaque_drop_thread_box_persistent_handle_inner(ptr)
}

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
#[wasm_bindgen]
pub unsafe extern "C" fn dart_opaque_drop_thread_box_persistent_handle(ptr: usize) {
dart_opaque_drop_thread_box_persistent_handle_inner(ptr)
Expand Down
6 changes: 3 additions & 3 deletions frb_rust/src/dart_opaque/rust2dart.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{DartOpaque, GeneralizedDartHandle};
use crate::generalized_isolate::IntoDart;
use crate::platform_types::DartAbi;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
use wasm_bindgen::prelude::*;

impl From<DartOpaque> for DartAbi {
Expand All @@ -16,13 +16,13 @@ impl DartOpaque {
}
}

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
#[wasm_bindgen]
pub unsafe fn dart_opaque_rust2dart_decode(ptr: usize) -> GeneralizedDartHandle {
dart_opaque_rust2dart_decode_inner(ptr)
}

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[no_mangle]
pub unsafe extern "C" fn dart_opaque_rust2dart_decode(ptr: usize) -> GeneralizedDartHandle {
dart_opaque_rust2dart_decode_inner(ptr)
Expand Down
8 changes: 4 additions & 4 deletions frb_rust/src/ffi_binding/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::for_generated::{into_leak_vec_ptr, new_leak_vec_ptr, vec_from_leak_ptr};

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
mod io;
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[allow(unused)]
pub use io::*;

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
mod web;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
#[allow(unused)]
pub use web::*;

Expand Down
2 changes: 1 addition & 1 deletion frb_rust/src/for_generated/cast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Cast a byte buffer into a boxed slice of the target type without making any copies.
/// Panics if the cast fails.
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub fn slice_from_byte_buffer<T: bytemuck::Pod>(buffer: Vec<u8>) -> Box<[T]> {
let buf = Box::leak(buffer.into_boxed_slice());
match bytemuck::try_cast_slice_mut(buf) {
Expand Down
12 changes: 6 additions & 6 deletions frb_rust/src/for_generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use crate::lockable::{
#[allow(unused)]
pub use crate::misc::manual_impl::*;
pub use crate::misc::version::FLUTTER_RUST_BRIDGE_RUNTIME_VERSION;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use crate::misc::web_utils;
pub use crate::platform_types::{
DartAbi, MessagePort, PlatformGeneralizedUint8ListPtr, WireSyncRust2DartDco,
Expand All @@ -63,23 +63,23 @@ pub use crate::rust_auto_opaque::{inner::RustAutoOpaqueInner, RustAutoOpaqueBase
pub use crate::rust_opaque::{dart2rust::decode_rust_opaque_nom, RustOpaqueBase};
pub use crate::stream::stream_sink::StreamSinkBase;
pub use crate::thread_pool::{BaseThreadPool, SimpleThreadPool};
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use crate::web_transfer::transfer_closure::TransferClosure;
#[cfg(feature = "anyhow")]
pub use anyhow;
pub use byteorder;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use cast::slice_from_byte_buffer;
#[cfg(feature = "dart-opaque")]
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub use dart_sys_fork as dart_sys;
#[cfg(feature = "rust-async")]
pub use futures;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use js_sys;
pub use lazy_static::lazy_static;
#[cfg(feature = "rust-async")]
pub use misc_rust_async::*;
pub use pointer::*;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use wasm_bindgen;
8 changes: 4 additions & 4 deletions frb_rust/src/generalized_isolate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// cbindgen:ignore
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
mod web;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use web::*;

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
mod io;
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub use io::*;
8 changes: 4 additions & 4 deletions frb_rust/src/handler/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ pub enum FfiCallMode {
Sync,
}

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub trait TaskRetFutTrait: Send {}
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
impl<T: Send> TaskRetFutTrait for T {}

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub trait TaskRetFutTrait {}
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
impl<T> TaskRetFutTrait for T {}

// Originally there were things for StreamSink, but it was moved, so now it is empty
Expand Down
8 changes: 4 additions & 4 deletions frb_rust/src/misc/manual_impl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(feature = "chrono")]
#[inline]
pub fn decode_timestamp(ts: i64) -> Timestamp {
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
const PRECISION: i64 = 1_000;
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
const PRECISION: i64 = 1_000_000;

let s = ts / PRECISION;
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn decode_uuid(id: Vec<u8>) -> uuid::Uuid {
mod tests {
#[test]
fn test_decode_timestamp() {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
{
// input in microseconds
let input: i64 = 3_496_567_123;
Expand All @@ -62,7 +62,7 @@ mod tests {
assert_eq!(ns, 567_123_000);
}

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
{
// input in milliseconds
let input: i64 = 3_496_567;
Expand Down
4 changes: 2 additions & 2 deletions frb_rust/src/misc/user_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn setup_default_user_utils() {
}

fn setup_backtrace() {
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
if std::env::var("RUST_BACKTRACE").err() == Some(std::env::VarError::NotPresent) {
std::env::set_var("RUST_BACKTRACE", "1");
} else {
Expand All @@ -33,7 +33,7 @@ fn setup_log_to_console() {
.level_filter(log::LevelFilter::Trace)
.init();

#[cfg(wasm)]
#[cfg(target_family = "wasm")]
let _ = crate::misc::web_utils::WebConsoleLogger::init();

// TODO add more platforms
Expand Down
8 changes: 4 additions & 4 deletions frb_rust/src/platform_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// cbindgen:ignore
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
mod web;
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use web::*;

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
mod io;
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub use io::*;
8 changes: 4 additions & 4 deletions frb_rust/src/rust_async/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#[cfg(feature = "rust-async")]
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
mod io;
#[cfg(feature = "rust-async")]
#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
pub use io::*;

#[cfg(feature = "rust-async")]
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
mod web;
#[cfg(feature = "rust-async")]
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub use web::*;

#[cfg(not(feature = "rust-async"))]
Expand Down
2 changes: 1 addition & 1 deletion frb_rust/src/rust_auto_opaque/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tests {
assert_eq!(*opaque.try_write().unwrap(), 42);
}

#[cfg(not(wasm))]
#[cfg(not(target_family = "wasm"))]
#[tokio::test]
async fn test_api_async() {
let opaque = RustAutoOpaqueNom::new(42);
Expand Down
2 changes: 1 addition & 1 deletion frb_rust/src/third_party/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#[cfg(wasm)]
#[cfg(target_family = "wasm")]
pub(crate) mod wasm_bindgen;
Loading

0 comments on commit 09d3194

Please sign in to comment.