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"]
[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-corelib = { version = "=0.0.5", path="../../sixtyfps_runtime/corelib" }

View file

@ -11,13 +11,13 @@ LICENSE END */
#[doc(hidden)]
#[cold]
pub fn use_modules() {
pub extern "C" fn use_modules() -> usize {
sixtyfps_rendering_backend_default::use_modules();
sixtyfps_corelib::use_modules()
}
use sixtyfps_rendering_backend_default::backend;
#[cfg(not(target_arch = "wasm32"))]
use sixtyfps_corelib::window::ffi::ComponentWindowOpaque;
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
rtti = []
femtovg_backend = ["femtovg"]
ffi = []
[dependencies]
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);
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
#![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 {
#![allow(unsafe_code)]

View file

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

View file

@ -76,6 +76,8 @@ pub use graphics::PathData;
#[cold]
#[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() -> usize {
#[cfg(feature = "ffi")]
{
tests::sixtyfps_mock_elapsed_time as usize
+ callbacks::ffi::sixtyfps_callback_init as usize
+ sharedvector::ffi::sixtyfps_shared_vector_empty as usize
@ -89,3 +91,8 @@ pub fn use_modules() -> 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);
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
use super::*;
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);
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
use super::*;

View file

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

View file

@ -303,7 +303,7 @@ fn lower_bound<T>(vec: &Vec<T>, mut less_than: impl FnMut(&T) -> bool) -> usize
left
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
#![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
/// from outside the Rust language.
#[cfg(feature = "ffi")]
pub mod ffi {
#![allow(unsafe_code)]

View file

@ -71,6 +71,7 @@ pub use default_backend::{
#[cold]
#[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() {
sixtyfps_corelib::use_modules();
default_backend::use_modules();
#[cfg(feature = "sixtyfps-rendering-backend-qt")]
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)]
#[cold]
#[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() {
sixtyfps_corelib::use_modules();
}
pub fn use_modules() {}
pub type NativeWidgets = ();
pub type NativeGlobals = ();

View file

@ -33,7 +33,6 @@ mod key_generated;
#[cold]
#[cfg(not(target_arch = "wasm32"))]
pub fn use_modules() -> usize {
sixtyfps_corelib::use_modules() + {
#[cfg(no_qt)]
{
0
@ -43,7 +42,6 @@ pub fn use_modules() -> usize {
(&widgets::NativeButtonVTable) as *const _ as usize
}
}
}
/// NativeWidgets and NativeGlobals are "type list" containing all the native widgets and global types.
///