Wasm hell
This commit is contained in:
parent
5f00622ed2
commit
323afc1cbd
7 changed files with 63 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
/**/input.txt
|
||||
/**/input.txt
|
||||
wasm/pkg
|
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -21,13 +21,13 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
|||
name = "advent"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"num-bigint",
|
||||
"num-irrational",
|
||||
"num-rational",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"scraper",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -39,6 +39,16 @@ dependencies = [
|
|||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "advent-wasm"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"advent",
|
||||
"console_error_panic_hook",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.6"
|
||||
|
@ -227,6 +237,16 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
|
@ -433,8 +453,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[workspace]
|
||||
members = ["cli", "lib"]
|
||||
members = ["cli", "lib", "wasm"]
|
||||
resolver = "2"
|
|
@ -9,5 +9,8 @@ num-irrational = { version = "0.3.0", features = ["num-bigint"] }
|
|||
num-rational = { version = "0.4.1", features = ["num-bigint"] }
|
||||
regex = "1.10.2"
|
||||
scraper = "0.18.1"
|
||||
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }
|
||||
reqwest = "0.11.22"
|
||||
reqwest = "0.11.22"
|
||||
|
||||
[dependencies.getrandom]
|
||||
version = "0.2.11"
|
||||
features = ["js"]
|
14
wasm/Cargo.toml
Normal file
14
wasm/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "advent-wasm"
|
||||
version = "0.1.0"
|
||||
authors = ["Ty"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.84"
|
||||
wasm-bindgen-futures = "0.4.39"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
advent = { path = "../lib" }
|
12
wasm/index.html
Normal file
12
wasm/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
WebAssembly.instantiateStreaming(fetch("simple.wasm")).then(
|
||||
(results) => {
|
||||
console.log(results);
|
||||
},
|
||||
);
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
6
wasm/src/lib.rs
Normal file
6
wasm/src/lib.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub async fn solve(day: u8, part: u8, auth: String) -> String {
|
||||
advent::get_day(day, advent::fetcher::fetch_input(auth, day).await).solve(part, false)
|
||||
}
|
Loading…
Reference in a new issue