Add a fii feature so that we don't compile in the ffi code if not required

This commit is contained in:
Olivier Goffart 2021-03-16 18:09:57 +01:00
parent 287670c140
commit 35cce45cbc
18 changed files with 43 additions and 38 deletions

View file

@ -14,6 +14,6 @@ path = "lib.rs"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
sixtyfps-corelib = { version = "=0.0.5", path="../../sixtyfps_runtime/corelib", features = ["ffi"] }
sixtyfps-rendering-backend-default = { version = "=0.0.5", path="../../sixtyfps_runtime/rendering_backends/default" } sixtyfps-rendering-backend-default = { version = "=0.0.5", path="../../sixtyfps_runtime/rendering_backends/default" }
sixtyfps-corelib = { version = "=0.0.5", path="../../sixtyfps_runtime/corelib" }

View file

@ -11,13 +11,13 @@ LICENSE END */
#[doc(hidden)] #[doc(hidden)]
#[cold] #[cold]
pub fn use_modules() { pub extern "C" fn use_modules() -> usize {
sixtyfps_rendering_backend_default::use_modules(); sixtyfps_rendering_backend_default::use_modules();
sixtyfps_corelib::use_modules()
} }
use sixtyfps_rendering_backend_default::backend; use sixtyfps_rendering_backend_default::backend;
#[cfg(not(target_arch = "wasm32"))]
use sixtyfps_corelib::window::ffi::ComponentWindowOpaque; use sixtyfps_corelib::window::ffi::ComponentWindowOpaque;
use sixtyfps_corelib::window::ComponentWindow; use sixtyfps_corelib::window::ComponentWindow;

View file

@ -16,6 +16,7 @@ path = "lib.rs"
# Allow the vewer to query at runtime information about item types # Allow the vewer to query at runtime information about item types
rtti = [] rtti = []
femtovg_backend = ["femtovg"] femtovg_backend = ["femtovg"]
ffi = []
[dependencies] [dependencies]
image = { version = "0.23.12", default-features = false, features = [ "png", "jpeg" ] } image = { version = "0.23.12", default-features = false, features = [ "png", "jpeg" ] }

View file

@ -69,7 +69,7 @@ fn callback_simple_test() {
assert_eq!(c.pressed.get(), true); assert_eq!(c.pressed.get(), true);
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -82,7 +82,7 @@ pub fn init_component_items<Base>(
}) })
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -141,7 +141,7 @@ pub trait FontMetrics {
fn height(&self) -> f32; fn height(&self) -> f32;
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -317,7 +317,7 @@ fn test_brighter_darker() {
assert_eq!(blue.darker(0.5), Color::from_rgb_u8(0, 0, 85)); assert_eq!(blue.darker(0.5), Color::from_rgb_u8(0, 0, 85));
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]
use super::*; use super::*;

View file

@ -278,7 +278,7 @@ pub fn visit_item_tree<Base>(
} }
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -778,7 +778,7 @@ pub fn solve_path_layout(data: &PathLayoutData) {
} }
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -76,16 +76,23 @@ pub use graphics::PathData;
#[cold] #[cold]
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() -> usize { pub fn use_modules() -> usize {
tests::sixtyfps_mock_elapsed_time as usize #[cfg(feature = "ffi")]
+ callbacks::ffi::sixtyfps_callback_init as usize {
+ sharedvector::ffi::sixtyfps_shared_vector_empty as usize tests::sixtyfps_mock_elapsed_time as usize
+ layout::ffi::sixtyfps_solve_grid_layout as usize + callbacks::ffi::sixtyfps_callback_init as usize
+ item_tree::ffi::sixtyfps_visit_item_tree as usize + sharedvector::ffi::sixtyfps_shared_vector_empty as usize
+ graphics::ffi::sixtyfps_new_path_elements as usize + layout::ffi::sixtyfps_solve_grid_layout as usize
+ properties::ffi::sixtyfps_property_init as usize + item_tree::ffi::sixtyfps_visit_item_tree as usize
+ string::ffi::sixtyfps_shared_string_bytes as usize + graphics::ffi::sixtyfps_new_path_elements as usize
+ window::ffi::sixtyfps_component_window_drop as usize + properties::ffi::sixtyfps_property_init as usize
+ component::ffi::sixtyfps_component_init_items as usize + string::ffi::sixtyfps_shared_string_bytes as usize
+ timers::ffi::sixtyfps_timer_start as usize + window::ffi::sixtyfps_component_window_drop as usize
+ graphics::color::ffi::sixtyfps_color_brighter as usize + component::ffi::sixtyfps_component_init_items as usize
+ timers::ffi::sixtyfps_timer_start as usize
+ graphics::color::ffi::sixtyfps_color_brighter as usize
}
#[cfg(not(feature = "ffi"))]
{
0
}
} }

View file

@ -1351,7 +1351,7 @@ fn test_property_listener_scope() {
assert!(ok); assert!(ok);
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
use super::*; use super::*;
use crate::graphics::{Brush, Color}; use crate::graphics::{Brush, Color};

View file

@ -459,7 +459,7 @@ fn invalid_capacity_test() {
let _: SharedVector<u8> = SharedVector::with_capacity(usize::MAX / 2 - 1000); let _: SharedVector<u8> = SharedVector::with_capacity(usize::MAX / 2 - 1000);
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
use super::*; use super::*;

View file

@ -316,7 +316,7 @@ fn simple_test() {
); );
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
use super::*; use super::*;

View file

@ -303,7 +303,7 @@ fn lower_bound<T>(vec: &Vec<T>, mut less_than: impl FnMut(&T) -> bool) -> usize
left left
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "ffi")]
pub(crate) mod ffi { pub(crate) mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -276,9 +276,9 @@ impl ComponentWindow {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
/// This module contains the functions needed to interface with the event loop and window traits /// This module contains the functions needed to interface with the event loop and window traits
/// from outside the Rust language. /// from outside the Rust language.
#[cfg(feature = "ffi")]
pub mod ffi { pub mod ffi {
#![allow(unsafe_code)] #![allow(unsafe_code)]

View file

@ -71,6 +71,7 @@ pub use default_backend::{
#[cold] #[cold]
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() { pub fn use_modules() {
sixtyfps_corelib::use_modules();
default_backend::use_modules(); default_backend::use_modules();
#[cfg(feature = "sixtyfps-rendering-backend-qt")] #[cfg(feature = "sixtyfps-rendering-backend-qt")]
sixtyfps_rendering_backend_qt::use_modules(); sixtyfps_rendering_backend_qt::use_modules();

View file

@ -1457,9 +1457,7 @@ pub fn create_gl_window_with_canvas_id(canvas_id: String) -> ComponentWindow {
#[doc(hidden)] #[doc(hidden)]
#[cold] #[cold]
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() { pub fn use_modules() {}
sixtyfps_corelib::use_modules();
}
pub type NativeWidgets = (); pub type NativeWidgets = ();
pub type NativeGlobals = (); pub type NativeGlobals = ();

View file

@ -33,15 +33,13 @@ mod key_generated;
#[cold] #[cold]
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() -> usize { pub fn use_modules() -> usize {
sixtyfps_corelib::use_modules() + { #[cfg(no_qt)]
#[cfg(no_qt)] {
{ 0
0 }
} #[cfg(not(no_qt))]
#[cfg(not(no_qt))] {
{ (&widgets::NativeButtonVTable) as *const _ as usize
(&widgets::NativeButtonVTable) as *const _ as usize
}
} }
} }