-
Notifications
You must be signed in to change notification settings - Fork 4
wasm: read the clock through one helper, and test a commit on wasm32 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| [workspace] | ||
| members = ["benchmarks/engine-comparison"] | ||
| members = ["benchmarks/engine-comparison", "wasm-smoke"] | ||
| default-members = ["."] | ||
| resolver = "3" | ||
|
|
||
|
|
@@ -132,6 +132,9 @@ opfs = [ | |
| "dep:futures", | ||
| ] | ||
|
|
||
| [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] | ||
| wasm-bindgen-test = "0.3" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No code in the |
||
|
|
||
| [dev-dependencies] | ||
| tokio = { version = "1", features = [ | ||
| "rt", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
|
||
| //! Wall-clock access. | ||
| //! | ||
| //! `wasm32-unknown-unknown` has no std clock: `SystemTime::now()` panics with | ||
| //! "time not implemented on this platform". The OPFS build reads the host | ||
| //! clock through `js_sys` instead; a wasm build without that feature degrades | ||
| //! to `0` rather than panicking. Every other target, `wasm32-wasip1` | ||
| //! included, uses std. | ||
|
|
||
| /// Seconds since the Unix epoch. | ||
| /// | ||
| /// Feeds the commit-history timestamp and the age-based retention threshold. | ||
| /// A `0` (no clock in this configuration) keeps both ordered by commit | ||
| /// sequence instead of inventing a time. | ||
| #[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "opfs"))] | ||
| pub(crate) fn unix_seconds() -> u64 { | ||
| (js_sys::Date::now() / 1000.0) as u64 | ||
| } | ||
|
|
||
| /// No clock in this configuration: `wasm32-unknown-unknown` without the JS | ||
| /// bindings. Callers get `0`, which the commit-history ordering tolerates. | ||
| #[cfg(all(target_arch = "wasm32", target_os = "unknown", not(feature = "opfs")))] | ||
| pub(crate) fn unix_seconds() -> u64 { | ||
| 0 | ||
|
Comment on lines
+24
to
+25
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocker.
The doc comment says the ordering tolerates Correct end state: a build with no clock refuses |
||
| } | ||
|
|
||
| #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] | ||
| pub(crate) fn unix_seconds() -> u64 { | ||
| std::time::SystemTime::now() | ||
| .duration_since(std::time::UNIX_EPOCH) | ||
| .map_or(0, |d| d.as_secs()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # wasm32 smoke tests for pagedb. | ||
| # | ||
| # Separate crate on purpose: the pagedb dev-dependencies (tokio | ||
| # rt-multi-thread, tempfile) do not compile for wasm32, and Cargo builds every | ||
| # dev-dependency for a crate's test targets. This crate depends on pagedb with | ||
| # the `opfs` feature only. | ||
| [package] | ||
| name = "pagedb-wasm-smoke" | ||
| version = "0.0.0" | ||
| edition = "2024" | ||
| publish = false | ||
|
|
||
| [lib] | ||
| path = "src/lib.rs" | ||
|
|
||
| [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] | ||
| wasm-bindgen-test = "0.3" | ||
| tokio = { version = "1", features = ["rt", "macros", "sync", "io-util", "time"] } | ||
| pagedb = { path = "..", features = ["opfs"] } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| //! wasm32 smoke-test crate; see tests/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this hunk. Changelog entries are maintainer-owned in this repo. The same hunk was removed from the other open PRs. The entry also names
clock::unix_seconds(), which is a private module and not public API.