GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Build for wasm32-wasip1 (WASI preview 1) by pankgeorg · Pull Request #7464 · libgit2/libgit2 ConversationThis lets libgit2 build for WebAssembly with wasi-sdk, as a static library for WASI preview 1 offers a POSIX-like filesystem through wasi-libc. It has no sockets, processes, users, Commits
BuildingWith wasi-sdk (tested with wasi-sdk 34, clang 23): cmake -S . -B build-wasi -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK/share/cmake/wasi-sdk-p1.cmake \ -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_CLI=OFF \ -DUSE_THREADS=OFF -DUSE_HTTPS=OFF -DUSE_SSH=OFF -DUSE_AUTH_NTLM=OFF -DUSE_AUTH_NEGOTIATE=OFF cmake --build build-wasi This produces TestingI don't add CI here, and I'd welcome guidance if you want a WASI job (the clar suite would need a WASI runner such as wasmtime or Node, plus a list of tests that need sockets or processes). What I checked:
Known WASI limits that need no code here: there are no permission bits, so The patches, tests and this description were drafted with an AI agent (Claude Code, Claude Opus 5.5) and reviewed before opening. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsOn wasm32 `size_t` is `unsigned long`, but `SIZE_MAX == UINT_MAX`, so the `SIZE_MAX` tests select `__builtin_uadd_overflow`/`__builtin_umul_overflow`, whose `unsigned int *` result type does not match a `size_t *`; clang rejects every caller with -Wincompatible-pointer-types. Use the type-generic `__builtin_add_overflow`/`__builtin_mul_overflow` there, which are correct for any width. WASI preview 1 has no sockets (no `<netdb.h>`, `<sys/socket.h>` or `<netinet/*>`). Build the socket stream there without the BSD socket code: the default stream fails with an error that says to register a stream (`git_stream_register`) or a transport (`git_transport_register`). A custom `GIT_STREAM_STANDARD` registration is still honoured. WASI has no users: no `<pwd.h>`, `getpwuid_r`, `getuid` or `geteuid`. Treat it as a single-user system whose home and XDG directories come from `$HOME` and `$XDG_CONFIG_HOME` only; the passwd lookup reports not found. WASI has no processes (no fork, exec, pipes or `<sys/wait.h>`). Only the `exec` SSH transport uses `git_process`, and SSH is not available on WASI; compile the unix implementation out there. llhttp's api.c declares `wasm_on_*` functions for its own build, which runs in a JavaScript host that implements them. Any other WebAssembly build that links llhttp then has eight undefined imports. Exclude them under `__wasi__`, where llhttp is used as an ordinary C library. WASI has no `getpid`, `getppid`, `getpgid`, `getsid`, `getuid` or `getgid`. The seed comes from `getentropy` there (which WASI provides and CMake detects); the time-based fallback leaves the ids out. WASI has no users: no `geteuid`, and `stat` reports no owner. Give WASI its own `git_fs_path_owner_is` that treats every existing file as the current user's, so the ownership checks of `safe.directory` pass, as they do for a single-user system. Define NO_MMAP for `CMAKE_SYSTEM_NAME` WASI: WASI preview 1 has no `mmap`
(wasi-libc offers only an emulation behind `_WASI_EMULATED_MMAN`), so
packfiles and other mapped files are read into allocated memory, as on other
platforms without mmap.
With the preceding changes, libgit2 builds for wasm32-wasip1 with wasi-sdk's
toolchain file and
cmake -DCMAKE_TOOLCHAIN_FILE=<wasi-sdk>/share/cmake/wasi-sdk-p1.cmake \
-DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_CLI=OFF \
-DUSE_THREADS=OFF -DUSE_HTTPS=OFF -DUSE_SSH=OFF
Network access needs a custom transport or stream, since WASI preview 1 has
no sockets.
wasi-libc's realpath() calls readlink() on every prefix of the path, and a prefix that is not inside a preopened directory fails: "/a" for the preopen "/a/b". So with a preopen of more than one path component, nothing below it resolves, and `git_repository_init`, `git_repository_open` and others fail with "failed to resolve path". When realpath() fails that way on WASI, resolve the path lexically (`.` and `..`, relative to the working directory) and check that it exists. Symbolic links are not resolved in that case. Node's WASI (uvwasi) fails readlink() with ENOBUFS when the link's target fills the buffer exactly, where POSIX truncates it. libgit2 reads a symbolic link into a buffer of its target's length (`st_size`), so on Node every symlink in a work tree fails: diffs and status report "failed to read symlink data ... No buffer space available". On WASI, read into a buffer one byte longer and copy the target.
pankgeorg
added a commit
to pankgeorg/LibGit2_wasm_jll.jl
that referenced
this pull request
This branch has not been deployedNo deployments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |