commit 31322944a490c37a1ad52d8b195cdb51112c2393
parent 9415ea83efc9ffd160e8fe628c4114a763fc8351
Author: Marcel <mtrnord1@gmail.com>
Date: Sat, 25 Jul 2020 04:01:43 +0200
Further cargo-make improvements
Took 1 hour 34 minutes
Diffstat:
5 files changed, 59 insertions(+), 80 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -7,8 +7,13 @@ license = "AGPL-v3.0"
repository = "https://github.com/MTRNord/Daydream"
description = "A Matrix Web client written in Rust"
-[lib]
-crate-type = ["cdylib", "rlib"]
+[[bin]]
+name = "daydream_app"
+path = "src/bin/app.rs"
+
+[[bin]]
+name = "daydream_worker"
+path = "src/bin/native_worker.rs"
[dependencies]
console_error_panic_hook = { version = "0.1" }
diff --git a/Makefile.toml b/Makefile.toml
@@ -11,43 +11,74 @@ script_runner = "@shell"
script = [
'''
rm ./dist
-rm ./pkg
'''
]
[tasks.dist]
# TODO add scss task when it works
-dependencies = ["format", "wasm-clean", "wasm-build", "copy-files"]
+dependencies = ["format", "wasm-clean", "scss", "pure-build-app", "wasm-build", "pure-build-worker", "wasm-build-worker", "copy-files"]
[tasks.dist-debug]
# TODO add scss task when it works
-dependencies = ["format", "wasm-clean", "wasm-build-debug", "copy-files"]
+dependencies = ["format", "wasm-clean", "scss", "pure-build-app-debug", "wasm-build-debug", "pure-build-worker-debug", "wasm-build-worker-debug", "copy-files"]
[tasks.run]
watch = {watch = ["./src", "./static", "./startup_helper"], poll = true}
dependencies = ["dist-debug", "start-server"]
[tasks.start-server]
-install_crate = { crate_name = "sfz", binary = "sfz", test_arg = "--help" }
-command = "sfz"
-args = ["./dist"]
+script_runner = "@shell"
+script = [
+'''
+cd dist
+python -m http.server
+'''
+]
+
+[tasks.pure-build-app]
+command = "cargo"
+args = ["build", "--release", "--target", "wasm32-unknown-unknown", "--bin", "daydream_app"]
+
+[tasks.pure-build-app-debug]
+command = "cargo"
+args = ["build", "--target", "wasm32-unknown-unknown", "--bin", "daydream_app"]
+
+[tasks.pure-build-worker]
+command = "cargo"
+args = ["build", "--release", "--target", "wasm32-unknown-unknown", "--bin", "daydream_worker"]
+
+[tasks.pure-build-worker-debug]
+command = "cargo"
+args = ["build", "--target", "wasm32-unknown-unknown", "--bin", "daydream_worker"]
[tasks.wasm-build]
-command = "wasm-pack"
-args = ["build", "--release", "--target", "web"]
+install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" }
+command = "wasm-bindgen"
+args = ["--no-typescript", "--release", "--out-dir", "./dist/", "--target", "web", "--out-name", "daydream", "./target/wasm32-unknown-unknown/release/daydream_app.wasm"]
[tasks.wasm-build-debug]
-command = "wasm-pack"
-args = ["build", "--debug", "--target", "web"]
+install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" }
+command = "wasm-bindgen"
+args = ["--no-typescript", "--debug", "--out-dir", "./dist/", "--target", "web", "--out-name", "daydream", "./target/wasm32-unknown-unknown/debug/daydream_app.wasm"]
+
+[tasks.wasm-build-worker]
+install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" }
+command = "wasm-bindgen"
+args = ["--no-typescript", "--release", "--out-dir", "./dist/", "--target", "no-modules", "--out-name", "worker", "./target/wasm32-unknown-unknown/release/daydream_worker.wasm"]
+
+[tasks.wasm-build-worker-debug]
+install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" }
+command = "wasm-bindgen"
+args = ["--no-typescript", "--debug", "--out-dir", "./dist/", "--target", "no-modules", "--out-name", "worker", "./target/wasm32-unknown-unknown/debug/daydream_worker.wasm"]
[tasks.copy-files]
script_runner = "@shell"
script = [
'''
-mkdir dist
cp static/index_rust_only.html dist/index.html
-cp pkg/daydream.js dist/daydream.js
-cp pkg/daydream_bg.wasm dist/daydream_bg.wasm
+mkdir dist/images
+cp static/images/* dist/images/*
+cp static/normalize.css dist/normalize.css
'''
]
@@ -64,5 +95,6 @@ install_crate = { crate_name = "xtr", binary = "xtr", test_arg = "--help" }
[tasks.scss]
install_crate = { crate_name = "grass", binary = "grass", test_arg = "--help" }
+install_crate_args = ["--git", "https://github.com/connorskees/grass"]
command = "grass"
args = ["static/style.scss", "dist/style.css"]
diff --git a/src/lib.rs b/src/lib.rs
@@ -1,60 +1,6 @@
#![recursion_limit = "512"]
-extern crate console_error_panic_hook;
-//extern crate wee_alloc;
-
-use console_error_panic_hook::set_once as set_panic_hook;
-use i18n_embed::{language_loader, I18nEmbed, WebLanguageRequester};
-use rust_embed::RustEmbed;
-use wasm_bindgen::prelude::*;
pub mod app;
mod constants;
mod errors;
pub mod utils;
-
-#[derive(RustEmbed, I18nEmbed)]
-#[folder = "i18n/mo"] // path to the compiled localization resources
-struct Translations;
-
-language_loader!(DaydreamLanguageLoader);
-
-//#[global_allocator]
-//static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
-
-//====== Running the primary frontend ======//
-#[wasm_bindgen]
-pub fn run_app() -> Result<(), JsValue> {
- // If the `console_error_panic_hook` feature is enabled this will set a panic hook, otherwise
- // it will do nothing.
- set_panic_hook();
- wasm_logger::init(wasm_logger::Config::default());
-
- let translations = Translations {};
- let language_loader = DaydreamLanguageLoader::new();
- let requested_languages = WebLanguageRequester::requested_languages();
-
- i18n_embed::select(&language_loader, &translations, &requested_languages).unwrap();
-
- yew::start_app::<app::App>();
- Ok(())
-}
-
-//====== Running the worker ======///
-
-// We need to import the Threaded trait to register the worker
-use yew::agent::Threaded;
-
-/// This gets called by the worker.js entrypoint
-/// We need to wrap it in wasm_bindgen so the worker knows the spin the the yew worker instance
-#[wasm_bindgen]
-pub fn init_worker() {
- wasm_logger::init(wasm_logger::Config::default());
-
- // Spawning a yew component without StartApp requires initializing
- yew::initialize();
-
- // ... registering the worker
- app::matrix::MatrixAgent::register();
-}
-
-// you would need a new launch function for each of the unique workers you want to register
diff --git a/static/index_rust_only.html b/static/index_rust_only.html
@@ -9,19 +9,14 @@
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
- <script type="module">
- import init, {run_app, init_worker} from "./daydream.js";
-
- async function run() {
- await init();
- init_worker();
- run_app();
- }
- run();
-
- </script>
+ <link href="style.css" rel="stylesheet">
<title>Daydream</title>
</head>
<body>
+
+ <script type="module">
+ import init from "./daydream.js"
+ init()
+ </script>
</body>
</html>
diff --git a/static/style.scss b/static/style.scss
@@ -5,6 +5,7 @@
@import "./variable-ovewrites.scss";
@import "./custom-css.scss";
@import "../node_modules/uikit/src/scss/mixins-theme.scss";
+@import "../node_modules/uikit/src/scss/variables.scss";
@import "../node_modules/uikit/src/scss/uikit-theme.scss";
[data-theme="dark"] {