Skip to content

UPSTREAM PR #2471: feat: add WASI (wasm32-wasip2) platform support#33

Open
loci-dev wants to merge 1 commit into
mainfrom
loci/pr-2471-feat-wasi-support
Open

UPSTREAM PR #2471: feat: add WASI (wasm32-wasip2) platform support#33
loci-dev wants to merge 1 commit into
mainfrom
loci/pr-2471-feat-wasi-support

Conversation

@loci-dev
Copy link
Copy Markdown

Note

Source pull request: GitoxideLabs/gitoxide#2471

Summary

Add compilation support for the wasm32-wasip2 target across four crates, enabling gitoxide to compile under WASI sandboxed environments such as Wasmtime.

Changes

  • gix-path: Enable #![feature(wasip2)] via cfg_attr for WASI builds, required for std::os::wasi path handling
  • gix-fs/symlink: Split #[cfg(not(windows))] into separate #[cfg(unix)] and #[cfg(target_os = "wasi")] blocks — WASI uses std::fs::soft_link since std::os::unix::fs::symlink is unavailable
  • gix-fs/capabilities: Add a Default impl for Capabilities on WASI (no executable bit, symlinks enabled, no case-folding or unicode precomposition)
  • gix-index/fs: Replace #[cfg(not(windows))] / #[cfg(windows)] with #[cfg(unix)] / #[cfg(not(unix))], grouping WASI with Windows for metadata access via std::fs::Metadata instead of rustix::fs::Stat

Motivation

We're compiling the GitButler CLI (but) to wasm32-wasip2 to run git operations inside sandboxed WASI agents. These four changes were the minimum needed to get gitoxide compiling for this target.

Notes

  • The #![feature(wasip2)] in gix-path requires nightly or RUSTC_BOOTSTRAP=1 on stable — this is a temporary requirement until std::os::wasi stabilizes
  • rustix doesn't support WASI, so gix-index falls back to std::fs::Metadata (same as Windows)
  • No behavioral changes for existing unix/windows/macos targets — all existing #[cfg] paths are preserved

Test plan

  • Verified cargo build --target wasm32-wasip2 succeeds for a downstream consumer (GitButler but CLI)
  • Verified no regressions on native Linux build
  • CI should confirm no regressions on Windows/macOS

Add compilation support for the `wasm32-wasip2` target across four crates:

**gix-path**: Enable `#![feature(wasip2)]` via `cfg_attr` for WASI builds,
required for `std::os::wasi` path handling.

**gix-fs/symlink**: Split `#[cfg(not(windows))]` into separate `#[cfg(unix)]`
and `#[cfg(target_os = "wasi")]` blocks. WASI uses `std::fs::soft_link` since
`std::os::unix::fs::symlink` is unavailable. `remove()` and
`is_collision_error()` use `#[cfg(any(unix, target_os = "wasi"))]`.

**gix-fs/capabilities**: Add a `Default` impl for `Capabilities` on WASI
(no executable bit, symlinks enabled, no case-folding or unicode
precomposition).

**gix-index/fs**: Replace `#[cfg(not(windows))]` / `#[cfg(windows)]` pairs
with `#[cfg(unix)]` / `#[cfg(not(unix))]`. This groups WASI with Windows
for metadata access, using `std::fs::Metadata` instead of `rustix::fs::Stat`
(rustix doesn't support WASI). The `system_time_from_secs_nanos` helper is
now `#[cfg(unix)]` only.

These changes allow gitoxide to compile (and partially function) under
WASI sandboxed environments such as Wasmtime.
@loci-review
Copy link
Copy Markdown

loci-review Bot commented Mar 17, 2026

Overview

Analysis of WASI platform support addition (commit 43bf94d) across two binaries shows negligible performance impact. Total functions: 34,636 (6,159 modified, 8,250 new, 8,282 removed).

Power consumption:

  • target.aarch64-unknown-linux-gnu.release.gix: 804,258.03 nJ → 803,778.78 nJ (-0.06%)
  • target.aarch64-unknown-linux-gnu.release.ein: 299,406.49 nJ → 301,228.08 nJ (+0.61%)

Function Analysis

Standard library I/O improvements (performance-critical):

  • std::io::Read::read_buf_exact (gix): Response time -1.72% (-163ns), used extensively in pack file reading
  • std::io::BufRead::skip_until (gix): Response time -1.97% (-62ns), benefits protocol handling
  • gix_negotiate::consecutive::Algorithm::add_tip (gix): Response time -3.52% (-223ns), improves fetch negotiation

Regressions in non-critical paths:

  • human_format::to_scaled_value (ein): Response time +1,125,522% (+68,312ns) — external dependency used only for CLI progress formatting
  • std::io::Read::read_exact (gix): Response time +22.06% (+548ns) — added protocol-aware functionality (header handling, content-type validation)
  • bstr::BString::fmt (gix): Response time +40.99% (+983ns) — external dependency for debug formatting
  • hyper::client::conn::http1::upgrades::UpgradeableConnection::poll (gix): Response time +2.50% (+64µs), throughput time +3,897% — enhanced state machine in HTTP transport, masked by network latency

Compiler-generated changes: Multiple OUTLINED_FUNCTION_* instances show large percentage increases (up to 506,496%) but minimal absolute impact (<70µs), affecting only cold paths (error handling, cleanup, initialization).

Source code context: Single commit added WASI platform support to gix-fs, gix-path, and gix-config-value with compile-time conditionals. Changes don't affect aarch64-linux target directly. Observed performance differences stem from compiler optimizations, standard library updates, and external dependency changes rather than application code modifications.

Additional Findings

Performance-critical Git operations (pack handling, object database access, diff algorithms) remain unaffected. Core I/O primitives show improvements through better lock acquisition (-2.6% in lock_slow) and optimized read operations. The WASI platform support successfully adds cross-platform compatibility without compromising performance on existing targets.

🔎 Full breakdown: Loci Inspector
💬 Questions? Tag @loci-dev

@loci-dev loci-dev force-pushed the main branch 5 times, most recently from 0223bcb to bfaee00 Compare March 24, 2026 07:50
@loci-dev loci-dev force-pushed the main branch 6 times, most recently from 0e47b1e to 8b02847 Compare March 31, 2026 07:55
@loci-dev loci-dev force-pushed the main branch 3 times, most recently from 96cdaee to cdbe120 Compare April 9, 2026 07:02
@loci-dev loci-dev force-pushed the main branch 5 times, most recently from 9c2e45d to 5124e99 Compare April 17, 2026 07:07
@loci-dev loci-dev force-pushed the main branch 5 times, most recently from 1c8b114 to e902b63 Compare April 26, 2026 07:07
@loci-dev loci-dev force-pushed the main branch 2 times, most recently from c6739bc to 6f67b12 Compare April 29, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants