From 7ef0935984346cc1e404748dafc0eb4417cd61ae Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Tue, 31 Dec 2024 16:14:32 +0800 Subject: [PATCH] Don't export run_js to the library (#249) Signed-off-by: Luca Della Vedova --- .gitignore | 10 +++++----- Cargo.lock | 11 +++++++++-- Cargo.toml | 1 + rmf_site_editor/Cargo.toml | 2 -- rmf_site_editor/src/lib.rs | 10 ---------- rmf_site_editor_web/Cargo.toml | 13 +++++++++++++ rmf_site_editor_web/src/lib.rs | 9 +++++++++ scripts/build-web.sh | 4 ++-- web/index.html | 4 ++-- 9 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 rmf_site_editor_web/Cargo.toml create mode 100644 rmf_site_editor_web/src/lib.rs diff --git a/.gitignore b/.gitignore index 5e89a5153..fbc6b3a2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ target -web/librmf_site_editor.d.ts -web/librmf_site_editor.js -web/librmf_site_editor_bg.wasm -web/librmf_site_editor_bg_optimized.wasm -web/librmf_site_editor_bg.wasm.d.ts +web/librmf_site_editor_web.d.ts +web/librmf_site_editor_web.js +web/librmf_site_editor_web_bg.wasm +web/librmf_site_editor_web_bg_optimized.wasm +web/librmf_site_editor_web_bg.wasm.d.ts /test_output/ diff --git a/Cargo.lock b/Cargo.lock index 074fc5746..07a798342 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4017,7 +4017,6 @@ dependencies = [ "bevy_stl", "bitfield", "clap", - "console_error_panic_hook", "crossbeam-channel", "dirs", "ehttp", @@ -4040,10 +4039,18 @@ dependencies = [ "tracing-subscriber", "urdf-rs", "utm", - "wasm-bindgen", "yaserde", ] +[[package]] +name = "rmf_site_editor_web" +version = "0.0.1" +dependencies = [ + "console_error_panic_hook", + "rmf_site_editor", + "wasm-bindgen", +] + [[package]] name = "rmf_site_format" version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml index 95f833d85..a35a2e461 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "rmf_site_editor", + "rmf_site_editor_web", "rmf_site_format", ] diff --git a/rmf_site_editor/Cargo.toml b/rmf_site_editor/Cargo.toml index 998396e6b..4f66bc591 100644 --- a/rmf_site_editor/Cargo.toml +++ b/rmf_site_editor/Cargo.toml @@ -27,7 +27,6 @@ smallvec = "*" serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.8.23" serde_json = "1.0" -wasm-bindgen = "=0.2.93" futures-lite = "1.12.0" bevy = { version = "0.12", features = ["pnm", "jpeg", "tga"] } dirs = "5.0" @@ -56,5 +55,4 @@ clap = { version = "4.0.10", features = ["color", "derive", "help", "usage", "su bevy_impulse = { git = "https://github.com/open-rmf/bevy_impulse", branch = "main" } [target.'cfg(target_arch = "wasm32")'.dependencies] -console_error_panic_hook = "0.1.7" bevy_impulse = { git = "https://github.com/open-rmf/bevy_impulse", branch = "main", features = ["single_threaded_async"]} diff --git a/rmf_site_editor/src/lib.rs b/rmf_site_editor/src/lib.rs index 9614e4811..f53ed940e 100644 --- a/rmf_site_editor/src/lib.rs +++ b/rmf_site_editor/src/lib.rs @@ -3,8 +3,6 @@ use bevy_egui::EguiPlugin; #[cfg(not(target_arch = "wasm32"))] use clap::Parser; use main_menu::MainMenuPlugin; -#[cfg(target_arch = "wasm32")] -use wasm_bindgen::prelude::*; pub mod aabb; pub mod animate; @@ -95,14 +93,6 @@ impl AppState { } } -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen] -pub fn run_js() { - extern crate console_error_panic_hook; - std::panic::set_hook(Box::new(console_error_panic_hook::hook)); - run(vec!["web".to_owned()]); -} - pub fn run(command_line_args: Vec) { let mut app = App::new(); let mut _headless_export = None; diff --git a/rmf_site_editor_web/Cargo.toml b/rmf_site_editor_web/Cargo.toml new file mode 100644 index 000000000..98a0cd33b --- /dev/null +++ b/rmf_site_editor_web/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "rmf_site_editor_web" +version = "0.0.1" +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] +name = "librmf_site_editor_web" + +[dependencies] +wasm-bindgen = "=0.2.93" +rmf_site_editor = { path = "../rmf_site_editor" } +console_error_panic_hook = "0.1.7" diff --git a/rmf_site_editor_web/src/lib.rs b/rmf_site_editor_web/src/lib.rs new file mode 100644 index 000000000..f6beef433 --- /dev/null +++ b/rmf_site_editor_web/src/lib.rs @@ -0,0 +1,9 @@ +use librmf_site_editor::run; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn run_js() { + extern crate console_error_panic_hook; + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + run(vec![]); +} diff --git a/scripts/build-web.sh b/scripts/build-web.sh index 16ed5761d..b65c8a493 100755 --- a/scripts/build-web.sh +++ b/scripts/build-web.sh @@ -4,6 +4,6 @@ set -o errexit export CARGO_PROFILE_RELEASE_LTO=true export CARGO_PROFILE_RELEASE_OPT_LEVEL=z cargo build --target wasm32-unknown-unknown --release -RUST_BACKTRACE=full wasm-bindgen --target web --out-dir web target/wasm32-unknown-unknown/release/librmf_site_editor.wasm +RUST_BACKTRACE=full wasm-bindgen --target web --out-dir web target/wasm32-unknown-unknown/release/librmf_site_editor_web.wasm cd web -wasm-opt -Oz -o librmf_site_editor_bg_optimized.wasm librmf_site_editor_bg.wasm +wasm-opt -Oz -o librmf_site_editor_web_bg_optimized.wasm librmf_site_editor_web_bg.wasm diff --git a/web/index.html b/web/index.html index f08a3d9fd..ea1150eb6 100644 --- a/web/index.html +++ b/web/index.html @@ -18,9 +18,9 @@