Skip to content

feat: support building for WASI - #1314

Open
msuozzo wants to merge 1 commit into
rust-lang:mainfrom
msuozzo:push-knnuksvulkut
Open

msuozzo wants to merge 1 commit into
rust-lang:mainfrom
msuozzo:push-knnuksvulkut

Conversation

@msuozzo

@msuozzo msuozzo commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Get git2 build running for the wasm32-wasip1 target. Given its lack of
socket support, this necessarily excludes the https and ssh features
for now (although wasip2 does add sockets).

The only change for non-WASI users is that libgit2-sys bumps the version
of libz-sys to 1.1.30 (see rust-lang/libz-sys#273).

On WASI, libgit2-sys requires the vendored feature, so libgit2 can be
compiled with a few local changes:

  • NO_MMAP is defined.
  • GIT_THREADS is off, ensuring wasm32-wasip1-threads won't build,
    which would otherwise make git2 Send types unsound.
  • streams/socket.c is stubbed out to return an error.
  • libgit2-sys/wasi/ stubs the user and process IDs and pwd.h, which
    wasi-libc lacks. The home directory comes from $HOME.
  • -Wno-incompatible-pointer-types works around a type mismatch in
    integer.h until integer: use type-generic overflow intrinsics for size_t libgit2/libgit2#7406 lands.

git2 itself needed two fixes to work on WASI. Its path conversions only
had unix and windows versions, so a wasi-specific variant is needed to
compile. std's env::join_paths also always fails on WASI, which made
every Repository::open_ext and discover_path call fail. The fix is
to re-implement those joins for wasi ourselves.

The new WASI CI job builds with wasi-sdk and runs the tests under
wasmtime on stable, beta and nightly. On MSRV (1.87), CI only builds,
since std's remove_dir_all is buggy on WASI before Rust 1.94. git2
itself doesn't use it.

Most of the test diff swaps TempDir::new() for a test::tempdir()
helper. std has no temp directory on WASI, so the helper points tempfile
at /tmp, which the CI runner preopens.

Four tests are skipped on WASI:

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Oct 11, 2026

@DanielEScherzer DanielEScherzer left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not going to pretend like I understand everything here, but some suggestions

View changes since this review

Comment thread .github/workflows/main.yml Resolved
Comment thread libgit2-sys/wasi/compat.c Resolved
@msuozzo

msuozzo commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

I intend to incorporate the changes from #1316, which run the test suite on WASI, once libz-sys releases the fix they need (rust-lang/libz-sys#276).

@msuozzo
msuozzo force-pushed the push-knnuksvulkut branch 2 times, most recently from 5d3f083 to c770a67 Compare October 12, 2026 16:25
@msuozzo

msuozzo commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

libz-sys 1.1.30 is out, so I've folded in #1316. libgit2-sys now requires 1.1.30, and the WASI job runs the test suite under wasmtime.

Get git2 build running for the `wasm32-wasip1` target. Given its lack of
socket support, this necessarily excludes the `https` and `ssh` features
for now (although wasip2 does add sockets).

The only change for non-WASI users is that libgit2-sys bumps the version
of libz-sys to 1.1.30 (see rust-lang/libz-sys#273).

On WASI, libgit2-sys requires the `vendored` feature, so libgit2 can be
compiled with a few local changes:

- `NO_MMAP` is defined.
- `GIT_THREADS` is off, ensuring `wasm32-wasip1-threads` won't build,
  which would otherwise make git2 `Send` types unsound.
- `streams/socket.c` is stubbed out to return an error.
- `libgit2-sys/wasi/` stubs the user and process IDs and `pwd.h`, which
  wasi-libc lacks. The home directory comes from `$HOME`.
- `-Wno-incompatible-pointer-types` works around a type mismatch in
  `integer.h` until libgit2/libgit2#7406 lands.

git2 itself needed two fixes to work on WASI. Its path conversions only
had unix and windows versions, so a wasi-specific variant is needed to
compile. std's `env::join_paths` also always fails on WASI, which made
every `Repository::open_ext` and `discover_path` call fail. The fix is
to re-implement those joins for wasi ourselves.

The new WASI CI job builds with wasi-sdk and runs the tests under
wasmtime on stable, beta and nightly. On MSRV (1.87), CI only builds,
since std's `remove_dir_all` is buggy on WASI before Rust 1.94. git2
itself doesn't use it.

Most of the test diff swaps `TempDir::new()` for a `test::tempdir()`
helper. std has no temp directory on WASI, so the helper points tempfile
at `/tmp`, which the CI runner preopens.

Four tests are skipped on WASI:

- `compile_fail` runs cargo.
- `non_utf8_branch` needs non-UTF-8 paths.
- `keeping_original_author_msg` and `prune` remove directories through
  paths with a trailing slash, which wasmtime rejects pending release of
  the fix (bytecodealliance/wasmtime#14662).
@rustbot

rustbot commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Waiting on review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants