diff --git a/.cargo/config b/.cargo/config index 7f9d89b452..584d158f1c 100644 --- a/.cargo/config +++ b/.cargo/config @@ -2,3 +2,9 @@ test-gen-llvm = "test -p test_gen" test-gen-dev = "test -p roc_gen_dev -p test_gen --no-default-features --features gen-dev" test-gen-wasm = "test -p roc_gen_wasm -p test_gen --no-default-features --features gen-wasm" + +[target.wasm32-unknown-unknown] +# Rust compiler flags for minimum-sized .wasm binary in the web REPL +# opt-level=s Optimizations should focus more on size than speed +# lto=fat Spend extra effort on link-time optimization across crates +rustflags = ["-Copt-level=s", "-Clto=fat"] diff --git a/repl_wasm/Cargo.toml b/repl_wasm/Cargo.toml index 944d550955..61dad966be 100644 --- a/repl_wasm/Cargo.toml +++ b/repl_wasm/Cargo.toml @@ -26,7 +26,6 @@ roc_target = {path = "../compiler/roc_target"} roc_types = {path = "../compiler/types"} [features] -default = ["console_error_panic_hook"] wasmer = ["futures"] [package.metadata.wasm-pack.profile.profiling] diff --git a/repl_wasm/src/lib.rs b/repl_wasm/src/lib.rs index 0d1c6d9461..a1d66e6f8d 100644 --- a/repl_wasm/src/lib.rs +++ b/repl_wasm/src/lib.rs @@ -3,7 +3,7 @@ mod repl; // // Interface with external JS in the browser // -#[cfg(not(feature = "wasmer"))] +#[cfg(feature = "console_error_panic_hook")] extern crate console_error_panic_hook; #[cfg(not(feature = "wasmer"))] mod externs_js; diff --git a/repl_wasm/src/repl.rs b/repl_wasm/src/repl.rs index 9bbd2891af..95cb77be11 100644 --- a/repl_wasm/src/repl.rs +++ b/repl_wasm/src/repl.rs @@ -155,7 +155,7 @@ impl<'a> ReplApp<'a> for WasmReplApp<'a> { } pub async fn entrypoint_from_js(src: String) -> Result { - #[cfg(not(feature = "wasmer"))] + #[cfg(feature = "console_error_panic_hook")] console_error_panic_hook::set_once(); let arena = &Bump::new(); diff --git a/repl_www/build.sh b/repl_www/build.sh index 52a2121631..d9e157271c 100755 --- a/repl_www/build.sh +++ b/repl_www/build.sh @@ -26,11 +26,11 @@ cp -r repl_www/public/* $WWW_ROOT if [ -n "${REPL_DEBUG:-}" ] then # Leave out wasm-opt since it takes too long when debugging, and provide some debug options - cargo build --target wasm32-unknown-unknown -p roc_repl_wasm --release + cargo build --target wasm32-unknown-unknown -p roc_repl_wasm --release --features console_error_panic_hook wasm-bindgen --target web --keep-debug target/wasm32-unknown-unknown/release/roc_repl_wasm.wasm --out-dir repl_wasm/pkg/ else # A `--profiling` build is optimized and has debug info, so we get stack traces for compiler `todo!()` - wasm-pack build --profiling --target web repl_wasm + wasm-pack build --profiling --target web repl_wasm -- --features console_error_panic_hook fi cp repl_wasm/pkg/*.wasm $WWW_ROOT