Skip to content

Commit 09218e1

Browse files
authored
Bump to 34.0.0 (#291)
Update some C header generation bits for the new component model APIs
1 parent 7d53651 commit 09218e1

File tree

10 files changed

+444
-95
lines changed

10 files changed

+444
-95
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
33.0.1
1+
34.0.0

ci/cbindgen.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self):
2222
self.ret += 'from typing import Any\n'
2323
self.ret += 'from enum import Enum, auto\n'
2424
self.ret += 'from ._ffi import dll, wasm_val_t, wasm_ref_t\n'
25+
self.forward_declared = {}
2526

2627
# Skip all function definitions, we don't bind those
2728
def visit_FuncDef(self, node):
@@ -36,35 +37,51 @@ def visit_Struct(self, node):
3637
return
3738

3839
self.ret += "\n"
39-
self.ret += "class {}(Structure):\n".format(node.name)
40-
if node.decls:
40+
if not node.decls:
41+
self.forward_declared[node.name] = True
42+
self.ret += "class {}(Structure):\n".format(node.name)
43+
self.ret += " pass\n"
44+
return
45+
46+
anon_decl = 0
47+
for decl in node.decls:
48+
if not decl.name:
49+
assert(isinstance(decl.type, c_ast.Struct))
50+
decl.type.name = node.name + '_anon_' + str(anon_decl)
51+
self.visit_Struct(decl.type)
52+
anon_decl += 1
53+
decl.name = '_anon_' + str(anon_decl)
54+
55+
if node.name in self.forward_declared:
56+
self.ret += "{}._fields = [ # type: ignore\n".format(node.name)
57+
else:
58+
self.ret += "class {}(Structure):\n".format(node.name)
4159
self.ret += " _fields_ = [\n"
42-
for decl in node.decls:
43-
self.ret += " (\"{}\", {}),\n".format(decl.name, type_name(decl.type))
44-
self.ret += " ]\n"
60+
61+
for decl in node.decls:
62+
self.ret += " (\"{}\", {}),\n".format(decl.name, type_name(decl.type))
63+
self.ret += " ]\n"
64+
65+
if not node.name in self.forward_declared:
4566
for decl in node.decls:
4667
self.ret += " {}: {}\n".format(decl.name, type_name(decl.type, typing=True))
47-
else:
48-
self.ret += " pass\n"
4968

5069
def visit_Union(self, node):
5170
if not node.name or not node.name.startswith('was'):
5271
return
72+
assert(node.decls)
5373

5474
self.ret += "\n"
5575
self.ret += "class {}(Union):\n".format(node.name)
56-
if node.decls:
57-
self.ret += " _fields_ = [\n"
58-
for decl in node.decls:
59-
self.ret += " (\"{}\", {}),\n".format(name(decl.name), type_name(decl.type))
60-
self.ret += " ]\n"
61-
for decl in node.decls:
62-
self.ret += " {}: {}".format(name(decl.name), type_name(decl.type, typing=True))
63-
if decl.name == 'v128':
64-
self.ret += ' # type: ignore'
65-
self.ret += "\n"
66-
else:
67-
self.ret += " pass\n"
76+
self.ret += " _fields_ = [\n"
77+
for decl in node.decls:
78+
self.ret += " (\"{}\", {}),\n".format(name(decl.name), type_name(decl.type))
79+
self.ret += " ]\n"
80+
for decl in node.decls:
81+
self.ret += " {}: {}".format(name(decl.name), type_name(decl.type, typing=True))
82+
if decl.name == 'v128':
83+
self.ret += ' # type: ignore'
84+
self.ret += "\n"
6885

6986
def visit_Enum(self, node):
7087
if not node.name or not node.name.startswith('was'):
@@ -85,7 +102,8 @@ def visit_Typedef(self, node):
85102

86103
# Given anonymous structs in typedefs names by default.
87104
if isinstance(node.type, c_ast.TypeDecl):
88-
if isinstance(node.type.type, c_ast.Struct):
105+
if isinstance(node.type.type, c_ast.Struct) or \
106+
isinstance(node.type.type, c_ast.Union):
89107
if node.type.type.name is None:
90108
if node.name.endswith('_t'):
91109
node.type.type.name = node.name[:-2]
@@ -178,8 +196,14 @@ def type_name(ty, ptr=False, typing=False):
178196
return "bool" if typing else "c_bool"
179197
elif ty.names[0] == "byte_t":
180198
return "c_ubyte"
199+
elif ty.names[0] == "int8_t":
200+
return "c_int8"
181201
elif ty.names[0] == "uint8_t":
182202
return "c_uint8"
203+
elif ty.names[0] == "int16_t":
204+
return "c_int16"
205+
elif ty.names[0] == "uint16_t":
206+
return "c_uint16"
183207
elif ty.names[0] == "int32_t":
184208
return "int" if typing else "c_int32"
185209
elif ty.names[0] == "uint32_t":
@@ -218,7 +242,7 @@ def type_name(ty, ptr=False, typing=False):
218242
tys.append("c_size_t")
219243
else:
220244
tys.append(type_name(ty.type))
221-
if ty.args.params:
245+
if ty.args and ty.args.params:
222246
for param in ty.args.params:
223247
tys.append(type_name(param.type))
224248
return "CFUNCTYPE({})".format(', '.join(tys))

ci/download-wasmtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# set to "dev" to download the latest or pick a tag from
1414
# https://github.com/bytecodealliance/wasmtime/tags
15-
WASMTIME_VERSION = "v33.0.0"
15+
WASMTIME_VERSION = "v34.0.0"
1616

1717

1818
def main(platform, arch):

rust/Cargo.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ heck = { version = "0.4", features = ["unicode"] }
1212
wit-parser = "0.230.0"
1313
wit-component = "0.230.0"
1414
indexmap = "2.0"
15-
wasmtime-environ = { version = "33.0.0", features = ['component-model', 'compile'] }
15+
wasmtime-environ = { version = "34.0.0", features = ['component-model', 'compile'] }
1616
wit-bindgen = "0.42.1"
1717
wit-bindgen-core = "0.42.1"
1818

tests/codegen/test_external_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
(instance
99
(type $runtime-value (variant
1010
(case "id" string) (case "id2" string)))
11-
(export $runtime-value-export "runtime-value"
12-
(type (eq $runtime-value)))
11+
(export "runtime-value"
12+
(type $runtime-value-export (eq $runtime-value)))
1313
)
1414
)
1515
(import "types" (instance $types (type $types)))
1616
(alias export $types "runtime-value" (type $runtime-value-export))
1717
1818
(import "host" (instance $inst
1919
(alias outer $OuterComp 1 (type $runtime-value))
20-
(export $export "runtime-value" (type (eq $runtime-value)))
20+
(export "runtime-value" (type $export (eq $runtime-value)))
2121
(export "some-fn" (func (param "v" $export) (result $export)))
2222
))
2323

tests/codegen/test_keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
(component
66
(import "false" (instance $i
77
(type $c1 (variant (case "break" s32) (case "class" s64) (case "true" s64)))
8-
(export $c1' "none" (type (eq $c1)))
8+
(export "none" (type $c1' (eq $c1)))
99
(export "as" (func (param "import" $c1') (result s64)))
1010
1111
(type $r1 (record (field "else" u8) (field "not" u8) (field "except" u8)))
12-
(export $r1' "true" (type (eq $r1)))
12+
(export "true" (type $r1' (eq $r1)))
1313
(export "lambda" (func (param "def" $r1') (result u32)))
1414
))
1515

tests/codegen/test_records.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
(export "multiple-results" (func (result (tuple u8 u16))))
2626
(export "swap" (func (param "a" $tuple) (result $tuple)))
2727
28-
(export $f1 "flag1" (type (eq $flag1)))
29-
(export $f2 "flag2" (type (eq $flag2)))
30-
(export $f8 "flag8" (type (eq $flag8)))
31-
(export $f16 "flag16" (type (eq $flag16)))
32-
(export $f32 "flag32" (type (eq $flag32)))
28+
(export "flag1" (type $f1 (eq $flag1)))
29+
(export "flag2" (type $f2 (eq $flag2)))
30+
(export "flag8" (type $f8 (eq $flag8)))
31+
(export "flag16" (type $f16 (eq $flag16)))
32+
(export "flag32" (type $f32 (eq $flag32)))
3333
3434
(export "roundtrip-flag1" (func (param "a" $f1) (result $f1)))
3535
(export "roundtrip-flag2" (func (param "a" $f2) (result $f2)))
@@ -38,7 +38,7 @@
3838
(export "roundtrip-flag32" (func (param "a" $f32) (result $f32)))
3939
4040
(type $r1 (record (field "a" u8) (field "b" $f1)))
41-
(export $r1' "r1" (type (eq $r1)))
41+
(export "r1" (type $r1' (eq $r1)))
4242
(export "roundtrip-r1" (func (param "a" $r1') (result $r1')))
4343
))
4444

tests/codegen/test_variants.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(case "c3" s32)
3838
))
3939
(type $distinguished (variant (case "s32" s32) (case "float32" float32)))
40-
(export $distinguished' "distinguished" (type (eq $distinguished)))
40+
(export "distinguished" (type $distinguished' (eq $distinguished)))
4141
4242
(type $nested-union (variant
4343
(case "d" $distinguished')
@@ -46,29 +46,29 @@
4646
))
4747
(type $option-in-union (variant (case "o" (option s32)) (case "i" s32)))
4848
49-
(export $e1' "e1" (type (eq $e1)))
49+
(export "e1" (type $e1' (eq $e1)))
5050
51-
(export $c1' "c1" (type (eq $c1)))
52-
(export $c2' "c2" (type (eq $c2)))
53-
(export $c3' "c3" (type (eq $c3)))
54-
(export $c4' "c4" (type (eq $c4)))
55-
(export $c5' "c5" (type (eq $c5)))
56-
(export $c6' "c6" (type (eq $c6)))
51+
(export "c1" (type $c1' (eq $c1)))
52+
(export "c2" (type $c2' (eq $c2)))
53+
(export "c3" (type $c3' (eq $c3)))
54+
(export "c4" (type $c4' (eq $c4)))
55+
(export "c5" (type $c5' (eq $c5)))
56+
(export "c6" (type $c6' (eq $c6)))
5757
(type $casts (tuple $c1' $c2' $c3' $c4' $c5' $c6'))
58-
(export $casts' "casts" (type (eq $casts)))
58+
(export "casts" (type $casts' (eq $casts)))
5959
60-
(export $z1' "z1" (type (eq $z1)))
61-
(export $z2' "z2" (type (eq $z2)))
62-
(export $z3' "z3" (type (eq $z3)))
63-
(export $z4' "z4" (type (eq $z4)))
60+
(export "z1" (type $z1' (eq $z1)))
61+
(export "z2" (type $z2' (eq $z2)))
62+
(export "z3" (type $z3' (eq $z3)))
63+
(export "z4" (type $z4' (eq $z4)))
6464
(type $zeros (tuple $z1' $z2' $z3' $z4'))
65-
(export $zeros' "zeros" (type (eq $zeros)))
65+
(export "zeros" (type $zeros' (eq $zeros)))
6666
67-
(export $all-integers' "all-integers" (type (eq $all-integers)))
68-
(export $all-floats' "all-floats" (type (eq $all-floats)))
69-
(export $duplicated-s32' "duplicated-s32" (type (eq $duplicated-s32)))
70-
(export $nested-union' "nested-union" (type (eq $nested-union)))
71-
(export $option-in-union' "option-in-union" (type (eq $option-in-union)))
67+
(export "all-integers" (type $all-integers' (eq $all-integers)))
68+
(export "all-floats" (type $all-floats' (eq $all-floats)))
69+
(export "duplicated-s32" (type $duplicated-s32' (eq $duplicated-s32)))
70+
(export "nested-union" (type $nested-union' (eq $nested-union)))
71+
(export "option-in-union" (type $option-in-union' (eq $option-in-union)))
7272
7373
(export "roundtrip-option" (func (param "a" (option float32)) (result (option u8))))
7474
(export "roundtrip-result" (func

0 commit comments

Comments
 (0)