From 5a035b37c2539d0bcb9924d342f555298170616d Mon Sep 17 00:00:00 2001 From: DavidOConnor Date: Sun, 21 Apr 2019 21:44:46 -0400 Subject: [PATCH] Updated to be IAW new build process --- .gitignore | 5 +---- Makefile.toml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 23 +++++------------------ build.ps1 | 5 ----- build.sh | 6 ------ pkg/.keep | 0 serve.py | 41 ----------------------------------------- 7 files changed, 56 insertions(+), 74 deletions(-) create mode 100644 Makefile.toml delete mode 100644 build.ps1 delete mode 100755 build.sh delete mode 100644 pkg/.keep delete mode 100644 serve.py diff --git a/.gitignore b/.gitignore index df2ac7d..84de0b9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,5 @@ Cargo.lock # Pycharm /.idea -pkg/*.wasm -pkg/*.d.ts -pkg/*.ts -pkg/*.js +pkg/* wasm-pack.log \ No newline at end of file diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..64208a8 --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,50 @@ +[env] +# all workspace members can use this Makefile +CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true" + +# ---- BUILD & CREATE WASMS ---- +[tasks.build] +description = "Build only Seed without examples" +workspace = false +command = "cargo" +args = ["build"] + +[tasks.build_release] +description = "Build only Seed without examples" +workspace = false +command = "cargo" +args = ["build", "--release"] + + +[tasks.create_wasms] +description = "Build examples with wasm-pack" +workspace = false +command = "cargo" +args = ["make", "create_wasm"] + +[tasks.all] +description = "Build all - Seed + examples and create wasms" +workspace = false +dependencies = ["build", "create_wasms"] + +[tasks.all_release] +description = "Build all - Seed + examples and create wasms, with the --release flag" +workspace = false +dependencies = ["build_release", "build_examples", "create_wasms"] + +[tasks.serve] +description = "Start server for given example" +install_crate = { crate_name = "https", binary = "http", test_arg = "--help" } +workspace = false +command = "http" +args = [] + +# ---- PRIVATE TASKS - run only inside another task ---- +# private atribute is ignored (bug?) + +[tasks.create_wasm] +description = "Build example with wasm-pack" +# private = true +install_crate = "wasm-pack" +command = "wasm-pack" +args = ["build", "--target", "no-modules", "--out-name", "package"] diff --git a/README.md b/README.md index 50fb7a2..a9512a5 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,16 @@ **To get started:** - Clone this repo + + - If you don't have Rust and wasm-bindgen installed, [Download it](https://www.rust-lang.org/tools/install), and run the following commands: `rustup update` `rustup target add wasm32-unknown-unknown` -`cargo install wasm-bindgen-cli` - -If you run into errors while installing `wasm-bindgen-cli`, you may need to install a C++ -build chain. On linux, run `sudo apt install build-essential`. On Windows, download and install -[Visual Studio 2017](https://visualstudio.microsoft.com/downloads/); when asked in the installer, -include the C++ workload. - - - Run `build.sh` or `build.ps1`, then start a dev server that supports WASM. -For example, with [Python](https://www.python.org/downloads/) installed, run `python serve.py`. -(Linux users may need to run `python3 serve.py`.) - -If you run into permission errors on `build.sh`, try this command -to allow executing the file:`chmod +x build.sh`. If you run into persmission errors on `build.ps1`, open Powershell as an administrator, and enter this command: `Set-ExecutionPolicy RemoteSigned`. - -Once you rename the crate in `Cargo.toml` (The `name` field under `[Package]`), make the -following change: +`cargo install cargo-make` -- Replace `appname` with your new name in either `build.sh`, or `build.ps1`, depending on your -operating system. +Run `cargo make all` in a terminal to build the app, and `cargo make serve` to start a dev server +on `127.0.0.0:8000`. diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 53a9bdf..0000000 --- a/build.ps1 +++ /dev/null @@ -1,5 +0,0 @@ -cargo build --target wasm32-unknown-unknown -wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg --out-name package - -#cargo build --target wasm32-unknown-unknown --release -#wasm-bindgen target/wasm32-unknown-unknown/release/appname.wasm --no-modules --out-dir ./pkg --out-name package \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index 12da0e5..0000000 --- a/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -cargo build --target wasm32-unknown-unknown -wasm-bindgen target/wasm32-unknown-unknown/debug/appname.wasm --no-modules --out-dir ./pkg --out-name package - -#cargo build --target wasm32-unknown-unknown --release -#wasm-bindgen target/wasm32-unknown-unknown/release/appname.wasm --no-modules --out-dir ./pkg --out-name package \ No newline at end of file diff --git a/pkg/.keep b/pkg/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/serve.py b/serve.py deleted file mode 100644 index 3dd9ef7..0000000 --- a/serve.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python3 - -import http.server -import os -import socketserver -import urllib -import sys - -PORT = 8000 - - -class Handler(http.server.SimpleHTTPRequestHandler): - # Allow SPA routing by redirecting subpaths. - def do_GET(self): - urlparts = urllib.parse.urlparse(self.path) - request_file_path = urlparts.path.strip('/') - if not os.path.exists(request_file_path): - self.path = '/' - - return http.server.SimpleHTTPRequestHandler.do_GET(self) - - -handler = Handler -# Add support for the WASM mime type. -handler.extensions_map.update({ - '.wasm': 'application/wasm', -}) - -socketserver.TCPServer.allow_reuse_address = True -print("Serving at port", PORT) -print("View at: http://localhost:{}/".format(PORT)) -# The context manager protocol is support only since python 3.6 and higher. -if (3 <= sys.version_info[0]) and (6 <= sys.version_info[1]): - with socketserver.TCPServer(("", PORT), handler) as httpd: - httpd.allow_reuse_address = True - httpd.serve_forever() -else: - httpd = socketserver.TCPServer(("", PORT), handler) - httpd.allow_reuse_address = True - httpd.serve_forever() - httpd.serve_close()