From f6d0bdfa8f32447272ce2e862b196fdd8bb7850c Mon Sep 17 00:00:00 2001 From: Dennis Ranke Date: Sun, 21 Nov 2021 16:46:20 +0100 Subject: [PATCH] add simple rust "script" to build platform binaries --- .gitignore | 2 + platform/.gitignore | 2 +- platform/Cargo.lock | 227 ++++++++++++++++++++++++++++++++ platform/Cargo.toml | 11 ++ platform/bin/loader.wasm | Bin 0 -> 1371 bytes platform/bin/platform.uw8 | Bin 0 -> 824 bytes platform/makefile | 7 - platform/{ => src}/loader.cwa | 2 +- platform/src/main.rs | 16 +++ platform/{ => src}/platform.cwa | 0 src/lib.rs | 4 +- web/src/main.js | 4 +- 12 files changed, 262 insertions(+), 13 deletions(-) create mode 100644 platform/Cargo.lock create mode 100644 platform/Cargo.toml create mode 100644 platform/bin/loader.wasm create mode 100644 platform/bin/platform.uw8 delete mode 100644 platform/makefile rename platform/{ => src}/loader.cwa (99%) create mode 100644 platform/src/main.rs rename platform/{ => src}/platform.cwa (100%) diff --git a/.gitignore b/.gitignore index ea8c4bf..9e6e17c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +.cargo/ +.vscode/ diff --git a/platform/.gitignore b/platform/.gitignore index 917660a..a6f89c2 100644 --- a/platform/.gitignore +++ b/platform/.gitignore @@ -1 +1 @@ -*.wasm \ No newline at end of file +/target/ \ No newline at end of file diff --git a/platform/Cargo.lock b/platform/Cargo.lock new file mode 100644 index 0000000..e8b57da --- /dev/null +++ b/platform/Cargo.lock @@ -0,0 +1,227 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" +dependencies = [ + "const-random", +] + +[[package]] +name = "anyhow" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d9ff5d688f1c13395289f67db01d4826b46dd694e7580accdc3e8430f2d98e" + +[[package]] +name = "ariadne" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7080ae01b2f0c312065d4914cd0f0de045eb8832e9415b355106a6cff3073cb4" +dependencies = [ + "yansi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cdivsufsort" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edefce019197609da416762da75bb000bbd2224b2d89a7e722c2296cbff79b8c" +dependencies = [ + "cc", + "sacabase", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chumsky" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d3efff85e8572b1c3fa0127706af58c4fff8458f8d9436d54b1e97573c7a3f" +dependencies = [ + "ahash", +] + +[[package]] +name = "const-random" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f590d95d011aa80b063ffe3253422ed5aa462af4e9867d43ce8337562bac77c4" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40" +dependencies = [ + "getrandom", + "lazy_static", + "proc-macro-hack", + "tiny-keccak", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "curlywas" +version = "0.1.0" +source = "git+https://github.com/exoticorn/curlywas.git?rev=788a565#788a5657b535448f0532b1481fbfe9a77ee3b5e1" +dependencies = [ + "anyhow", + "ariadne", + "chumsky", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "pico-args" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" + +[[package]] +name = "platform" +version = "0.1.0" +dependencies = [ + "anyhow", + "curlywas", + "uw8-tool", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "sacabase" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9883fc3d6ce3d78bb54d908602f8bc1f7b5f983afe601dabe083009d86267a84" +dependencies = [ + "num-traits", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "upkr" +version = "0.1.0" +source = "git+https://github.com/exoticorn/upkr.git?rev=479a2e2#479a2e2c899a7aa24fa1fd9b4ebd371f8bc39f8e" +dependencies = [ + "cdivsufsort", +] + +[[package]] +name = "uw8-tool" +version = "0.1.0" +dependencies = [ + "anyhow", + "pico-args", + "upkr", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-encoder" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0c351632e46cc06a58a696a6c11e4cf90cad4b9f8f07a0b59128d616c29bb0" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmparser" +version = "0.81.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98930446519f63d00a836efdc22f67766ceae8dbcc1571379f2bcabc6b2b9abc" + +[[package]] +name = "yansi" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" diff --git a/platform/Cargo.toml b/platform/Cargo.toml new file mode 100644 index 0000000..c1b5c57 --- /dev/null +++ b/platform/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "platform" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +curlywas = { git="https://github.com/exoticorn/curlywas.git", rev="788a565" } +uw8-tool = { path="../uw8-tool" } +anyhow = "1" \ No newline at end of file diff --git a/platform/bin/loader.wasm b/platform/bin/loader.wasm new file mode 100644 index 0000000000000000000000000000000000000000..516bf44e7d35f2085c302ba6bf2856b4ecc932ce GIT binary patch literal 1371 zcmYLH3s6*L6#id#ci}GW4W6ASTW|%Um6atbF#u6kRq7*qeW|_>Gj7AC8Gz{rjO=RaT%s4yuf1U4q=R4mXl(Vf6 zBZTmMEE{WB%O;w!QccrPHbTUPX>L)4sW7*&xU8BWMgs!?Ody3)(*i-mDiZxmEp{RC z?qUujmV)A(%`a`Qj6o=Hd(q3qg(YRV+qNNQ!Ir>AQ@}9BW=%y=2&p*V4m^p>$&pP| z^?ox)Zkceb;!@^RvAUz*EHRk~Mo2{*NmNvks_(a{7Ky5_?YGHPwaCoC$pUq9fs;f| z74$3@fSyxWlFNXKGx!M-v76j7GXRNq0jrES%9*O;(jX*q%uzlkZZQ~R z;DIZau$@Sh6EPfd;7ejoAT*9(6mbKBxPdzs!4nXOVh8q1aKK;SAn;Kab}&eR5;|E* zblnC=<_0l!)$Kn!9G@~b@I3Nu7BoilKlW`$#+21V; zf!|}uHDcmtFnAiN1q3U2*l4RwCe*1=7xyVtVICLu!ZDROC9{#IFqf|DmUQDTnT@lq zbA@^xY%at!nJNSxIMp~whtk+T1Eki$H~~DYUKjIuVDuCi4Nhu34%p`-eiY!C&npwr zFN%{Rb9Q4f3MoX@+IP7udlX|5+UgucF-&k^h0X^YAR6MJ$BO0#T4D|`XozCCi@o&D z1gd{Cs$s>Jf}q%qCrciCVYKt&(I*pP4u%F@uYdjQfb~X#*O8$t?=f}V`|iKbbliWd zbx%~;`9Jn$Y+dAQYkWK8($`y(k6S~>n;*3F4YVIxpVpW4*E{teuALasgJ(TWF+Zjk z^p%jv*odrO?3HzPj?&{2WWs$i4}8=Y@0KoqwloQc_2vH=MjOweXR=_>c(e zP}Aw?5Kq##K^=pi_j@Xu*4Ws=wL#P8PK0?Tlbx$$u2$@>aa5IzZJ3#!86BKy7DxDj za3NLQ-n6&sXL;eL-sYQv5H?n~B($({Hubxs&Iej=o%$*3i;VH7T#>skwpU$lXkPZg zwW^fO>r$MD20QLq^-x|<)5>G-B`wOVy0&-cik2i(Z{*{XC%RL=ypkDyJ0kw+7QKB& z|0MMJ)<;{F!=c}d4UAY0AF1f-uDLPmJ3jQ>rit+qYs>q+nbM!We=eItcUf;<-nk&U z;fMaZ$YA%Wtqa>~-co;Gb~~V^YjoY2HN$af!{r~>UJ7qqA3HvHAi{MvyZ(*prNsS8 zZrbW)(#HQf&-@ygGF2i!VY@UL7x>Zjsq>3}yHR~1Z-^wGUcUI)_u`8^!xjGn9=&bD literal 0 HcmV?d00001 diff --git a/platform/bin/platform.uw8 b/platform/bin/platform.uw8 new file mode 100644 index 0000000000000000000000000000000000000000..811e189b94a0505af53528d2465bede766a32ed8 GIT binary patch literal 824 zcmZ8fv2GJV5S`iG+dF&ha1u08nmLCwpmfLuO}tK%P#`4e(%7;uA?EBTb`+VyK7&Yz zWC?}Xlr%J?NEJE?#1~NKGg2Y}g4r_`5_ek7)6CAB_jVWRy*2^>t`};6DX$@~K@C%= ziNS!8OjC!`l&cPNP#iet4fx}zW&uFlKpA%qbvthFb)O4Ra-j$)q>`TYgIwNdjYF)i z7(X$(TkkaY+5o`}lRKSPh>xCv5ixA&S%)<}Bb1-=zC9- z-A)X-TsLkU)H^##40+wy?KT*g01NqVsu)0sReJr=+(jHN!!lG0Cr2e9s4gDQ;?l{{ zZI^%l`O}Z-*{=^PLvs`CXf*mML$JBS?iY)f6SK%Y7gaj8YXr|OxFy8dG7DVcAK$$p zoKDOg#FW7P#(n$Z<*OixKvoC|%A!wbRjY({bfq?mV2tatU&SWpuW@r Result<()> { + uw8_tool::BaseModule::create_binary(&Path::new("target/base.upk"))?; + + let loader = curlywas::compile_file("src/loader.cwa")?; + File::create("bin/loader.wasm")?.write_all(&loader)?; + + let platform = curlywas::compile_file("src/platform.cwa")?; + File::create("bin/platform.uw8")?.write_all(&platform)?; + + Ok(()) +} diff --git a/platform/platform.cwa b/platform/src/platform.cwa similarity index 100% rename from platform/platform.cwa rename to platform/src/platform.cwa diff --git a/src/lib.rs b/src/lib.rs index 68f3e5e..46352db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ impl MicroW8 { let engine = wasmtime::Engine::default(); let loader_module = - wasmtime::Module::new(&engine, include_bytes!("../platform/loader.wasm"))?; + wasmtime::Module::new(&engine, include_bytes!("../platform/bin/loader.wasm"))?; let mut window = Window::new("MicroW8", 320, 240, WindowOptions::default())?; window.limit_update_rate(Some(std::time::Duration::from_micros(16666))); @@ -74,7 +74,7 @@ impl MicroW8 { let loader_instance = linker.instantiate(&mut store, &self.loader_module)?; let load_uw8 = loader_instance.get_typed_func::(&mut store, "load_uw8")?; - let platform_data = include_bytes!("../platform/platform.wasm"); + let platform_data = include_bytes!("../platform/bin/platform.uw8"); memory.data_mut(&mut store)[..platform_data.len()].copy_from_slice(platform_data); let platform_length = load_uw8.call(&mut store, platform_data.len() as i32)? as u32 as usize; let platform_module = wasmtime::Module::new(&self.engine, &memory.data(&store)[..platform_length])?; diff --git a/web/src/main.js b/web/src/main.js index dd45607..d9c05a3 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -1,5 +1,5 @@ -import loaderUrl from "data-url:../../platform/loader.wasm"; -import platformUrl from "data-url:../../platform/platform.wasm"; +import loaderUrl from "data-url:../../platform/bin/loader.wasm"; +import platformUrl from "data-url:../../platform/bin/platform.uw8"; function setMessage(size, error) { let html = size ? `${size} bytes` : 'Insert cart';