Wasm target check before build (#1689)
* Add `rustup show` check for wasm32 target * better place for check * fmt * clippy fmt
This commit is contained in:
1 parent
424926a8db
commit
fc31876a57
9 files changed
+36
-36
No files matched your search
@@ -48,6 +48,18 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
|
|
||||||
// [1] Build the .wasm module
|
// [1] Build the .wasm module
|
||||||
log::info!("🚅 Running build command...");
|
log::info!("🚅 Running build command...");
|
||||||
|
|
||||||
|
let wasm_check_command = std::process::Command::new("rustup")
|
||||||
|
.args(["show"])
|
||||||
|
.output()?;
|
||||||
|
let wasm_check_output = String::from_utf8(wasm_check_command.stdout).unwrap();
|
||||||
|
if !wasm_check_output.contains("wasm32-unknown-unknown") {
|
||||||
|
log::info!("wasm32-unknown-unknown target not detected, installing..");
|
||||||
|
let _ = std::process::Command::new("rustup")
|
||||||
|
.args(["target", "add", "wasm32-unknown-unknown"])
|
||||||
|
.output()?;
|
||||||
|
}
|
||||||
|
|
||||||
let cmd = subprocess::Exec::cmd("cargo");
|
let cmd = subprocess::Exec::cmd("cargo");
|
||||||
let cmd = cmd
|
let cmd = cmd
|
||||||
.cwd(crate_dir)
|
.cwd(crate_dir)
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ impl Build {
|
|||||||
.platform
|
.platform
|
||||||
.unwrap_or(crate_config.dioxus_config.application.default_platform);
|
.unwrap_or(crate_config.dioxus_config.application.default_platform);
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
// #[cfg(feature = "plugin")]
|
||||||
let _ = PluginManager::on_build_start(&crate_config, &platform);
|
// let _ = PluginManager::on_build_start(&crate_config, &platform);
|
||||||
|
|
||||||
match platform {
|
match platform {
|
||||||
Platform::Web => {
|
Platform::Web => {
|
||||||
@@ -66,8 +66,8 @@ impl Build {
|
|||||||
)?;
|
)?;
|
||||||
file.write_all(temp.as_bytes())?;
|
file.write_all(temp.as_bytes())?;
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
// #[cfg(feature = "plugin")]
|
||||||
let _ = PluginManager::on_build_finish(&crate_config, &platform);
|
// let _ = PluginManager::on_build_finish(&crate_config, &platform);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ impl<'b> VirtualDom {
|
|||||||
// If none of the old keys are reused by the new children, then we remove all the remaining old children and
|
// If none of the old keys are reused by the new children, then we remove all the remaining old children and
|
||||||
// create the new children afresh.
|
// create the new children afresh.
|
||||||
if shared_keys.is_empty() {
|
if shared_keys.is_empty() {
|
||||||
if old.get(0).is_some() {
|
if old.first().is_some() {
|
||||||
self.remove_nodes(&old[1..]);
|
self.remove_nodes(&old[1..]);
|
||||||
self.replace(&old[0], new);
|
self.replace(&old[0], new);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ fn app(cx: Scope) -> Element {
|
|||||||
let mapping: DioxusElementToNodeId = cx.consume_context().unwrap();
|
let mapping: DioxusElementToNodeId = cx.consume_context().unwrap();
|
||||||
// disable templates so that every node has an id and can be queried
|
// disable templates so that every node has an id and can be queried
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div{
|
div {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
background_color: "hsl({hue}, 70%, {brightness}%)",
|
background_color: "hsl({hue}, 70%, {brightness}%)",
|
||||||
onmousemove: move |evt| {
|
onmousemove: move |evt| {
|
||||||
if let RenderReturn::Ready(node) = cx.root_node() {
|
if let RenderReturn::Ready(node) = cx.root_node() {
|
||||||
if let Some(id) = node.root_ids.borrow().get(0).cloned() {
|
if let Some(id) = node.root_ids.borrow().first().cloned() {
|
||||||
let node = tui_query.get(mapping.get_node_id(id).unwrap());
|
let node = tui_query.get(mapping.get_node_id(id).unwrap());
|
||||||
let Size{width, height} = node.size().unwrap();
|
let Size { width, height } = node.size().unwrap();
|
||||||
let pos = evt.inner().element_coordinates();
|
let pos = evt.inner().element_coordinates();
|
||||||
hue.set((pos.x as f32/width as f32)*255.0);
|
hue.set((pos.x as f32 / width as f32) * 255.0);
|
||||||
brightness.set((pos.y as f32/height as f32)*100.0);
|
brightness.set((pos.y as f32 / height as f32) * 100.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hsl({hue}, 70%, {brightness}%)",
|
"hsl({hue}, 70%, {brightness}%)"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,6 @@ mod atoms {
|
|||||||
pub use atom::*;
|
pub use atom::*;
|
||||||
pub use atomfamily::*;
|
pub use atomfamily::*;
|
||||||
pub use atomref::*;
|
pub use atomref::*;
|
||||||
pub use selector::*;
|
|
||||||
pub use selectorfamily::*;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod hooks {
|
pub mod hooks {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ impl Redirect {
|
|||||||
|
|
||||||
let (segments, query) = parse_route_segments(
|
let (segments, query) = parse_route_segments(
|
||||||
path.span(),
|
path.span(),
|
||||||
|
#[allow(clippy::map_identity)]
|
||||||
closure_arguments.iter().map(|(name, ty)| (name, ty)),
|
closure_arguments.iter().map(|(name, ty)| (name, ty)),
|
||||||
&path.value(),
|
&path.value(),
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
|
|||||||
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
||||||
let mut context = DynamicContext::default();
|
let mut context = DynamicContext::default();
|
||||||
|
|
||||||
let key = match self.roots.get(0) {
|
let key = match self.roots.first() {
|
||||||
Some(BodyNode::Element(el)) if self.roots.len() == 1 => el.key.clone(),
|
Some(BodyNode::Element(el)) if self.roots.len() == 1 => el.key.clone(),
|
||||||
Some(BodyNode::Component(comp)) if self.roots.len() == 1 => comp.key().cloned(),
|
Some(BodyNode::Component(comp)) if self.roots.len() == 1 => comp.key().cloned(),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
@@ -22,15 +22,9 @@ fn app(cx: Scope) -> Element {
|
|||||||
use_context_provider(cx, ApplicationData::default);
|
use_context_provider(cx, ApplicationData::default);
|
||||||
|
|
||||||
render! {
|
render! {
|
||||||
div {
|
div { ReadsFirst {} }
|
||||||
ReadsFirst {}
|
div { ReadsSecond {} }
|
||||||
}
|
div { ReadsManySignals {} }
|
||||||
div {
|
|
||||||
ReadsSecond {}
|
|
||||||
}
|
|
||||||
div {
|
|
||||||
ReadsManySignals {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,16 +101,14 @@ fn ReadsManySignals(cx: Scope) -> Element {
|
|||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
if let Some(first) = data.many_signals.read().get(0) {
|
if let Some(first) = data.many_signals.read().first() {
|
||||||
*first.write() += 1;
|
*first.write() += 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Increase First Item"
|
"Increase First Item"
|
||||||
}
|
}
|
||||||
for signal in data.many_signals {
|
for signal in data.many_signals {
|
||||||
Child {
|
Child { count: signal }
|
||||||
count: signal,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use futures_channel::mpsc::UnboundedReceiver;
|
|||||||
use dioxus_core::Template;
|
use dioxus_core::Template;
|
||||||
|
|
||||||
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
||||||
use std::convert::TryInto;
|
|
||||||
use wasm_bindgen::closure::Closure;
|
use wasm_bindgen::closure::Closure;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
use web_sys::{MessageEvent, WebSocket};
|
use web_sys::{MessageEvent, WebSocket};
|
||||||
@@ -31,14 +30,12 @@ pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
|||||||
// change the rsx when new data is received
|
// change the rsx when new data is received
|
||||||
let cl = Closure::wrap(Box::new(move |e: MessageEvent| {
|
let cl = Closure::wrap(Box::new(move |e: MessageEvent| {
|
||||||
if let Ok(text) = e.data().dyn_into::<js_sys::JsString>() {
|
if let Ok(text) = e.data().dyn_into::<js_sys::JsString>() {
|
||||||
let text: Result<String, _> = text.try_into();
|
let string: String = text.into();
|
||||||
if let Ok(string) = text {
|
let val = serde_json::from_str::<serde_json::Value>(&string).unwrap();
|
||||||
let val = serde_json::from_str::<serde_json::Value>(&string).unwrap();
|
// leak the value
|
||||||
// leak the value
|
let val: &'static serde_json::Value = Box::leak(Box::new(val));
|
||||||
let val: &'static serde_json::Value = Box::leak(Box::new(val));
|
let template: Template<'_> = Template::deserialize(val).unwrap();
|
||||||
let template: Template<'_> = Template::deserialize(val).unwrap();
|
tx.unbounded_send(template).unwrap();
|
||||||
tx.unbounded_send(template).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}) as Box<dyn FnMut(MessageEvent)>);
|
}) as Box<dyn FnMut(MessageEvent)>);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user