diff --git a/.gitignore b/.gitignore index f5aa729..4cf52b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/**/input.txt \ No newline at end of file +/**/input.txt +wasm/pkg \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7a1d570..60eb36c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] diff --git a/Cargo.toml b/Cargo.toml index d7351b1..adf09d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["cli", "lib"] +members = ["cli", "lib", "wasm"] resolver = "2" \ No newline at end of file diff --git a/lib/Cargo.toml b/lib/Cargo.toml index de57434..a288dfb 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -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" \ No newline at end of file +reqwest = "0.11.22" + +[dependencies.getrandom] +version = "0.2.11" +features = ["js"] \ No newline at end of file diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml new file mode 100644 index 0000000..5851740 --- /dev/null +++ b/wasm/Cargo.toml @@ -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" } \ No newline at end of file diff --git a/wasm/index.html b/wasm/index.html new file mode 100644 index 0000000..71cb911 --- /dev/null +++ b/wasm/index.html @@ -0,0 +1,12 @@ + + +
+ + + \ No newline at end of file diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs new file mode 100644 index 0000000..8cb9b2d --- /dev/null +++ b/wasm/src/lib.rs @@ -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) +} \ No newline at end of file