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
Add support for WebAssembly System Interface (wasm32-wasi) #90473
Comments
WASI is another WebAssembly platform similar to Emscripten (bpo-40280). Simply speaking Emscripten binaries (wasm32-emscripten) run inside a browser while WASI binaries target standalone runtimes like wasmtime [2][3] on the host. The lines are a bit blurry, as it is possible to run WASI binaries in the browser with help of JS-polyfills. WASI provides compile once, run anyway with JIT/AOT and sandboxing. WASI is still under development and is lacking several core features:
For 3.11 I plan to fix our use of #ifdef HAVE_FEATURE to make it easier to experiment with WASI. The pthread APIs need stubs, which I won't commit to 3.11 upstream yet. [1] https://wasi.dev/ |
dup() is required by _PyTokenizer_FindEncodingFilename(). I came up with this hack: // from wasi-libc libc-top-half/musl/src/internal/stdio_impl.h
struct _IO_FILE {
unsigned flags;
unsigned char *rpos, *rend;
int (*close)(FILE *);
unsigned char *wend, *wpos;
// incomplete
};
static int
dummy_close(FILE *fp) {
return 0;
};
static FILE *
_Py_fdopen_borrow(int fd, const char *mode) {
FILE *fp = fdopen(fd, mode);
((struct _IO_FILE*)fp)->close = dummy_close;
return fp;
} keithw on #wasi pointed out that fopencookie() can archive the same outcome without resorting to ABI-specific hack. A trivial implementation is straight forward: typedef union {
void *cookie;
int fd;
} borrowed; static ssize_t static ssize_t
borrow_write(void *cookie, const char *buf, size_t size)
{
errno = ENOTSUP;
return -1;
}
static int
borrow_seek(void *cookie, off_t *off, int whence)
{
borrowed b;
b.cookie = cookie;
off_t pos;
pos = lseek(b.fd, *off, whence);
if (pos == (off_t)-1) {
return -1;
} else {
*off = pos;
return 0;
}
}
static int
borrow_close(void *cookie)
{
// does not close(fd)
return 0;
}
FILE *
_Py_fdopen_borrow(int fd, const char *mode) {
// only support read for now
if (strcmp(mode, "r") != 0) {
return NULL;
}
cookie_io_functions_t cookie_io = {
borrow_read, borrow_write, borrow_seek, borrow_close
};
// cookie is just the fd
borrowed b;
b.fd = fd;
return fopencookie(b.cookie, "r", cookie_io);
} |
Reduce recursion limit to 750. WASI has limited call stack. Mark tests that require mmap, os.pipe, or fail on musl libc.
Reduce recursion limit to 750. WASI has limited call stack. Mark tests that require mmap, os.pipe, or fail on musl libc.
) (cherry picked from commit db0b455) Co-authored-by: Christian Heimes <christian@python.org>
Reduce recursion limit to 750. WASI has limited call stack. Mark tests that require mmap, os.pipe, or fail on musl libc.
Reduce recursion limit to 750. WASI has limited call stack. Mark tests that require mmap, os.pipe, or fail on musl libc.
Reduce recursion limit to 750. WASI has limited call stack. Mark tests that require mmap, os.pipe, or fail on musl libc.
(cherry picked from commit 4c71d22) Co-authored-by: Christian Heimes <christian@python.org>
WASI does not have ``chmod(2)`` syscall yet.
…honGH-93536) (cherry picked from commit 80a39da) Co-authored-by: Christian Heimes <christian@python.org>
WASI does not have the ``chmod(2)`` syscall yet.
(cherry picked from commit 22df2e0) Co-authored-by: Christian Heimes <christian@python.org>
The test cases are incompatible with WASI mapdir and OOT builds. wasmtime starts the process with ``/`` as CWD, but the files are in a subdirectory.
(cherry picked from commit 6099611) Co-authored-by: Christian Heimes <christian@python.org>
Almost all tests were already skipped anyways. The remaining tests are not useful without threading primitives like locks and conditions.
…onGH-93712) (cherry picked from commit f0b7aa7) Co-authored-by: Christian Heimes <christian@python.org>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: