Skip to content

Commit 4a0fdec

Browse files
author
Guy Bedford
authored
component: update to latest bindgen (#395)
1 parent f8ef046 commit 4a0fdec

File tree

7 files changed

+673
-713
lines changed

7 files changed

+673
-713
lines changed
Binary file not shown.

c-dependencies/js-compute-runtime/xqd-world/xqd_world.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ bool fastly_http_req_cache_override_set(fastly_request_handle_t h,
744744
fastly_http_cache_override_tag_t tag, uint32_t *maybe_ttl,
745745
uint32_t *maybe_stale_while_revalidate,
746746
xqd_world_string_t *maybe_sk, fastly_error_t *err) {
747+
__attribute__((aligned(1))) uint8_t ret_area[2];
747748
fastly_option_u32_t ttl;
748749
ttl.is_some = maybe_ttl != NULL;
749750
if (maybe_ttl) {
@@ -792,7 +793,6 @@ bool fastly_http_req_cache_override_set(fastly_request_handle_t h,
792793
option9 = 0;
793794
option10 = 0;
794795
}
795-
__attribute__((aligned(1))) uint8_t ret_area[2];
796796
int32_t ptr = (int32_t)&ret_area;
797797
__wasm_import_fastly_http_req_cache_override_set((int32_t)(h), tag, option, option1, option4,
798798
option5, option8, option9, option10, ptr);
@@ -1901,29 +1901,25 @@ bool fastly_http_req_register_dynamic_backend(xqd_world_string_t *prefix,
19011901
} else {
19021902
*((int8_t *)(ptr + 96)) = 0;
19031903
}
1904-
// Bug: https://github.com/bytecodealliance/wit-bindgen/pull/444
1905-
{
1906-
__attribute__((aligned(1))) uint8_t ret_area[2];
1907-
int32_t ptr21 = (int32_t)&ret_area;
1908-
__wasm_import_fastly_http_req_register_dynamic_backend(ptr, ptr21);
1909-
fastly_result_void_error_t result;
1910-
switch ((int32_t)(*((uint8_t *)(ptr21 + 0)))) {
1911-
case 0: {
1912-
result.is_err = false;
1913-
break;
1914-
}
1915-
case 1: {
1916-
result.is_err = true;
1917-
result.val.err = (int32_t)(*((uint8_t *)(ptr21 + 1)));
1918-
break;
1919-
}
1920-
}
1921-
if (!result.is_err) {
1922-
return 1;
1923-
} else {
1924-
*err = result.val.err;
1925-
return 0;
1926-
}
1904+
int32_t ptr21 = (int32_t)&ret_area;
1905+
__wasm_import_fastly_http_req_register_dynamic_backend(ptr, ptr21);
1906+
fastly_result_void_error_t result;
1907+
switch ((int32_t)(*((uint8_t *)(ptr21 + 0)))) {
1908+
case 0: {
1909+
result.is_err = false;
1910+
break;
1911+
}
1912+
case 1: {
1913+
result.is_err = true;
1914+
result.val.err = (int32_t)(*((uint8_t *)(ptr21 + 1)));
1915+
break;
1916+
}
1917+
}
1918+
if (!result.is_err) {
1919+
return 1;
1920+
} else {
1921+
*err = result.val.err;
1922+
return 0;
19271923
}
19281924
}
19291925

c-dependencies/js-compute-runtime/xqd-world/xqd_world.h

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,37 @@ typedef struct {
1414
size_t len;
1515
} xqd_world_string_t;
1616

17-
typedef uint8_t fastly_error_t;
18-
19-
#define FASTLY_ERROR_UNKNOWN_ERROR 0
20-
#define FASTLY_ERROR_GENERIC_ERROR 1
21-
#define FASTLY_ERROR_INVALID_ARGUMENT 2
22-
#define FASTLY_ERROR_BAD_HANDLE 3
23-
#define FASTLY_ERROR_BUFFER_LEN 4
24-
#define FASTLY_ERROR_UNSUPPORTED 5
25-
#define FASTLY_ERROR_BAD_ALIGN 6
26-
#define FASTLY_ERROR_HTTP_INVALID 7
27-
#define FASTLY_ERROR_HTTP_USER 8
28-
#define FASTLY_ERROR_HTTP_INCOMPLETE 9
29-
#define FASTLY_ERROR_OPTIONAL_NONE 10
30-
#define FASTLY_ERROR_HTTP_HEAD_TOO_LARGE 11
31-
#define FASTLY_ERROR_HTTP_INVALID_STATUS 12
32-
#define FASTLY_ERROR_LIMIT_EXCEEDED 13
33-
3417
typedef struct {
3518
xqd_world_string_t family;
3619
xqd_world_string_t major;
3720
xqd_world_string_t minor;
3821
xqd_world_string_t patch;
3922
} fastly_user_agent_t;
4023

41-
typedef uint32_t fastly_body_handle_t;
42-
43-
typedef uint8_t fastly_body_write_end_t;
44-
45-
#define FASTLY_BODY_WRITE_END_BACK 0
46-
#define FASTLY_BODY_WRITE_END_FRONT 1
24+
typedef uint8_t fastly_tls_version_t;
4725

48-
typedef uint32_t fastly_log_endpoint_handle_t;
26+
#define FASTLY_TLS_VERSION_TLS1 0
27+
#define FASTLY_TLS_VERSION_TLS11 1
28+
#define FASTLY_TLS_VERSION_TLS12 2
29+
#define FASTLY_TLS_VERSION_TLS13 3
4930

50-
typedef uint32_t fastly_request_handle_t;
31+
typedef uint32_t fastly_secret_store_handle_t;
5132

52-
typedef uint32_t fastly_pending_request_handle_t;
33+
typedef uint32_t fastly_secret_handle_t;
5334

5435
typedef uint32_t fastly_response_handle_t;
5536

56-
typedef struct {
57-
fastly_request_handle_t f0;
58-
fastly_body_handle_t f1;
59-
} fastly_request_t;
37+
typedef uint32_t fastly_request_handle_t;
6038

6139
typedef struct {
62-
fastly_response_handle_t f0;
63-
fastly_body_handle_t f1;
64-
} fastly_response_t;
40+
xqd_world_string_t id;
41+
} fastly_purge_result_t;
6542

66-
typedef uint8_t fastly_http_cache_override_tag_t;
43+
typedef uint32_t fastly_pending_request_handle_t;
6744

68-
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_PASS (1 << 0)
69-
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_TTL (1 << 1)
70-
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_STALE_WHILE_REVALIDATE (1 << 2)
71-
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_PCI (1 << 3)
45+
typedef uint32_t fastly_object_store_handle_t;
46+
47+
typedef uint32_t fastly_log_endpoint_handle_t;
7248

7349
typedef uint8_t fastly_http_version_t;
7450

@@ -78,22 +54,14 @@ typedef uint8_t fastly_http_version_t;
7854
#define FASTLY_HTTP_VERSION_H2 3
7955
#define FASTLY_HTTP_VERSION_H3 4
8056

81-
typedef uint8_t fastly_content_encodings_t;
82-
83-
#define FASTLY_CONTENT_ENCODINGS_GZIP 0
84-
// Adjust how this requests's framing headers are determined.
85-
86-
typedef uint8_t fastly_framing_headers_mode_t;
87-
88-
#define FASTLY_FRAMING_HEADERS_MODE_AUTOMATIC 0
89-
#define FASTLY_FRAMING_HEADERS_MODE_MANUALLY_FROM_HEADERS 1
57+
typedef uint16_t fastly_http_status_t;
9058

91-
typedef uint8_t fastly_tls_version_t;
59+
typedef uint8_t fastly_http_cache_override_tag_t;
9260

93-
#define FASTLY_TLS_VERSION_TLS1 0
94-
#define FASTLY_TLS_VERSION_TLS11 1
95-
#define FASTLY_TLS_VERSION_TLS12 2
96-
#define FASTLY_TLS_VERSION_TLS13 3
61+
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_PASS (1 << 0)
62+
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_TTL (1 << 1)
63+
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_STALE_WHILE_REVALIDATE (1 << 2)
64+
#define FASTLY_HTTP_CACHE_OVERRIDE_TAG_PCI (1 << 3)
9765

9866
typedef struct {
9967
bool is_some;
@@ -105,35 +73,6 @@ typedef struct {
10573
uint32_t val;
10674
} fastly_option_u32_t;
10775

108-
typedef struct {
109-
bool is_some;
110-
bool val;
111-
} fastly_option_bool_t;
112-
113-
typedef struct {
114-
bool is_some;
115-
fastly_tls_version_t val;
116-
} fastly_option_tls_version_t;
117-
// Create a backend for later use
118-
119-
typedef struct {
120-
fastly_option_string_t host_override;
121-
fastly_option_u32_t connect_timeout;
122-
fastly_option_u32_t first_byte_timeout;
123-
fastly_option_u32_t between_bytes_timeout;
124-
fastly_option_bool_t use_ssl;
125-
fastly_option_tls_version_t ssl_min_version;
126-
fastly_option_tls_version_t ssl_max_version;
127-
fastly_option_string_t cert_hostname;
128-
fastly_option_string_t ca_cert;
129-
fastly_option_string_t ciphers;
130-
fastly_option_string_t sni_hostname;
131-
} fastly_dynamic_backend_config_t;
132-
133-
typedef uint16_t fastly_http_status_t;
134-
135-
typedef uint32_t fastly_dictionary_handle_t;
136-
13776
typedef struct {
13877
bool is_some;
13978
float val;
@@ -161,13 +100,79 @@ typedef struct {
161100
fastly_option_u32_t utc_offset;
162101
} fastly_geo_data_t;
163102

103+
// Adjust how this requests's framing headers are determined.
104+
typedef uint8_t fastly_framing_headers_mode_t;
105+
106+
#define FASTLY_FRAMING_HEADERS_MODE_AUTOMATIC 0
107+
#define FASTLY_FRAMING_HEADERS_MODE_MANUALLY_FROM_HEADERS 1
108+
164109
typedef uint32_t fastly_fd_t;
165110

166-
typedef uint32_t fastly_object_store_handle_t;
111+
typedef uint8_t fastly_error_t;
167112

168-
typedef uint32_t fastly_secret_store_handle_t;
113+
#define FASTLY_ERROR_UNKNOWN_ERROR 0
114+
#define FASTLY_ERROR_GENERIC_ERROR 1
115+
#define FASTLY_ERROR_INVALID_ARGUMENT 2
116+
#define FASTLY_ERROR_BAD_HANDLE 3
117+
#define FASTLY_ERROR_BUFFER_LEN 4
118+
#define FASTLY_ERROR_UNSUPPORTED 5
119+
#define FASTLY_ERROR_BAD_ALIGN 6
120+
#define FASTLY_ERROR_HTTP_INVALID 7
121+
#define FASTLY_ERROR_HTTP_USER 8
122+
#define FASTLY_ERROR_HTTP_INCOMPLETE 9
123+
#define FASTLY_ERROR_OPTIONAL_NONE 10
124+
#define FASTLY_ERROR_HTTP_HEAD_TOO_LARGE 11
125+
#define FASTLY_ERROR_HTTP_INVALID_STATUS 12
126+
#define FASTLY_ERROR_LIMIT_EXCEEDED 13
127+
128+
typedef struct {
129+
bool is_some;
130+
bool val;
131+
} fastly_option_bool_t;
132+
133+
typedef struct {
134+
bool is_some;
135+
fastly_tls_version_t val;
136+
} fastly_option_tls_version_t;
137+
138+
// Create a backend for later use
139+
typedef struct {
140+
fastly_option_string_t host_override;
141+
fastly_option_u32_t connect_timeout;
142+
fastly_option_u32_t first_byte_timeout;
143+
fastly_option_u32_t between_bytes_timeout;
144+
fastly_option_bool_t use_ssl;
145+
fastly_option_tls_version_t ssl_min_version;
146+
fastly_option_tls_version_t ssl_max_version;
147+
fastly_option_string_t cert_hostname;
148+
fastly_option_string_t ca_cert;
149+
fastly_option_string_t ciphers;
150+
fastly_option_string_t sni_hostname;
151+
} fastly_dynamic_backend_config_t;
152+
153+
typedef uint32_t fastly_dictionary_handle_t;
154+
155+
typedef uint8_t fastly_content_encodings_t;
156+
157+
#define FASTLY_CONTENT_ENCODINGS_GZIP 0
158+
159+
typedef uint8_t fastly_body_write_end_t;
160+
161+
#define FASTLY_BODY_WRITE_END_BACK 0
162+
#define FASTLY_BODY_WRITE_END_FRONT 1
163+
164+
typedef uint32_t fastly_body_handle_t;
165+
166+
typedef struct {
167+
fastly_response_handle_t f0;
168+
fastly_body_handle_t f1;
169+
} fastly_response_t;
170+
171+
typedef struct {
172+
fastly_request_handle_t f0;
173+
fastly_body_handle_t f1;
174+
} fastly_request_t;
169175

170-
typedef uint32_t fastly_secret_handle_t;
171176
// A handle to an object supporting generic async operations.
172177
// Can be either a `BodyHandle` or a `PendingRequestHandle`.
173178
//
@@ -179,13 +184,8 @@ typedef uint32_t fastly_secret_handle_t;
179184
//
180185
// For writing bytes, note that there is a large host-side buffer that bytes can eagerly be written
181186
// into, even before the origin itself consumes that data.
182-
183187
typedef uint32_t fastly_async_handle_t;
184188

185-
typedef struct {
186-
xqd_world_string_t id;
187-
} fastly_purge_result_t;
188-
189189
typedef struct {
190190
uint8_t *ptr;
191191
size_t len;

c-dependencies/js-compute-runtime/xqd.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
world xqd-world {
1+
default world xqd-world {
22
import fastly: interface {
33
// TODO: split this up into function-specific error enums
44
enum error {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"@jakechampion/wizer": "^1.6.0",
4646
"esbuild": "^0.15.16",
47-
"js-component-tools": "0.2.2",
47+
"js-component-tools": "0.3.0-beta.2",
4848
"tree-sitter": "^0.20.1",
4949
"tree-sitter-javascript": "^0.19.0"
5050
}

src/component.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { componentNew } from 'js-component-tools';
1+
import { componentEmbed, componentNew } from 'js-component-tools';
22
import { readFile, writeFile } from 'node:fs/promises';
33

44
export async function compileComponent (path) {
55
const coreComponent = await readFile(path);
66
const wit = await readFile(new URL('../xqd.wit', import.meta.url), 'utf8');
7-
const generatedComponent = await componentNew(coreComponent, {
8-
adapters: [['wasi_snapshot_preview1', await readFile(new URL('../wasi_snapshot_preview1.wasm', import.meta.url))]],
9-
wit
10-
});
7+
const coreComponentEmbedded = await componentEmbed(coreComponent, wit);
8+
const generatedComponent = await componentNew(coreComponentEmbedded, [['wasi_snapshot_preview1', await readFile(new URL('../wasi_snapshot_preview1.wasm', import.meta.url))]]);
119
await writeFile(path, generatedComponent);
1210
}

0 commit comments

Comments
 (0)