Switch const serialize to use CBOR (#4932)
* implement const cbor encoding + decoding for basic types * implement map encoding and decoding * fix map test * all tests passing * dynamically sized arrays * smaller str encoding * swap array and list and add more documentation * move serialization and deserialization for each struct together * support both legacy and new assets * bump const serialize version * fix asset conversion code * pull out manganis symbol struct from tuble * test reading old asset versions * more list/array cleanup and bump rust version * fix clippy * switch cli opt port * install playwright deps * split cli-optimization package to avoid two dioxus' in the same crate * fix clippy * force the toast.png asset to be included in the linker stage #[used] has platform depedant behavior * bundle both formats in the link section and only use the asset the cli changed * remove sudo which doesn't exist on windows * add binstall to the playwright workflow * separate bin target for the old cli * lockfile * cargo update to get versions shaken out * notes on binstalls, add back `.read()` for compat * use 0.8.0-alpha.0 for const-serialize instead of 0.8 this ensures we can still publish breaking changes on 0.8 without taking over the full version * fix clippy in example * small debug nits * update rust-overlay in nix * fix flake? * migrate to new structure * just comment out binstalls * just remove old test harness --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
c68a47b2d3
commit
c977cc125e
48 files changed
+3386
-2007
No files matched your search
@@ -1,4 +1,5 @@
|
||||
dist
|
||||
target
|
||||
monaco-editor
|
||||
partial-monaco-editor
|
||||
partial-monaco-editor
|
||||
dx-07
|
||||
@@ -15,3 +15,8 @@ serde_json.workspace = true
|
||||
# reqwest = { workspace = true, features = ["blocking"] }
|
||||
# flate2 = "1.1.2"
|
||||
# tar = "0.4.44"
|
||||
|
||||
# We need a separate bin for the old CLI build to avoid conflicting caches
|
||||
[[bin]]
|
||||
name = "cli-optimization-old-cli"
|
||||
path = "src/old_cli.rs"
|
||||
@@ -0,0 +1,93 @@
|
||||
// This test checks the CLI optimizes assets correctly without breaking them
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
const SOME_IMAGE: Asset = asset!("/images/toasts.png", AssetOptions::image().with_avif());
|
||||
const SOME_IMAGE_WITH_THE_SAME_URL: Asset =
|
||||
asset!("/images/toasts.png", AssetOptions::image().with_jpg());
|
||||
#[used]
|
||||
static SOME_IMAGE_WITHOUT_HASH: Asset = asset!(
|
||||
"/images/toasts.png",
|
||||
AssetOptions::image().with_avif().with_hash_suffix(false)
|
||||
);
|
||||
// This asset is unused, but it should still be bundled because it is an external asset
|
||||
#[used]
|
||||
static _ASSET: Asset = asset!(
|
||||
"/images/toasts.png",
|
||||
AssetOptions::builder().with_hash_suffix(false)
|
||||
);
|
||||
|
||||
pub fn main() {
|
||||
dioxus::launch(App);
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
// todo: test monaco more....
|
||||
// const MONACO_FOLDER: Asset = asset!("/monaco-editor/package/min/vs");
|
||||
// let script = format!("(() => {{
|
||||
// require.config({{ paths: {{ vs: '{MONACO_FOLDER}' }} }});
|
||||
|
||||
// require(['vs/editor/editor.main'], () => {{
|
||||
// var model = monaco.editor.createModel('fn main() {{\\n\\tprintln!(\\\"hi\\\")\\n}}', 'rust');
|
||||
// var editor = monaco.editor.create(document.getElementById('editor'));
|
||||
// editor.setModel(model);
|
||||
// }})
|
||||
// }})()");
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
id: "editor",
|
||||
width: "100vw",
|
||||
height: "100vw",
|
||||
}
|
||||
// // Monaco script
|
||||
// script {
|
||||
// src: "{MONACO_FOLDER}/loader.js",
|
||||
// "onload": script
|
||||
// }
|
||||
img {
|
||||
id: "some_image",
|
||||
src: "{SOME_IMAGE}"
|
||||
}
|
||||
img {
|
||||
id: "some_image_with_the_same_url",
|
||||
src: "{SOME_IMAGE_WITH_THE_SAME_URL}"
|
||||
}
|
||||
img {
|
||||
id: "some_image_without_hash",
|
||||
src: "{SOME_IMAGE_WITHOUT_HASH}"
|
||||
}
|
||||
LoadsAsset {}
|
||||
}
|
||||
}
|
||||
|
||||
const JSON: Asset = asset!("/assets/data.json");
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize)]
|
||||
struct Data {
|
||||
list: Vec<i32>,
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn LoadsAsset() -> Element {
|
||||
let data = use_resource(|| async {
|
||||
let bytes = dioxus::asset_resolver::read_asset_bytes(&JSON)
|
||||
.await
|
||||
.unwrap();
|
||||
serde_json::from_slice::<Data>(&bytes).unwrap()
|
||||
});
|
||||
match data() {
|
||||
Some(data) => rsx! {
|
||||
div {
|
||||
id: "resolved-data",
|
||||
"List: {data.list:?}"
|
||||
}
|
||||
},
|
||||
None => rsx! {
|
||||
div {
|
||||
"Loading..."
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,93 +1,3 @@
|
||||
// This test checks the CLI optimizes assets correctly without breaking them
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
const SOME_IMAGE: Asset = asset!("/images/toasts.png", AssetOptions::image().with_avif());
|
||||
const SOME_IMAGE_WITH_THE_SAME_URL: Asset =
|
||||
asset!("/images/toasts.png", AssetOptions::image().with_jpg());
|
||||
#[used]
|
||||
static SOME_IMAGE_WITHOUT_HASH: Asset = asset!(
|
||||
"/images/toasts.png",
|
||||
AssetOptions::image().with_avif().with_hash_suffix(false)
|
||||
);
|
||||
// This asset is unused, but it should still be bundled because it is an external asset
|
||||
#[used]
|
||||
static _ASSET: Asset = asset!(
|
||||
"/images/toasts.png",
|
||||
AssetOptions::builder().with_hash_suffix(false)
|
||||
);
|
||||
|
||||
fn main() {
|
||||
dioxus::launch(App);
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
// todo: test monaco more....
|
||||
// const MONACO_FOLDER: Asset = asset!("/monaco-editor/package/min/vs");
|
||||
// let script = format!("(() => {{
|
||||
// require.config({{ paths: {{ vs: '{MONACO_FOLDER}' }} }});
|
||||
|
||||
// require(['vs/editor/editor.main'], () => {{
|
||||
// var model = monaco.editor.createModel('fn main() {{\\n\\tprintln!(\\\"hi\\\")\\n}}', 'rust');
|
||||
// var editor = monaco.editor.create(document.getElementById('editor'));
|
||||
// editor.setModel(model);
|
||||
// }})
|
||||
// }})()");
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
id: "editor",
|
||||
width: "100vw",
|
||||
height: "100vw",
|
||||
}
|
||||
// // Monaco script
|
||||
// script {
|
||||
// src: "{MONACO_FOLDER}/loader.js",
|
||||
// "onload": script
|
||||
// }
|
||||
img {
|
||||
id: "some_image",
|
||||
src: "{SOME_IMAGE}"
|
||||
}
|
||||
img {
|
||||
id: "some_image_with_the_same_url",
|
||||
src: "{SOME_IMAGE_WITH_THE_SAME_URL}"
|
||||
}
|
||||
img {
|
||||
id: "some_image_without_hash",
|
||||
src: "{SOME_IMAGE_WITHOUT_HASH}"
|
||||
}
|
||||
LoadsAsset {}
|
||||
}
|
||||
}
|
||||
|
||||
const JSON: Asset = asset!("/assets/data.json");
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize)]
|
||||
struct Data {
|
||||
list: Vec<i32>,
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn LoadsAsset() -> Element {
|
||||
let data = use_resource(|| async {
|
||||
let bytes = dioxus::asset_resolver::read_asset_bytes(&JSON)
|
||||
.await
|
||||
.unwrap();
|
||||
serde_json::from_slice::<Data>(&bytes).unwrap()
|
||||
});
|
||||
match data() {
|
||||
Some(data) => rsx! {
|
||||
div {
|
||||
id: "resolved-data",
|
||||
"List: {data.list:?}"
|
||||
}
|
||||
},
|
||||
None => rsx! {
|
||||
div {
|
||||
"Loading..."
|
||||
}
|
||||
},
|
||||
}
|
||||
dioxus_cli_optimization_test::main()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
dioxus_cli_optimization_test::main()
|
||||
}
|
||||
Reference in new issue
Block a user