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.
This commit is contained in:
Simon Hausmann 2021-02-26 17:04:49 +01:00
parent 3d7eb6ac70
commit f087cc18bc
16 changed files with 18 additions and 1 deletions

View file

@ -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)]

View file

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

View file

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

View file

@ -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::*;

View file

@ -400,6 +400,7 @@ impl PathData {
}
}
#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod ffi {
#![allow(unsafe_code)]

View file

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

View file

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

View file

@ -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

View file

@ -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)]

View file

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

View file

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

View file

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

View file

@ -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 {

View file

@ -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;

View file

@ -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();
}

View file

@ -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)]