From 6ead2fa7f1bc0c9e1988e9a5960579038fbc6183 Mon Sep 17 00:00:00 2001 From: Jesse Rusak Date: Fri, 15 Nov 2024 12:06:07 -0500 Subject: [PATCH] Update to latest wasmtime dev (#257) --- ci/cbindgen.py | 16 +++++ ci/download-wasmtime.py | 5 +- rust/Cargo.lock | 146 ++++++++++++++++++++-------------------- rust/Cargo.toml | 11 +-- rust/src/bindgen.rs | 4 +- tests/test_wasi.py | 4 +- wasmtime/__init__.py | 4 +- wasmtime/_bindings.py | 138 ++++++++++++++++++++++++++----------- wasmtime/_table.py | 4 +- wasmtime/_types.py | 15 +++-- wasmtime/_wasi.py | 35 ++++++++-- 11 files changed, 245 insertions(+), 137 deletions(-) diff --git a/ci/cbindgen.py b/ci/cbindgen.py index 1c244d7a..5aa16df4 100644 --- a/ci/cbindgen.py +++ b/ci/cbindgen.py @@ -20,6 +20,7 @@ def __init__(self): self.ret += 'from ctypes import *\n' self.ret += 'import ctypes\n' self.ret += 'from typing import Any\n' + self.ret += 'from enum import Enum, auto\n' self.ret += 'from ._ffi import dll, wasm_val_t, wasm_ref_t\n' # Skip all function definitions, we don't bind those @@ -65,6 +66,19 @@ def visit_Union(self, node): else: self.ret += " pass\n" + def visit_Enum(self, node): + if not node.name or not node.name.startswith('was'): + return + + self.ret += "\n" + self.ret += "class {}(Enum):\n".format(node.name) + for enumerator in node.values.enumerators: + if enumerator.value: + self.ret += " {} = {}\n".format(enumerator.name, enumerator.value.value) + else: + self.ret += " {} = auto()\n".format(enumerator.name) + + def visit_Typedef(self, node): if not node.name or not node.name.startswith('was'): return @@ -194,6 +208,8 @@ def type_name(ty, ptr=False, typing=False): return ty.name elif isinstance(ty, c_ast.Union): return ty.name + elif isinstance(ty, c_ast.Enum): + return ty.name elif isinstance(ty, c_ast.FuncDecl): tys = [] # TODO: apparently errors are thrown if we faithfully represent the diff --git a/ci/download-wasmtime.py b/ci/download-wasmtime.py index ecb8f66d..344d6c03 100644 --- a/ci/download-wasmtime.py +++ b/ci/download-wasmtime.py @@ -1,5 +1,5 @@ # Helper script to download a precompiled binary of the wasmtime dll for the -# current platform. Currently always downloads the dev release of wasmtime. +# current platform. import io import platform @@ -10,7 +10,8 @@ import zipfile from pathlib import Path -WASMTIME_VERSION = "v25.0.0" + # set to "dev" to download the latest or pick a tag from https://github.com/bytecodealliance/wasmtime/tags +WASMTIME_VERSION = "dev" def main(platform, arch): diff --git a/rust/Cargo.lock b/rust/Cargo.lock index ea5153fe..a78c38b9 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -16,9 +16,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "bindgen" @@ -27,6 +27,7 @@ dependencies = [ "anyhow", "heck 0.4.1", "indexmap", + "wasmparser", "wasmtime-environ", "wit-bindgen", "wit-bindgen-core", @@ -54,9 +55,9 @@ checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" [[package]] name = "cranelift-bitset" -version = "0.112.0" +version = "0.113.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2797648025a7b2e32ec49fb2f71655fed74453cd41e209c6e39fd3107654f8" +checksum = "c7cb269598b9557ab942d687d3c1086d77c4b50dcf35813f3a65ba306fd42279" dependencies = [ "serde", "serde_derive", @@ -64,9 +65,9 @@ dependencies = [ [[package]] name = "cranelift-entity" -version = "0.112.0" +version = "0.113.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e9d6c799b0775d43211d983b5f9230ea604063003cb6d492daf8dcac51da9b" +checksum = "963c17147b80df351965e57c04d20dbedc85bcaf44c3436780a59a3f1ff1b1c2" dependencies = [ "cranelift-bitset", "serde", @@ -100,11 +101,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" dependencies = [ "indexmap", ] @@ -119,6 +126,15 @@ dependencies = [ "serde", ] +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "foldhash", +] + [[package]] name = "heck" version = "0.4.1" @@ -142,12 +158,12 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.1", "serde", ] @@ -177,21 +193,21 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "crc32fast", - "hashbrown", + "hashbrown 0.15.1", "indexmap", "memchr", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "postcard" @@ -207,9 +223,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.22" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", "syn", @@ -217,9 +233,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -250,18 +266,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -270,9 +286,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -291,18 +307,18 @@ dependencies = [ [[package]] name = "spdx" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc" +checksum = "bae30cc7bfe3656d60ee99bf6836f472b0c53dddcbf335e253329abb16e535a2" dependencies = [ "smallvec", ] [[package]] name = "syn" -version = "2.0.77" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -350,9 +366,9 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasm-encoder" -version = "0.217.0" +version = "0.218.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b88b0814c9a2b323a9b46c687e726996c255ac8b64aa237dd11c81ed4854760" +checksum = "22b896fa8ceb71091ace9bcb81e853f54043183a1c9667cf93422c40252ffa0a" dependencies = [ "leb128", "wasmparser", @@ -360,9 +376,9 @@ dependencies = [ [[package]] name = "wasm-metadata" -version = "0.217.0" +version = "0.218.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65a146bf9a60e9264f0548a2599aa9656dba9a641eff9ab88299dc2a637e483c" +checksum = "aa5eeb071abe8a2132fdd5565dabffee70775ee8c24fc7e300ac43f51f4a8a91" dependencies = [ "anyhow", "indexmap", @@ -376,13 +392,13 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.217.0" +version = "0.218.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca917a21307d3adf2b9857b94dd05ebf8496bdcff4437a9b9fb3899d3e6c74e7" +checksum = "b09e46c7fceceaa72b2dd1a8a137ea7fd8f93dfaa69806010a709918e496c5dc" dependencies = [ "ahash", "bitflags", - "hashbrown", + "hashbrown 0.14.5", "indexmap", "semver", "serde", @@ -390,9 +406,9 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.217.0" +version = "0.218.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50dc568b3e0d47e8f96ea547c90790cfa783f0205160c40de894a427114185ce" +checksum = "0ace089155491837b75f474bf47c99073246d1b737393fe722d6dee311595ddc" dependencies = [ "anyhow", "termcolor", @@ -401,15 +417,15 @@ dependencies = [ [[package]] name = "wasmtime-component-util" -version = "25.0.0" +version = "26.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8553d3720625ad4e65a9c71e215566361fcefc4e4001f17e7c669c503c33e6f6" +checksum = "35e87a1212270dbb84a49af13d82594e00a92769d6952b0ea7fc4366c949f6ad" [[package]] name = "wasmtime-environ" -version = "25.0.0" +version = "26.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe742ef5ee9ce201e513ee8da472eaf198e760499a730853622fc85a61cfb1eb" +checksum = "8613075e89e94a48c05862243c2b718eef1b9c337f51493ebf951e149a10fa19" dependencies = [ "anyhow", "cranelift-bitset", @@ -422,26 +438,12 @@ dependencies = [ "semver", "serde", "serde_derive", + "smallvec", "target-lexicon", "wasm-encoder", "wasmparser", "wasmprinter", "wasmtime-component-util", - "wasmtime-types", -] - -[[package]] -name = "wasmtime-types" -version = "25.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24adc06abbf23bf9abbdc4b4a3bb743436a60a2a76dfabb2e49bf5237d0dadcc" -dependencies = [ - "anyhow", - "cranelift-entity", - "serde", - "serde_derive", - "smallvec", - "wasmparser", ] [[package]] @@ -528,9 +530,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wit-bindgen" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eb9327b2afd6af02ab39f8fbde6bfc7d369d14bc8c8688311d3defcda3952bd" +checksum = "8fcf26778671a2327bd237a32c6f2d1d9bb0ec077e482b0839552b00d4566544" dependencies = [ "wit-bindgen-rt", "wit-bindgen-rust-macro", @@ -538,9 +540,9 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc9cfd3f1b4e29e9a90fe04157764f24ae396cfb8530dae5753de140e73f9e56" +checksum = "4b885a00e1c428fd12b7b7c4bccc4bad8b2a3ca0abe8eaf1e0f90adabb4c7ac7" dependencies = [ "anyhow", "heck 0.5.0", @@ -549,18 +551,18 @@ dependencies = [ [[package]] name = "wit-bindgen-rt" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca6f307148acf7199e492fd3781cc7b79f8f3eda003c0ac3aa8079449601ccb" +checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" dependencies = [ "bitflags", ] [[package]] name = "wit-bindgen-rust" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf075ae0c89dc391f7d710d70c69bfd018c029c74a54f7ddfd0266dccc8ff0c5" +checksum = "542608877814a54f6bea6b24dcbe249a2e293d67d709f4f8ec578d06b1c00730" dependencies = [ "anyhow", "heck 0.5.0", @@ -574,9 +576,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ab28d36e4d326bd43d483512348874d4fffa378d8dc1da6dd6521afe2ec4f6" +checksum = "30d462025f670fff96606ddbfe62500255b4fe3de7298cd9cbabb2de3d567183" dependencies = [ "anyhow", "prettyplease", @@ -589,9 +591,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.217.0" +version = "0.218.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7117809905e49db716d81e794f79590c052bf2fdbbcda1731ca0fb28f6f3ddf" +checksum = "aa53aa7e6bf2b3e8ccaffbcc963fbdb672a603dc0af393a481b6cec24c266406" dependencies = [ "anyhow", "bitflags", @@ -608,9 +610,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.217.0" +version = "0.218.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb893dcd6d370cfdf19a0d9adfcd403efb8e544e1a0ea3a8b81a21fe392eaa78" +checksum = "0d3d1066ab761b115f97fef2b191090faabcb0f37b555b758d3caf42d4ed9e55" dependencies = [ "anyhow", "id-arena", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index a3496cef..05112175 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -9,12 +9,13 @@ crate-type = ['cdylib', 'rlib'] [dependencies] anyhow = "1.0" heck = { version = "0.4", features = ["unicode"] } -wit-parser = "0.217.0" -wit-component = "0.217.0" +wit-parser = "0.218.0" +wit-component = "0.218.0" indexmap = "2.0" -wasmtime-environ = { version = "25.0.0", features = ['component-model', 'compile'] } -wit-bindgen = { version = "0.32.0" } -wit-bindgen-core = "0.32.0" +wasmtime-environ = { version = "26.0.1", features = ['component-model', 'compile'] } +wit-bindgen = { version = "0.33.0" } +wit-bindgen-core = "0.33.0" +wasmparser = "0.218.0" # this can be removed once wasmtime-environ re-exports wasmparser (wasmtime 27) [features] diff --git a/rust/src/bindgen.rs b/rust/src/bindgen.rs index e82c47ae..528ce042 100644 --- a/rust/src/bindgen.rs +++ b/rust/src/bindgen.rs @@ -31,6 +31,8 @@ use crate::ns::Ns; use crate::source::{self, Source}; use anyhow::{bail, Context, Result}; use heck::*; +use wasmparser::Validator; +use wasmtime_environ::prelude::*; use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::fmt::Write; use std::mem; @@ -40,8 +42,6 @@ use wasmtime_environ::component::{ RuntimeImportIndex, RuntimeInstanceIndex, StaticModuleIndex, StringEncoding, Trampoline, TrampolineIndex, Translator, TypeFuncIndex, TypeResourceTableIndex, }; -use wasmtime_environ::wasmparser::collections::IndexMap; -use wasmtime_environ::wasmparser::Validator; use wasmtime_environ::{EntityIndex, ModuleTranslation, PrimaryMap, ScopeVec, Tunables}; use wit_bindgen_core::abi::{self, AbiVariant, Bindgen, Bitcast, Instruction, LiftLower, WasmType}; use wit_component::DecodedWasm; diff --git a/tests/test_wasi.py b/tests/test_wasi.py index eb0921d1..2a3ddf69 100644 --- a/tests/test_wasi.py +++ b/tests/test_wasi.py @@ -30,7 +30,7 @@ def test_config(self): config.stdout_file = 'some-directory/without-a-rainbow' with self.assertRaises(WasmtimeError): config.stderr_file = 'some-directory/without-a-rainbow' - config.preopen_dir('wasmtime', 'other') + config.preopen_dir('wasmtime', 'other', DirPerms.READ_WRITE, FilePerms.READ_WRITE) def test_preview1(self): linker = Linker(Engine()) @@ -50,4 +50,4 @@ def test_preview1(self): def preopen_nonexistent(self): config = WasiConfig() with self.assertRaises(WasmtimeError): - config.preopen_dir('/path/to/nowhere', '/') + config.preopen_dir('/path/to/nowhere', '/', DirPerms.READ_ONLY, FilePerms.READ_ONLY) diff --git a/wasmtime/__init__.py b/wasmtime/__init__.py index 9776bf40..434e3971 100644 --- a/wasmtime/__init__.py +++ b/wasmtime/__init__.py @@ -29,7 +29,7 @@ from ._table import Table from ._memory import Memory from ._instance import Instance -from ._wasi import WasiConfig +from ._wasi import WasiConfig, FilePerms, DirPerms from ._linker import Linker __all__ = [ @@ -58,6 +58,8 @@ 'Module', 'Instance', 'WasiConfig', + 'FilePerms', + 'DirPerms', 'Linker', 'WasmtimeError', ] diff --git a/wasmtime/_bindings.py b/wasmtime/_bindings.py index 1e5ad6ed..5709afcb 100644 --- a/wasmtime/_bindings.py +++ b/wasmtime/_bindings.py @@ -6,6 +6,7 @@ from ctypes import * import ctypes from typing import Any +from enum import Enum, auto from ._ffi import dll, wasm_val_t, wasm_ref_t wasm_byte_t = c_ubyte @@ -103,6 +104,10 @@ def wasm_store_new(arg0: Any) -> ctypes._Pointer: wasm_mutability_t = c_uint8 +class wasm_mutability_enum(Enum): + WASM_CONST = auto() + WASM_VAR = auto() + class wasm_limits_t(Structure): _fields_ = [ ("min", c_uint32), @@ -166,6 +171,14 @@ def wasm_valtype_copy(arg0: Any) -> ctypes._Pointer: wasm_valkind_t = c_uint8 +class wasm_valkind_enum(Enum): + WASM_I32 = auto() + WASM_I64 = auto() + WASM_F32 = auto() + WASM_F64 = auto() + WASM_EXTERNREF = 128 + WASM_FUNCREF = auto() + _wasm_valtype_new = dll.wasm_valtype_new _wasm_valtype_new.restype = POINTER(wasm_valtype_t) _wasm_valtype_new.argtypes = [wasm_valkind_t] @@ -511,6 +524,12 @@ def wasm_externtype_copy(arg0: Any) -> ctypes._Pointer: wasm_externkind_t = c_uint8 +class wasm_externkind_enum(Enum): + WASM_EXTERN_FUNC = auto() + WASM_EXTERN_GLOBAL = auto() + WASM_EXTERN_TABLE = auto() + WASM_EXTERN_MEMORY = auto() + _wasm_externtype_kind = dll.wasm_externtype_kind _wasm_externtype_kind.restype = wasm_externkind_t _wasm_externtype_kind.argtypes = [POINTER(wasm_externtype_t)] @@ -1953,11 +1972,23 @@ def wasi_config_set_stderr_file(config: Any, path: Any) -> bool: def wasi_config_inherit_stderr(config: Any) -> None: return _wasi_config_inherit_stderr(config) # type: ignore +class wasi_dir_perms_flags(Enum): + WASMTIME_WASI_DIR_PERMS_READ = 1 + WASMTIME_WASI_DIR_PERMS_WRITE = 2 + +wasi_dir_perms = c_size_t + +class wasi_file_perms_flags(Enum): + WASMTIME_WASI_FILE_PERMS_READ = 1 + WASMTIME_WASI_FILE_PERMS_WRITE = 2 + +wasi_file_perms = c_size_t + _wasi_config_preopen_dir = dll.wasi_config_preopen_dir _wasi_config_preopen_dir.restype = c_bool -_wasi_config_preopen_dir.argtypes = [POINTER(wasi_config_t), POINTER(c_char), POINTER(c_char)] -def wasi_config_preopen_dir(config: Any, path: Any, guest_path: Any) -> bool: - return _wasi_config_preopen_dir(config, path, guest_path) # type: ignore +_wasi_config_preopen_dir.argtypes = [POINTER(wasi_config_t), POINTER(c_char), POINTER(c_char), wasi_dir_perms, wasi_file_perms] +def wasi_config_preopen_dir(config: Any, host_path: Any, guest_path: Any, dir_perms: Any, file_perms: Any) -> bool: + return _wasi_config_preopen_dir(config, host_path, guest_path, dir_perms, file_perms) # type: ignore class wasmtime_error(Structure): pass @@ -1996,10 +2027,25 @@ def wasmtime_error_wasm_trace(arg0: Any, out: Any) -> None: wasmtime_strategy_t = c_uint8 +class wasmtime_strategy_enum(Enum): + WASMTIME_STRATEGY_AUTO = auto() + WASMTIME_STRATEGY_CRANELIFT = auto() + wasmtime_opt_level_t = c_uint8 +class wasmtime_opt_level_enum(Enum): + WASMTIME_OPT_LEVEL_NONE = auto() + WASMTIME_OPT_LEVEL_SPEED = auto() + WASMTIME_OPT_LEVEL_SPEED_AND_SIZE = auto() + wasmtime_profiling_strategy_t = c_uint8 +class wasmtime_profiling_strategy_enum(Enum): + WASMTIME_PROFILING_STRATEGY_NONE = auto() + WASMTIME_PROFILING_STRATEGY_JITDUMP = auto() + WASMTIME_PROFILING_STRATEGY_VTUNE = auto() + WASMTIME_PROFILING_STRATEGY_PERFMAP = auto() + _wasmtime_config_debug_info_set = dll.wasmtime_config_debug_info_set _wasmtime_config_debug_info_set.restype = None _wasmtime_config_debug_info_set.argtypes = [POINTER(wasm_config_t), c_bool] @@ -2096,6 +2142,12 @@ def wasmtime_config_wasm_multi_memory_set(arg0: Any, arg1: Any) -> None: def wasmtime_config_wasm_memory64_set(arg0: Any, arg1: Any) -> None: return _wasmtime_config_wasm_memory64_set(arg0, arg1) # type: ignore +_wasmtime_config_wasm_wide_arithmetic_set = dll.wasmtime_config_wasm_wide_arithmetic_set +_wasmtime_config_wasm_wide_arithmetic_set.restype = None +_wasmtime_config_wasm_wide_arithmetic_set.argtypes = [POINTER(wasm_config_t), c_bool] +def wasmtime_config_wasm_wide_arithmetic_set(arg0: Any, arg1: Any) -> None: + return _wasmtime_config_wasm_wide_arithmetic_set(arg0, arg1) # type: ignore + _wasmtime_config_strategy_set = dll.wasmtime_config_strategy_set _wasmtime_config_strategy_set.restype = None _wasmtime_config_strategy_set.argtypes = [POINTER(wasm_config_t), wasmtime_strategy_t] @@ -2132,35 +2184,29 @@ def wasmtime_config_cranelift_opt_level_set(arg0: Any, arg1: Any) -> None: def wasmtime_config_profiler_set(arg0: Any, arg1: Any) -> None: return _wasmtime_config_profiler_set(arg0, arg1) # type: ignore -_wasmtime_config_static_memory_forced_set = dll.wasmtime_config_static_memory_forced_set -_wasmtime_config_static_memory_forced_set.restype = None -_wasmtime_config_static_memory_forced_set.argtypes = [POINTER(wasm_config_t), c_bool] -def wasmtime_config_static_memory_forced_set(arg0: Any, arg1: Any) -> None: - return _wasmtime_config_static_memory_forced_set(arg0, arg1) # type: ignore - -_wasmtime_config_static_memory_maximum_size_set = dll.wasmtime_config_static_memory_maximum_size_set -_wasmtime_config_static_memory_maximum_size_set.restype = None -_wasmtime_config_static_memory_maximum_size_set.argtypes = [POINTER(wasm_config_t), c_uint64] -def wasmtime_config_static_memory_maximum_size_set(arg0: Any, arg1: Any) -> None: - return _wasmtime_config_static_memory_maximum_size_set(arg0, arg1) # type: ignore - -_wasmtime_config_static_memory_guard_size_set = dll.wasmtime_config_static_memory_guard_size_set -_wasmtime_config_static_memory_guard_size_set.restype = None -_wasmtime_config_static_memory_guard_size_set.argtypes = [POINTER(wasm_config_t), c_uint64] -def wasmtime_config_static_memory_guard_size_set(arg0: Any, arg1: Any) -> None: - return _wasmtime_config_static_memory_guard_size_set(arg0, arg1) # type: ignore - -_wasmtime_config_dynamic_memory_guard_size_set = dll.wasmtime_config_dynamic_memory_guard_size_set -_wasmtime_config_dynamic_memory_guard_size_set.restype = None -_wasmtime_config_dynamic_memory_guard_size_set.argtypes = [POINTER(wasm_config_t), c_uint64] -def wasmtime_config_dynamic_memory_guard_size_set(arg0: Any, arg1: Any) -> None: - return _wasmtime_config_dynamic_memory_guard_size_set(arg0, arg1) # type: ignore - -_wasmtime_config_dynamic_memory_reserved_for_growth_set = dll.wasmtime_config_dynamic_memory_reserved_for_growth_set -_wasmtime_config_dynamic_memory_reserved_for_growth_set.restype = None -_wasmtime_config_dynamic_memory_reserved_for_growth_set.argtypes = [POINTER(wasm_config_t), c_uint64] -def wasmtime_config_dynamic_memory_reserved_for_growth_set(arg0: Any, arg1: Any) -> None: - return _wasmtime_config_dynamic_memory_reserved_for_growth_set(arg0, arg1) # type: ignore +_wasmtime_config_memory_may_move_set = dll.wasmtime_config_memory_may_move_set +_wasmtime_config_memory_may_move_set.restype = None +_wasmtime_config_memory_may_move_set.argtypes = [POINTER(wasm_config_t), c_bool] +def wasmtime_config_memory_may_move_set(arg0: Any, arg1: Any) -> None: + return _wasmtime_config_memory_may_move_set(arg0, arg1) # type: ignore + +_wasmtime_config_memory_reservation_set = dll.wasmtime_config_memory_reservation_set +_wasmtime_config_memory_reservation_set.restype = None +_wasmtime_config_memory_reservation_set.argtypes = [POINTER(wasm_config_t), c_uint64] +def wasmtime_config_memory_reservation_set(arg0: Any, arg1: Any) -> None: + return _wasmtime_config_memory_reservation_set(arg0, arg1) # type: ignore + +_wasmtime_config_memory_guard_size_set = dll.wasmtime_config_memory_guard_size_set +_wasmtime_config_memory_guard_size_set.restype = None +_wasmtime_config_memory_guard_size_set.argtypes = [POINTER(wasm_config_t), c_uint64] +def wasmtime_config_memory_guard_size_set(arg0: Any, arg1: Any) -> None: + return _wasmtime_config_memory_guard_size_set(arg0, arg1) # type: ignore + +_wasmtime_config_memory_reservation_for_growth_set = dll.wasmtime_config_memory_reservation_for_growth_set +_wasmtime_config_memory_reservation_for_growth_set.restype = None +_wasmtime_config_memory_reservation_for_growth_set.argtypes = [POINTER(wasm_config_t), c_uint64] +def wasmtime_config_memory_reservation_for_growth_set(arg0: Any, arg1: Any) -> None: + return _wasmtime_config_memory_reservation_for_growth_set(arg0, arg1) # type: ignore _wasmtime_config_native_unwind_info_set = dll.wasmtime_config_native_unwind_info_set _wasmtime_config_native_unwind_info_set.restype = None @@ -2937,9 +2983,9 @@ def wasmtime_linker_instantiate_pre(linker: Any, module: Any, instance_pre: Any) _wasmtime_memorytype_new = dll.wasmtime_memorytype_new _wasmtime_memorytype_new.restype = POINTER(wasm_memorytype_t) -_wasmtime_memorytype_new.argtypes = [c_uint64, c_bool, c_uint64, c_bool] -def wasmtime_memorytype_new(min: Any, max_present: Any, max: Any, is_64: Any) -> ctypes._Pointer: - return _wasmtime_memorytype_new(min, max_present, max, is_64) # type: ignore +_wasmtime_memorytype_new.argtypes = [c_uint64, c_bool, c_uint64, c_bool, c_bool] +def wasmtime_memorytype_new(min: Any, max_present: Any, max: Any, is_64: Any, shared: Any) -> ctypes._Pointer: + return _wasmtime_memorytype_new(min, max_present, max, is_64, shared) # type: ignore _wasmtime_memorytype_minimum = dll.wasmtime_memorytype_minimum _wasmtime_memorytype_minimum.restype = c_uint64 @@ -3054,30 +3100,44 @@ def wasmtime_table_type(store: Any, table: Any) -> ctypes._Pointer: _wasmtime_table_get = dll.wasmtime_table_get _wasmtime_table_get.restype = c_bool -_wasmtime_table_get.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t), c_uint32, POINTER(wasmtime_val_t)] +_wasmtime_table_get.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t), c_uint64, POINTER(wasmtime_val_t)] def wasmtime_table_get(store: Any, table: Any, index: Any, val: Any) -> bool: return _wasmtime_table_get(store, table, index, val) # type: ignore _wasmtime_table_set = dll.wasmtime_table_set _wasmtime_table_set.restype = POINTER(wasmtime_error_t) -_wasmtime_table_set.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t), c_uint32, POINTER(wasmtime_val_t)] +_wasmtime_table_set.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t), c_uint64, POINTER(wasmtime_val_t)] def wasmtime_table_set(store: Any, table: Any, index: Any, value: Any) -> ctypes._Pointer: return _wasmtime_table_set(store, table, index, value) # type: ignore _wasmtime_table_size = dll.wasmtime_table_size -_wasmtime_table_size.restype = c_uint32 +_wasmtime_table_size.restype = c_uint64 _wasmtime_table_size.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t)] def wasmtime_table_size(store: Any, table: Any) -> int: return _wasmtime_table_size(store, table) # type: ignore _wasmtime_table_grow = dll.wasmtime_table_grow _wasmtime_table_grow.restype = POINTER(wasmtime_error_t) -_wasmtime_table_grow.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t), c_uint32, POINTER(wasmtime_val_t), POINTER(c_uint32)] +_wasmtime_table_grow.argtypes = [POINTER(wasmtime_context_t), POINTER(wasmtime_table_t), c_uint64, POINTER(wasmtime_val_t), POINTER(c_uint64)] def wasmtime_table_grow(store: Any, table: Any, delta: Any, init: Any, prev_size: Any) -> ctypes._Pointer: return _wasmtime_table_grow(store, table, delta, init, prev_size) # type: ignore wasmtime_trap_code_t = c_uint8 +class wasmtime_trap_code_enum(Enum): + WASMTIME_TRAP_CODE_STACK_OVERFLOW = auto() + WASMTIME_TRAP_CODE_MEMORY_OUT_OF_BOUNDS = auto() + WASMTIME_TRAP_CODE_HEAP_MISALIGNED = auto() + WASMTIME_TRAP_CODE_TABLE_OUT_OF_BOUNDS = auto() + WASMTIME_TRAP_CODE_INDIRECT_CALL_TO_NULL = auto() + WASMTIME_TRAP_CODE_BAD_SIGNATURE = auto() + WASMTIME_TRAP_CODE_INTEGER_OVERFLOW = auto() + WASMTIME_TRAP_CODE_INTEGER_DIVISION_BY_ZERO = auto() + WASMTIME_TRAP_CODE_BAD_CONVERSION_TO_INTEGER = auto() + WASMTIME_TRAP_CODE_UNREACHABLE_CODE_REACHED = auto() + WASMTIME_TRAP_CODE_INTERRUPT = auto() + WASMTIME_TRAP_CODE_OUT_OF_FUEL = auto() + _wasmtime_trap_new = dll.wasmtime_trap_new _wasmtime_trap_new.restype = POINTER(wasm_trap_t) _wasmtime_trap_new.argtypes = [POINTER(c_char), c_size_t] diff --git a/wasmtime/_table.py b/wasmtime/_table.py index 676b1bc0..89ce5ec0 100644 --- a/wasmtime/_table.py +++ b/wasmtime/_table.py @@ -51,8 +51,8 @@ def grow(self, store: Storelike, amt: int, init: Any) -> int: Returns the previous size of the table otherwise. """ init_val = Val._convert_to_raw(store, self.type(store).element, init) - prev = c_uint32(0) - error = ffi.wasmtime_table_grow(store._context(), byref(self._table), c_uint32(amt), byref(init_val), byref(prev)) + prev = c_uint64(0) + error = ffi.wasmtime_table_grow(store._context(), byref(self._table), c_uint64(amt), byref(init_val), byref(prev)) ffi.wasmtime_val_unroot(store._context(), byref(init_val)) if error: raise WasmtimeError._from_ptr(error) diff --git a/wasmtime/_types.py b/wasmtime/_types.py index ca96bb4f..a4807bf6 100644 --- a/wasmtime/_types.py +++ b/wasmtime/_types.py @@ -1,8 +1,10 @@ -from . import _ffi as ffi -from wasmtime import WasmtimeError, Managed import ctypes -from ctypes import byref, POINTER -from typing import Union, List, Optional, Any +from ctypes import POINTER, byref +from typing import Any, List, Optional, Union + +from wasmtime import Managed, WasmtimeError + +from . import _ffi as ffi class ValType(Managed["ctypes._Pointer[ffi.wasm_valtype_t]"]): @@ -282,7 +284,7 @@ def _as_extern(self) -> "ctypes._Pointer[ffi.wasm_externtype_t]": class MemoryType(Managed["ctypes._Pointer[ffi.wasm_memorytype_t]"]): - def __init__(self, limits: Limits, is_64: bool = False): + def __init__(self, limits: Limits, is_64: bool = False, shared: bool = False): if not isinstance(limits, Limits): raise TypeError("expected Limits") if is_64: @@ -296,7 +298,8 @@ def __init__(self, limits: Limits, is_64: bool = False): ptr = ffi.wasmtime_memorytype_new(limits.min, limits.max is not None, limits.max if limits.max else 0, - is_64) + is_64, + shared) if not ptr: raise WasmtimeError("failed to allocate MemoryType") self._set_ptr(ptr) diff --git a/wasmtime/_wasi.py b/wasmtime/_wasi.py index 8b2461a1..1718cae7 100644 --- a/wasmtime/_wasi.py +++ b/wasmtime/_wasi.py @@ -1,10 +1,13 @@ -from ctypes import c_char, POINTER, cast, c_char_p, c_int import ctypes -from wasmtime import WasmtimeError, Managed +from ctypes import POINTER, c_char, c_char_p, cast +from enum import Enum +from os import PathLike +from typing import Iterable, List, Union + +from wasmtime import Managed, WasmtimeError + from . import _ffi as ffi from ._config import setter_property -from typing import List, Iterable, Union -from os import PathLike def _encode_path(path: Union[str, bytes, PathLike]) -> bytes: @@ -16,6 +19,15 @@ def _encode_path(path: Union[str, bytes, PathLike]) -> bytes: return path2 return path2.encode('utf8') +class DirPerms(Enum): + READ_ONLY = ffi.wasi_dir_perms_flags.WASMTIME_WASI_DIR_PERMS_READ.value + WRITE_ONLY = ffi.wasi_dir_perms_flags.WASMTIME_WASI_DIR_PERMS_WRITE.value + READ_WRITE = ffi.wasi_dir_perms_flags.WASMTIME_WASI_DIR_PERMS_READ.value | ffi.wasi_dir_perms_flags.WASMTIME_WASI_DIR_PERMS_WRITE.value + +class FilePerms(Enum): + READ_ONLY = ffi.wasi_file_perms_flags.WASMTIME_WASI_FILE_PERMS_READ.value + WRITE_ONLY = ffi.wasi_file_perms_flags.WASMTIME_WASI_FILE_PERMS_WRITE.value + READ_WRITE = ffi.wasi_file_perms_flags.WASMTIME_WASI_FILE_PERMS_READ.value | ffi.wasi_file_perms_flags.WASMTIME_WASI_FILE_PERMS_WRITE.value class WasiConfig(Managed["ctypes._Pointer[ffi.wasi_config_t]"]): @@ -142,10 +154,21 @@ def inherit_stderr(self) -> None: """ ffi.wasi_config_inherit_stderr(self.ptr()) - def preopen_dir(self, path: str, guest_path: str) -> None: + def preopen_dir(self, path: str, guest_path: str, dir_perms: DirPerms, file_perms: FilePerms) -> None: + """ + Allows the WASI program to access the directory at `path` using the + path `guest_path` within the WASI program. + + `dir_perms` specifies the permissions that wasm will have to operate on + `guest_path`. This can be used, for example, to provide readonly access to a + directory. + + `file_perms` specifies the maximum set of permissions that can be used for + any file in this directory. + """ path_ptr = c_char_p(path.encode('utf-8')) guest_path_ptr = c_char_p(guest_path.encode('utf-8')) - if not ffi.wasi_config_preopen_dir(self.ptr(), path_ptr, guest_path_ptr): + if not ffi.wasi_config_preopen_dir(self.ptr(), path_ptr, guest_path_ptr, dir_perms.value, file_perms.value): raise WasmtimeError('failed to add preopen dir')