Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 🤖 optimize wasm binary for size #73

Merged
merged 12 commits into from
Feb 21, 2024
Merged
2 changes: 2 additions & 0 deletions .mac-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ echo
echo "Installing rust nightly ..."
rustup install nightly-x86_64-apple-darwin

rustup component add rust-src --toolchain nightly

echo
echo "Installing rust target(s) ..."
rustup target add aarch64-linux-android \
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ endef

define CARGO_BUILD
source $(EMSDK_DIR)/$(EMSDK)_env.sh && \
cargo build \
RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--release
Expand Down
9 changes: 9 additions & 0 deletions dotlottie-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ version = "0.1.14"
edition = "2021"
build = "build.rs"

[profile.release]
lto = true
opt-level = "s"
strip = true
codegen-units = 1
panic = "abort"

[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
name = "dotlottie_player"
Expand All @@ -13,13 +20,15 @@ name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[dependencies]
# uncomment uniffi v0.25.3 when building with uniffi-cpp-bindgen targetting C++/WASM
# uniffi = { version = "0.25.3", features = ["cli"] }
uniffi = { version = "0.26.0", features = ["cli"] }
dotlottie_player = { path = "../dotlottie-rs" }
dotlottie_fms = { path = "../dotlottie-fms" }
cfg-if = "1.0"

[build-dependencies]
# uncomment uniffi v0.25.3 when building with uniffi-cpp-bindgen targetting C++/WASM
# uniffi = { version = "0.25.3", features = ["build"] }
uniffi = { version = "0.26.0", features = ["build"] }
lazy_static = "1.4"
29 changes: 14 additions & 15 deletions dotlottie-ffi/src/dotlottie_player_cpp.udl
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
namespace dotlottie_player {
};

///[Trait]
///interface Observer {
/// void on_load();
/// void on_load_error();
/// void on_play();
/// void on_pause();
/// void on_stop();
/// void on_frame(f32 frame_no);
/// void on_render(f32 frame_no);
/// void on_loop(u32 loop_count);
/// void on_complete();
///};
/// [Trait]
/// interface Observer {
/// void on_load();
/// void on_play();
/// void on_pause();
/// void on_stop();
/// void on_frame(f32 frame_no);
/// void on_render(f32 frame_no);
/// void on_loop(u32 loop_count);
/// void on_complete();
/// };

enum Mode {
"Forward",
Expand Down Expand Up @@ -73,7 +72,7 @@ interface DotLottiePlayer {
boolean load_animation_path([ByRef] string animation_path, u32 width, u32 height);
boolean load_dotlottie_data([ByRef] bytes file_data, u32 width, u32 height);
boolean load_animation([ByRef] string animation_id, u32 width, u32 height);
/// Manifest? manifest();
/// Manifest? manifest();
string manifest_string();
u64 buffer_ptr();
u64 buffer_len();
Expand All @@ -96,7 +95,7 @@ interface DotLottiePlayer {
boolean render();
boolean resize(u32 width, u32 height);
void clear();
/// void subscribe(Observer observer);
/// void unsubscribe([ByRef] Observer observer);
/// void subscribe(Observer observer);
/// void unsubscribe([ByRef] Observer observer);
boolean is_complete();
};
16 changes: 4 additions & 12 deletions dotlottie-rs/src/dotlottie_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,6 @@ impl DotLottieRuntime {
self.loop_count
}

pub fn set_speed(&mut self, speed: f32) {
self.config.speed = if speed < 0.0 { 1.0 } else { speed };
}

pub fn speed(&self) -> f32 {
self.config.speed
}
Expand Down Expand Up @@ -761,6 +757,7 @@ impl DotLottiePlayer {
is_ok
}

#[cfg(not(target_arch = "wasm32"))]
pub fn manifest(&self) -> Option<Manifest> {
self.runtime.read().unwrap().manifest()
}
Expand All @@ -781,10 +778,6 @@ impl DotLottiePlayer {
self.runtime.write().unwrap().set_config(config);
}

pub fn set_speed(&self, speed: f32) {
self.runtime.write().unwrap().set_speed(speed);
}

pub fn speed(&self) -> f32 {
self.runtime.read().unwrap().speed()
}
Expand Down Expand Up @@ -919,21 +912,20 @@ impl DotLottiePlayer {
self.runtime.read().unwrap().config()
}

#[cfg(not(target_arch = "wasm32"))]
pub fn subscribe(&self, observer: Arc<dyn Observer>) {
self.observers.write().unwrap().push(observer);
}

pub fn manifest_string(&self) -> String {
match self.manifest() {
Some(manifest) => manifest.to_string(),
None => "{}".to_string(),
}
self.runtime.read().unwrap().manifest().unwrap().to_string()
}

pub fn is_complete(&self) -> bool {
self.runtime.read().unwrap().is_complete()
}

#[cfg(not(target_arch = "wasm32"))]
pub fn unsubscribe(&self, observer: &Arc<dyn Observer>) {
self.observers
.write()
Expand Down
Loading