From f087cc18bc6af744ffbbee9ebb2e6fabdfdc9200 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 26 Feb 2021 17:04:49 +0100 Subject: [PATCH] Remove extern "C" functions from wasm module We don't need these functions and their export. They account for ~20kb in the optimized .wasm - plus JS glue code. --- sixtyfps_runtime/corelib/callbacks.rs | 1 + sixtyfps_runtime/corelib/component.rs | 1 + sixtyfps_runtime/corelib/graphics.rs | 1 + sixtyfps_runtime/corelib/graphics/color.rs | 1 + sixtyfps_runtime/corelib/graphics/path.rs | 1 + sixtyfps_runtime/corelib/item_tree.rs | 1 + sixtyfps_runtime/corelib/layout.rs | 1 + sixtyfps_runtime/corelib/lib.rs | 1 + sixtyfps_runtime/corelib/properties.rs | 3 ++- sixtyfps_runtime/corelib/sharedvector.rs | 1 + sixtyfps_runtime/corelib/string.rs | 1 + sixtyfps_runtime/corelib/timers.rs | 1 + sixtyfps_runtime/corelib/window.rs | 1 + sixtyfps_runtime/rendering_backends/default/lib.rs | 2 ++ sixtyfps_runtime/rendering_backends/gl/lib.rs | 1 + sixtyfps_runtime/rendering_backends/qt/lib.rs | 1 + 16 files changed, 18 insertions(+), 1 deletion(-) diff --git a/sixtyfps_runtime/corelib/callbacks.rs b/sixtyfps_runtime/corelib/callbacks.rs index 9f2d396aa..2a8123fcd 100644 --- a/sixtyfps_runtime/corelib/callbacks.rs +++ b/sixtyfps_runtime/corelib/callbacks.rs @@ -69,6 +69,7 @@ fn callback_simple_test() { assert_eq!(c.pressed.get(), true); } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/component.rs b/sixtyfps_runtime/corelib/component.rs index 4f5b5daa0..a8e4060e1 100644 --- a/sixtyfps_runtime/corelib/component.rs +++ b/sixtyfps_runtime/corelib/component.rs @@ -82,6 +82,7 @@ pub fn init_component_items( }) } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index d3e04dc98..6dfc54434 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -127,6 +127,7 @@ pub trait FontMetrics { fn height(&self) -> f32; } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/graphics/color.rs b/sixtyfps_runtime/corelib/graphics/color.rs index 1d09b0ec8..6779748d2 100644 --- a/sixtyfps_runtime/corelib/graphics/color.rs +++ b/sixtyfps_runtime/corelib/graphics/color.rs @@ -317,6 +317,7 @@ fn test_brighter_darker() { assert_eq!(blue.darker(0.5), Color::from_rgb_u8(0, 0, 85)); } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] use super::*; diff --git a/sixtyfps_runtime/corelib/graphics/path.rs b/sixtyfps_runtime/corelib/graphics/path.rs index b4cd85519..78b2c2fb3 100644 --- a/sixtyfps_runtime/corelib/graphics/path.rs +++ b/sixtyfps_runtime/corelib/graphics/path.rs @@ -400,6 +400,7 @@ impl PathData { } } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/item_tree.rs b/sixtyfps_runtime/corelib/item_tree.rs index fab330c62..a2fe46433 100644 --- a/sixtyfps_runtime/corelib/item_tree.rs +++ b/sixtyfps_runtime/corelib/item_tree.rs @@ -278,6 +278,7 @@ pub fn visit_item_tree( } } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/layout.rs b/sixtyfps_runtime/corelib/layout.rs index dacd2a6e2..ce2e61693 100644 --- a/sixtyfps_runtime/corelib/layout.rs +++ b/sixtyfps_runtime/corelib/layout.rs @@ -778,6 +778,7 @@ pub fn solve_path_layout(data: &PathLayoutData) { } } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/lib.rs b/sixtyfps_runtime/corelib/lib.rs index 15b824835..fb2fa8d08 100644 --- a/sixtyfps_runtime/corelib/lib.rs +++ b/sixtyfps_runtime/corelib/lib.rs @@ -74,6 +74,7 @@ pub use graphics::PathData; /// This only use functions from modules which are not otherwise used. #[doc(hidden)] #[cold] +#[cfg(not(target_arch = "wasm32"))] pub fn use_modules() -> usize { tests::sixtyfps_mock_elapsed_time as usize + callbacks::ffi::sixtyfps_callback_init as usize diff --git a/sixtyfps_runtime/corelib/properties.rs b/sixtyfps_runtime/corelib/properties.rs index 417806765..524504598 100644 --- a/sixtyfps_runtime/corelib/properties.rs +++ b/sixtyfps_runtime/corelib/properties.rs @@ -97,7 +97,6 @@ use core::cell::{Cell, RefCell, UnsafeCell}; use core::{marker::PhantomPinned, pin::Pin}; use std::rc::Rc; -use crate::graphics::{Brush, Color}; use crate::items::PropertyAnimation; /// The return value of a binding @@ -1352,8 +1351,10 @@ fn test_property_listener_scope() { assert!(ok); } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { use super::*; + use crate::graphics::{Brush, Color}; use core::pin::Pin; #[allow(non_camel_case_types)] diff --git a/sixtyfps_runtime/corelib/sharedvector.rs b/sixtyfps_runtime/corelib/sharedvector.rs index 553754bed..afc5b5f2e 100644 --- a/sixtyfps_runtime/corelib/sharedvector.rs +++ b/sixtyfps_runtime/corelib/sharedvector.rs @@ -459,6 +459,7 @@ fn invalid_capacity_test() { let _: SharedVector = SharedVector::with_capacity(usize::MAX / 2 - 1000); } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { use super::*; diff --git a/sixtyfps_runtime/corelib/string.rs b/sixtyfps_runtime/corelib/string.rs index e83d073b4..23db04b9e 100644 --- a/sixtyfps_runtime/corelib/string.rs +++ b/sixtyfps_runtime/corelib/string.rs @@ -316,6 +316,7 @@ fn simple_test() { ); } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { use super::*; diff --git a/sixtyfps_runtime/corelib/timers.rs b/sixtyfps_runtime/corelib/timers.rs index 93f6ef70a..3096c994f 100644 --- a/sixtyfps_runtime/corelib/timers.rs +++ b/sixtyfps_runtime/corelib/timers.rs @@ -303,6 +303,7 @@ fn lower_bound(vec: &Vec, mut less_than: impl FnMut(&T) -> bool) -> usize left } +#[cfg(not(target_arch = "wasm32"))] pub(crate) mod ffi { #![allow(unsafe_code)] diff --git a/sixtyfps_runtime/corelib/window.rs b/sixtyfps_runtime/corelib/window.rs index c5c6fea24..a4da8fc74 100644 --- a/sixtyfps_runtime/corelib/window.rs +++ b/sixtyfps_runtime/corelib/window.rs @@ -271,6 +271,7 @@ 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. pub mod ffi { diff --git a/sixtyfps_runtime/rendering_backends/default/lib.rs b/sixtyfps_runtime/rendering_backends/default/lib.rs index ac9cce1a9..594d85698 100644 --- a/sixtyfps_runtime/rendering_backends/default/lib.rs +++ b/sixtyfps_runtime/rendering_backends/default/lib.rs @@ -69,6 +69,7 @@ pub use default_backend::{ #[doc(hidden)] #[cold] +#[cfg(not(target_arch = "wasm32"))] pub fn use_modules() { default_backend::use_modules(); #[cfg(feature = "sixtyfps-rendering-backend-qt")] @@ -77,6 +78,7 @@ pub fn use_modules() { sixtyfps_rendering_backend_gl::use_modules(); } +#[cfg(not(target_arch = "wasm32"))] pub mod ffi { use sixtyfps_corelib::window::ffi::ComponentWindowOpaque; use sixtyfps_corelib::window::ComponentWindow; diff --git a/sixtyfps_runtime/rendering_backends/gl/lib.rs b/sixtyfps_runtime/rendering_backends/gl/lib.rs index bea372f2c..9bc9d01e1 100644 --- a/sixtyfps_runtime/rendering_backends/gl/lib.rs +++ b/sixtyfps_runtime/rendering_backends/gl/lib.rs @@ -1399,6 +1399,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(); } diff --git a/sixtyfps_runtime/rendering_backends/qt/lib.rs b/sixtyfps_runtime/rendering_backends/qt/lib.rs index d7887f6d1..3783e4d65 100644 --- a/sixtyfps_runtime/rendering_backends/qt/lib.rs +++ b/sixtyfps_runtime/rendering_backends/qt/lib.rs @@ -31,6 +31,7 @@ mod key_generated; #[doc(hidden)] #[cold] +#[cfg(not(target_arch = "wasm32"))] pub fn use_modules() -> usize { sixtyfps_corelib::use_modules() + { #[cfg(no_qt)]