Artifact 38ebe736d93cda8b37c5bcd426175a98296409ca0a5e34cd5115221512b29708:
- File
examples/wasm/README.md
— part of check-in
[6273a0750d]
at
2026-07-22 23:03:24
on branch trunk
— fix: correct go.mod module path to go-libfossil (#76) (#117)
* fix: correct go.mod module path to go-libfossil (#76)
The module directive still declared github.com/danmestas/libfossil after the repository was renamed to go-libfossil. pkg.go.dev/godoc scraping matches the declared module path against its hosting path, so the stale path broke SDK doc generation.
Rename the module path across all four in-repo modules (root, the two db/driver submodules, observer/otel, and docs/site) and every internal import, plus the release workflow, the doc-generation script, and the docs.
No tag has been published under the go-libfossil path yet, so the cross-module requires cannot resolve from the proxy. Add replace directives pointing the in-repo requires at their local directories so GOWORK=off builds and the CI matrix resolve without a published version. These replaces are ignored by downstream consumers and can be dropped once new-path tags are cut.
* Guard releases against replace directives; regenerate SDK docs
The go-libfossil rename bridges the in-repo modules with `replace` directives. Go refuses a main module that carries them, so a tag cut while they are present breaks `go install .../cmd/libfossil@<tag>` and every `@version` fetch of the driver submodules. Add a Release workflow step that fails the job before anything is published if any tracked go.mod still contains a replace directive, so the bridge is a CI-enforced TODO rather than a silent landmine. The step comment records what unblocks a release: re-tag the submodules with the corrected module paths, bump the root requires, then drop the replace blocks.
Regenerate the SDK reference docs. The previous pass only substituted URLs over the pre-existing generated files, leaving stale signatures (Repo.Timeline was still documented as taking LogOpts rather than TimelineOpts). Note that gomarkdoc must be run outside a git worktree — inside one it silently strips every source link.
Also reword the README rename note, which read as though the import path had not changed, and re-sort the ncruces require block. (user: [email protected], size: 2505) [annotate] [blame] [check-ins using]
# wasm (WASI Preview 1) Minimal example of building `libfossil` for a generic WASI Preview 1 wasm target. The produced `.wasm` binary is not tied to any specific runtime and is intended to run under `wasmtime`, `wazero`, or any other WASI P1 host. ## Driver choice The default `modernc.org/sqlite` driver pulls in syscalls (`pthread`, `signal`, `stdio`, `sys/types`, `unistd`, ...) that have no Go files under `GOOS=wasip1`, so `_ "github.com/danmestas/go-libfossil/db/driver/modernc"` will not compile for wasip1. This example blank-imports the `ncruces` driver instead: ```go _ "github.com/danmestas/go-libfossil/db/driver/ncruces" ``` `ncruces/go-sqlite3` ships SQLite itself as WebAssembly and is the supported driver for `wasip1` and browser (`js`) builds. ## Build From the repo root: ``` GOOS=wasip1 GOARCH=wasm go build -o libfossil-demo.wasm ./examples/wasm/ ``` The output is a generic WASI P1 module (`~22 MiB`) with no runtime-specific imports. ## Run ### wasmtime `wasmtime` requires an explicit `--dir` map so the guest can see a writable directory. The simplest form maps the current host directory to the guest root: ``` wasmtime run --dir=.::/ libfossil-demo.wasm ``` `--dir=.` alone works in newer wasmtime releases but some versions require the explicit `HOST::GUEST` form shown above. ### wazero (CLI) ``` wazero run -mount .:/ libfossil-demo.wasm ``` ## What the example demonstrates - Registering the `ncruces` driver via a blank import. - `libfossil.Create` to create a fresh `.fossil` file in the mapped directory. - `libfossil.Open` to re-open it. - `repo.Config("project-code")` to read a config row. - `repo.Commit` to write one file. - `repo.Timeline` and `repo.ListFiles` to read back the commit. ## Runtime limitations under WASI WASI P1 does not expose POSIX / OFD / BSD file locking, which SQLite relies on for concurrency control. `libfossil` detects `GOOS=wasip1` at compile time and switches to a WAL-free, exclusive-locking pragma profile (see `db/config_wasm.go`), but some combinations of host runtime and SQLite VFS still surface I/O errors when `PRAGMA journal_mode` is set through the DSN. If you hit `sqlite3: invalid _pragma: sqlite3: disk I/O error` under your runtime, the issue is in the SQLite VFS glue, not in this example — the build itself is a clean WASI P1 artifact and loads fine under wasmtime / wazero. The example is designed for single-process, single-connection usage, which is the supported mode for `libfossil` on WASI.