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:
Exotik850 2023-12-07 12:35:16 -06:00 committed by GitHub
parent 424926a8db
commit fc31876a57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 36 deletions

View file

@ -48,6 +48,18 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
// [1] Build the .wasm module
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 = cmd
.cwd(crate_dir)

View file

@ -37,8 +37,8 @@ impl Build {
.platform
.unwrap_or(crate_config.dioxus_config.application.default_platform);
#[cfg(feature = "plugin")]
let _ = PluginManager::on_build_start(&crate_config, &platform);
// #[cfg(feature = "plugin")]
// let _ = PluginManager::on_build_start(&crate_config, &platform);
match platform {
Platform::Web => {
@ -66,8 +66,8 @@ impl Build {
)?;
file.write_all(temp.as_bytes())?;
#[cfg(feature = "plugin")]
let _ = PluginManager::on_build_finish(&crate_config, &platform);
// #[cfg(feature = "plugin")]
// let _ = PluginManager::on_build_finish(&crate_config, &platform);
Ok(())
}

View file

@ -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
// create the new children afresh.
if shared_keys.is_empty() {
if old.get(0).is_some() {
if old.first().is_some() {
self.remove_nodes(&old[1..]);
self.replace(&old[0], new);
} else {

View file

@ -15,21 +15,21 @@ fn app(cx: Scope) -> Element {
let mapping: DioxusElementToNodeId = cx.consume_context().unwrap();
// disable templates so that every node has an id and can be queried
cx.render(rsx! {
div{
div {
width: "100%",
background_color: "hsl({hue}, 70%, {brightness}%)",
onmousemove: move |evt| {
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 Size{width, height} = node.size().unwrap();
let Size { width, height } = node.size().unwrap();
let pos = evt.inner().element_coordinates();
hue.set((pos.x as f32/width as f32)*255.0);
brightness.set((pos.y as f32/height as f32)*100.0);
hue.set((pos.x as f32 / width as f32) * 255.0);
brightness.set((pos.y as f32 / height as f32) * 100.0);
}
}
},
"hsl({hue}, 70%, {brightness}%)",
"hsl({hue}, 70%, {brightness}%)"
}
})
}

View file

@ -22,8 +22,6 @@ mod atoms {
pub use atom::*;
pub use atomfamily::*;
pub use atomref::*;
pub use selector::*;
pub use selectorfamily::*;
}
pub mod hooks {

View file

@ -75,6 +75,7 @@ impl Redirect {
let (segments, query) = parse_route_segments(
path.span(),
#[allow(clippy::map_identity)]
closure_arguments.iter().map(|(name, ty)| (name, ty)),
&path.value(),
)?;

View file

@ -193,7 +193,7 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
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::Component(comp)) if self.roots.len() == 1 => comp.key().cloned(),
_ => None,

View file

@ -22,15 +22,9 @@ fn app(cx: Scope) -> Element {
use_context_provider(cx, ApplicationData::default);
render! {
div {
ReadsFirst {}
}
div {
ReadsSecond {}
}
div {
ReadsManySignals {}
}
div { ReadsFirst {} }
div { ReadsSecond {} }
div { ReadsManySignals {} }
}
}
@ -107,16 +101,14 @@ fn ReadsManySignals(cx: Scope) -> Element {
}
button {
onclick: move |_| {
if let Some(first) = data.many_signals.read().get(0) {
if let Some(first) = data.many_signals.read().first() {
*first.write() += 1;
}
},
"Increase First Item"
}
for signal in data.many_signals {
Child {
count: signal,
}
Child { count: signal }
}
}
}

View file

@ -5,7 +5,6 @@ use futures_channel::mpsc::UnboundedReceiver;
use dioxus_core::Template;
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
use std::convert::TryInto;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsCast;
use web_sys::{MessageEvent, WebSocket};
@ -31,15 +30,13 @@ pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
// change the rsx when new data is received
let cl = Closure::wrap(Box::new(move |e: MessageEvent| {
if let Ok(text) = e.data().dyn_into::<js_sys::JsString>() {
let text: Result<String, _> = text.try_into();
if let Ok(string) = text {
let string: String = text.into();
let val = serde_json::from_str::<serde_json::Value>(&string).unwrap();
// leak the value
let val: &'static serde_json::Value = Box::leak(Box::new(val));
let template: Template<'_> = Template::deserialize(val).unwrap();
tx.unbounded_send(template).unwrap();
}
}
}) as Box<dyn FnMut(MessageEvent)>);
ws.set_onmessage(Some(cl.as_ref().unchecked_ref()));