From 7a10767fed1f792dddc9a074af95bc9508835999 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Tue, 4 Apr 2023 19:27:20 +0200 Subject: [PATCH] jotdown_wasm: display version mostly useful for the hosted version --- Cargo.lock | 144 +++++++++++++++++++++++++++++-- examples/jotdown_wasm/Cargo.toml | 3 + examples/jotdown_wasm/Makefile | 2 +- examples/jotdown_wasm/build.rs | 17 ++++ examples/jotdown_wasm/demo.html | 25 ++++-- examples/jotdown_wasm/src/lib.rs | 6 ++ 6 files changed, 184 insertions(+), 13 deletions(-) create mode 100644 examples/jotdown_wasm/build.rs diff --git a/Cargo.lock b/Cargo.lock index c85b251..d686cdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -159,6 +168,28 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "git2" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3826a6e0e2215d7a41c2bfc7c9244123969273f3476b939a226aac0ab56e9e3c" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "half" version = "1.8.2" @@ -186,6 +217,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.2" @@ -211,6 +252,15 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "jotdown" version = "0.1.0" @@ -219,6 +269,7 @@ version = "0.1.0" name = "jotdown_wasm" version = "0.1.0" dependencies = [ + "git2", "jotdown", "wasm-bindgen", "web-sys", @@ -245,6 +296,30 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +[[package]] +name = "libgit2-sys" +version = "0.13.2+1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a42de9a51a5c12e00fc0e4ca6bc2ea43582fc6418488e8f615e905d886f258b" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "log" version = "0.4.17" @@ -282,19 +357,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] -name = "proc-macro2" -version = "1.0.51" +name = "percent-encoding" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "proc-macro2" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -387,12 +474,59 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "walkdir" version = "2.3.2" diff --git a/examples/jotdown_wasm/Cargo.toml b/examples/jotdown_wasm/Cargo.toml index 13dc212..307afb1 100644 --- a/examples/jotdown_wasm/Cargo.toml +++ b/examples/jotdown_wasm/Cargo.toml @@ -17,3 +17,6 @@ wasm-bindgen = { version = "0.2", default-features = false } [dependencies.web-sys] version = "0.3" + +[build-dependencies] +git2 = { version = "0.14", default-features = false } diff --git a/examples/jotdown_wasm/Makefile b/examples/jotdown_wasm/Makefile index d2a2b92..89a7632 100644 --- a/examples/jotdown_wasm/Makefile +++ b/examples/jotdown_wasm/Makefile @@ -1,6 +1,6 @@ WASM=pkg/jotdown_wasm_bg.wasm -SRC=$(shell find src ../../src -name '*.rs') +SRC=$(shell find . ../../src -name '*.rs') ${WASM}: ${SRC} wasm-pack build --release --target web diff --git a/examples/jotdown_wasm/build.rs b/examples/jotdown_wasm/build.rs new file mode 100644 index 0000000..84d86c0 --- /dev/null +++ b/examples/jotdown_wasm/build.rs @@ -0,0 +1,17 @@ +fn get_version() -> String { + if let Ok(repo) = git2::Repository::discover(".") { + if let Ok(describe) = repo.describe(&git2::DescribeOptions::new()) { + if let Ok(format) = describe.format(None) { + return format; + } + } + } + + std::env::var("CARGO_PKG_VERSION").unwrap() +} + +fn main() { + let out_dir = std::env::var_os("OUT_DIR").unwrap(); + let dest_path = std::path::Path::new(&out_dir).join("version"); + std::fs::write(&dest_path, get_version()).unwrap(); +} diff --git a/examples/jotdown_wasm/demo.html b/examples/jotdown_wasm/demo.html index a3ad142..ba7679b 100644 --- a/examples/jotdown_wasm/demo.html +++ b/examples/jotdown_wasm/demo.html @@ -1,12 +1,16 @@
-
- +
+
+ + version: (not loaded) + +
+
+ +
*Hello world!*
diff --git a/examples/jotdown_wasm/src/lib.rs b/examples/jotdown_wasm/src/lib.rs index ba72c80..9aeb866 100644 --- a/examples/jotdown_wasm/src/lib.rs +++ b/examples/jotdown_wasm/src/lib.rs @@ -3,6 +3,12 @@ use wasm_bindgen::prelude::*; use jotdown::Render; use std::fmt::Write; +#[must_use] +#[wasm_bindgen] +pub fn jotdown_version() -> String { + include_str!(concat!(env!("OUT_DIR"), "/version")).to_string() +} + #[must_use] #[wasm_bindgen] pub fn jotdown_render(djot: &str) -> String {