Skip to content

Commit

Permalink
Don't export run_js to the library (#249)
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
  • Loading branch information
luca-della-vedova authored Dec 31, 2024
1 parent 2402c98 commit 7ef0935
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"rmf_site_editor",
"rmf_site_editor_web",
"rmf_site_format",
]

Expand Down
2 changes: 0 additions & 2 deletions rmf_site_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]}
10 changes: 0 additions & 10 deletions rmf_site_editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>) {
let mut app = App::new();
let mut _headless_export = None;
Expand Down
13 changes: 13 additions & 0 deletions rmf_site_editor_web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions rmf_site_editor_web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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![]);
}
4 changes: 2 additions & 2 deletions scripts/build-web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<body>
<canvas id="rmf_site_editor_canvas">
<script type="module">
import init from "./librmf_site_editor.js";
import init from "./librmf_site_editor_web.js";
document.addEventListener('contextmenu', function(evt) { evt.preventDefault(); });
init("./librmf_site_editor_bg_optimized.wasm").then(function (wasm) {
init("./librmf_site_editor_web_bg_optimized.wasm").then(function (wasm) {
wasm.run_js();
});
</script>
Expand Down

0 comments on commit 7ef0935

Please sign in to comment.