diff --git a/Cargo.toml b/Cargo.toml index 43b395e2..8cddeaab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,22 @@ regex = "0.2.*" string-interner = "0.6.*" lazy_static = "1.0.*" derive-new = "0.5.*" -cargo-wasm = "0.4.*" +#cargo-wasm = "0.4.*" +wasm-bindgen = "0.2.*" + +[profile.release] +lto = true +opt-level = 's' + +[lib] +crate-type = ["cdylib"] +name = "mango" +path = "src/lib.rs" + +#[[bin]] +#name = "mangoc" +#path = "src/mango/ui/cli/main.rs" + +#[[bin]] +#name = "mango-webi" +#path = "src/mango/ui/webi/compile_str.rs" diff --git a/README.rst b/README.rst index 2c822695..5f5e17db 100644 --- a/README.rst +++ b/README.rst @@ -38,14 +38,14 @@ These instructions were tested on Ubuntu 18.4 (using Bash). It should also work rustup toolchain install nightly rustup override set nightly # make sure you are in the mango directory - rustup target add wasm32-unknown-emscripten # emscritem for now + rustup target add wasm32-unknown-unknown --toolchain nightly * We need a few packages: .. code:: bash rustup component add rustfmt-preview - cargo install cargo-web + cargo install wasm-bindgen-cli * There are git commit hooks that you can use. They test that code is formatted well and compiles and commit messages are correctly formatted. You don't have to use them if you ensure these things yourself. If you want to use them: @@ -65,12 +65,7 @@ These instructions were tested on Ubuntu 18.4 (using Bash). It should also work cargo test --all cargo run --bin mango-cli -* To deploy the web version in release mode: - -.. code:: bash - - cargo web deploy --release - # then open target/deploy/index.html in a browser +* To deploy the web version in release mode, run the script `dev/build_web.sh` (or view it for the steps needed). It uses Python's SimpleHTTPServer, if you don't have that, you can still find the deployable code in `target/deploy`. * You're now ready to make changes! If you want to help, you're very welcome! Have a glance at CONTRIBUTING.rst_ if you have a minute. diff --git a/dev/build_web.sh b/dev/build_web.sh new file mode 100644 index 00000000..12bacf91 --- /dev/null +++ b/dev/build_web.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +pth="$(dirname $(dirname $(realpath -s $0)))" +echo $pth + +set -e # stop on error +set -o xtrace # print commands + +# Compile rust to wasm +# TODO: need release as workaround for a compile error in dependency; remove when that is resolved +cargo +nightly build --target wasm32-unknown-unknown --release + +# Copy the static files +outdir="$pth/target/deploy" +mkdir -p "$outdir" +cp -rf "$pth/static"/* "$outdir" + +# Prepare the wasm for use from js +wasm-bindgen --debug --no-modules --no-typescript "$pth/target/wasm32-unknown-unknown/release/mango.wasm" --out-dir "$outdir" + +# Start a simple webserver +( + cd "$outdir" + python -m SimpleHTTPServer +) diff --git a/src/lib.rs b/src/lib.rs index c7fe180e..6d88dc87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ +#![feature(proc_macro, wasm_custom_section, wasm_import_module)] extern crate core; +extern crate wasm_bindgen; #[macro_use] extern crate lazy_static; extern crate regex; @@ -8,8 +10,8 @@ extern crate derive_new; pub mod mango { // Utilities - pub mod cli; pub mod jit; + pub mod ui; pub mod util; // Types diff --git a/src/mango/token/collect/stream.rs b/src/mango/token/collect/stream.rs index 10ab1825..1b34486c 100644 --- a/src/mango/token/collect/stream.rs +++ b/src/mango/token/collect/stream.rs @@ -20,11 +20,12 @@ pub struct MemoryTokenStream { } impl MemoryTokenStream { - #[allow(dead_code)] + #[allow(dead_code)] // TODO: for now pub fn new(tokens: Vec) -> MemoryTokenStream { MemoryTokenStream { index: 0, tokens } } + #[allow(dead_code)] // TODO: for now pub fn to_text(&self) -> String { format!( " {}", diff --git a/src/mango/ui/cli/main.rs b/src/mango/ui/cli/main.rs new file mode 100644 index 00000000..eb941355 --- /dev/null +++ b/src/mango/ui/cli/main.rs @@ -0,0 +1,3 @@ +pub fn main() { + println!("welcome to Mango CLI!"); +} diff --git a/src/mango/cli/mod.rs b/src/mango/ui/cli/mod.rs similarity index 100% rename from src/mango/cli/mod.rs rename to src/mango/ui/cli/mod.rs diff --git a/src/mango/ui/mod.rs b/src/mango/ui/mod.rs new file mode 100644 index 00000000..2e8134b1 --- /dev/null +++ b/src/mango/ui/mod.rs @@ -0,0 +1,5 @@ +pub mod cli; +pub use self::cli::*; + +pub mod webi; +pub use self::webi::*; diff --git a/src/mango/ui/webi/compile_str.rs b/src/mango/ui/webi/compile_str.rs new file mode 100644 index 00000000..0a0c4825 --- /dev/null +++ b/src/mango/ui/webi/compile_str.rs @@ -0,0 +1,7 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn compile_string_to_wat(code: &str) -> String { + // TODO + format!("compiled: {}", code).to_owned() +} diff --git a/src/mango/ui/webi/mod.rs b/src/mango/ui/webi/mod.rs new file mode 100644 index 00000000..bd370a72 --- /dev/null +++ b/src/mango/ui/webi/mod.rs @@ -0,0 +1,2 @@ +pub mod compile_str; +pub use self::compile_str::compile_string_to_wat; diff --git a/src/mango/ui/webi/static/prepend-emscripten.js b/src/mango/ui/webi/static/prepend-emscripten.js new file mode 100644 index 00000000..21219ff1 --- /dev/null +++ b/src/mango/ui/webi/static/prepend-emscripten.js @@ -0,0 +1,3 @@ +/** + * Mango: Javascript prefix for emscripten target. + */ diff --git a/src/mango/ui/webi/static/prepend-general.js b/src/mango/ui/webi/static/prepend-general.js new file mode 100644 index 00000000..2168946e --- /dev/null +++ b/src/mango/ui/webi/static/prepend-general.js @@ -0,0 +1,3 @@ +/** + * Mango: General javascript prefix. + */ \ No newline at end of file diff --git a/static/index.html b/static/index.html new file mode 100644 index 00000000..bf0f00cf --- /dev/null +++ b/static/index.html @@ -0,0 +1,100 @@ + + + + + + + + + + + + + +
+
+

Mango (wasm)

+
// Type your Mango code here! + +
+ + + +
+
+
+ + + + + + + + + + + + + +