crossbind 2.0.0-beta.62 → 2.0.0-beta.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/AGENTS.md +2 -1
  2. package/README.md +2 -2
  3. package/package.json +7 -2
  4. package/src/actions/buildBinTools.js +0 -0
  5. package/src/actions/buildDependencies.js +15 -2
  6. package/src/actions/buildExternal.js +9 -1
  7. package/src/actions/buildJs.js +2 -9
  8. package/src/actions/buildLib.js +25 -8
  9. package/src/actions/buildNativeCommand.js +84 -0
  10. package/src/actions/buildNode.js +49 -10
  11. package/src/actions/buildTypes.js +8 -2
  12. package/src/actions/buildWasiCommand.js +10 -9
  13. package/src/actions/buildWasm.js +72 -31
  14. package/src/actions/cloudCommands.js +133 -0
  15. package/src/actions/createImportedBridges.js +71 -0
  16. package/src/actions/createInterface.js +247 -68
  17. package/src/actions/createLib.js +70 -42
  18. package/src/actions/getData.js +6 -2
  19. package/src/actions/getEnv.js +7 -0
  20. package/src/actions/getLinkInputs.js +12 -5
  21. package/src/actions/isSourceNewer.js +2 -0
  22. package/src/actions/licenses.js +143 -19
  23. package/src/actions/prepareConanDependencies.js +51 -0
  24. package/src/actions/publishBinary.js +32 -0
  25. package/src/actions/run.js +63 -66
  26. package/src/actions/runnerCommands.js +433 -0
  27. package/src/actions/writeRuntimeEntry.js +80 -0
  28. package/src/assets/cmake/command/CMakeLists.txt +21 -0
  29. package/src/assets/cmake/command/command.cpp +1 -0
  30. package/src/assets/cmake/dist.cmake +2 -1
  31. package/src/assets/configure/install.sh +22 -0
  32. package/src/assets/cpp-runtime/node.cpp +18 -1
  33. package/src/assets/js-runtime/adapters/path-url.js +6 -3
  34. package/src/assets/js-runtime/adapters/unboundMessage.js +2 -0
  35. package/src/assets/js-runtime/adapters/worker-comlink.js +138 -60
  36. package/src/assets/js-runtime/core.js +12 -0
  37. package/src/assets/node-import-hooks.mjs +61 -0
  38. package/src/assets/toolchain-digests.json +19 -19
  39. package/src/assets/wasi-runtime/http/README.md +17 -0
  40. package/src/assets/wasi-runtime/http/bindings/crossbind_http.c +2537 -0
  41. package/src/assets/wasi-runtime/http/bindings/crossbind_http.h +826 -0
  42. package/src/assets/wasi-runtime/http/bindings/crossbind_http_component_type.o +0 -0
  43. package/src/assets/wasi-runtime/http/handler.cpp +298 -0
  44. package/src/assets/wasi-runtime/http/include/crossbind/http.h +31 -0
  45. package/src/assets/wasi-runtime/http/wit/deps/LICENSE.md +8 -0
  46. package/src/assets/wasi-runtime/http/wit/deps/cli.wit +28 -0
  47. package/src/assets/wasi-runtime/http/wit/deps/clocks.wit +43 -0
  48. package/src/assets/wasi-runtime/http/wit/deps/http.wit +509 -0
  49. package/src/assets/wasi-runtime/http/wit/deps/random.wit +18 -0
  50. package/src/assets/wasi-runtime/http/wit/world.wit +6 -0
  51. package/src/assets/wasi-runtime/stubs.c +29 -0
  52. package/src/bin.js +218 -161
  53. package/src/cli.js +14 -0
  54. package/src/index.js +3 -0
  55. package/src/integration/bindHeaderImports.js +18 -0
  56. package/src/integration/getCrossbindScript.js +50 -13
  57. package/src/integration/getDependFilePath.js +9 -0
  58. package/src/integration/resolveNativeImport.js +14 -0
  59. package/src/node/dev.mjs +19 -0
  60. package/src/program.js +169 -0
  61. package/src/runner/blobs.js +135 -0
  62. package/src/runner/files.js +193 -0
  63. package/src/runner/server.js +320 -0
  64. package/src/state/attachConanDependencies.js +56 -0
  65. package/src/state/index.js +20 -11
  66. package/src/state/loadConfig.js +37 -35
  67. package/src/state/refreshBuiltDependencies.js +20 -0
  68. package/src/state/refreshConanDependencies.js +17 -0
  69. package/src/utils/androidToolchain.js +4 -0
  70. package/src/utils/appRustCrates.js +19 -1
  71. package/src/utils/appSources.js +97 -6
  72. package/src/utils/archiveFlags.js +12 -0
  73. package/src/utils/boundHeaders.js +79 -0
  74. package/src/utils/bridgeExtras.js +554 -0
  75. package/src/utils/bridgeRuntimeFixes.js +48 -0
  76. package/src/utils/bundledLicenses.js +26 -0
  77. package/src/utils/cargoLock.js +19 -0
  78. package/src/utils/cargoTarget.js +21 -3
  79. package/src/utils/cloudAccount.js +55 -0
  80. package/src/utils/conanDependencies.js +66 -0
  81. package/src/utils/conanImport.js +58 -0
  82. package/src/utils/conanInstall.js +154 -0
  83. package/src/utils/conanProfile.js +203 -0
  84. package/src/utils/conanStage.js +292 -0
  85. package/src/utils/copyToDistSource.js +13 -0
  86. package/src/utils/cppDts.js +60 -15
  87. package/src/utils/darwinToolchain.js +11 -0
  88. package/src/utils/dirLock.js +137 -28
  89. package/src/utils/downloadAndExtractFile.js +34 -7
  90. package/src/utils/embindArgumentGuards.js +41 -2
  91. package/src/utils/embindCallArguments.js +19 -0
  92. package/src/utils/embindJspiQueue.js +25 -0
  93. package/src/utils/embindObjectLifetime.js +35 -0
  94. package/src/utils/execContainer.js +49 -0
  95. package/src/utils/headerImports.js +16 -5
  96. package/src/utils/hostPlatform.js +21 -0
  97. package/src/utils/iosToolchain.js +6 -0
  98. package/src/utils/isSourceCmakePackage.js +10 -0
  99. package/src/utils/licenseReport.js +11 -2
  100. package/src/utils/linuxToolchain.js +24 -0
  101. package/src/utils/makeTreeWritable.js +12 -0
  102. package/src/utils/nativeImports.js +23 -0
  103. package/src/utils/nativeSourceStamp.js +36 -0
  104. package/src/utils/nodeDevBuild.js +92 -0
  105. package/src/utils/packageLicense.js +103 -0
  106. package/src/utils/pthreadMainScript.js +14 -0
  107. package/src/utils/pullDockerImage.js +3 -1
  108. package/src/utils/relocatePrebuilt.js +119 -0
  109. package/src/utils/remoteClient.js +127 -0
  110. package/src/utils/remoteOutputs.js +39 -0
  111. package/src/utils/remoteRunner.js +97 -0
  112. package/src/utils/remoteUpload.js +134 -0
  113. package/src/utils/replaceFile.js +8 -0
  114. package/src/utils/resetCMakeCacheForSource.js +26 -0
  115. package/src/utils/runCargo.js +48 -51
  116. package/src/utils/runConan.js +257 -0
  117. package/src/utils/runtimeEntries.js +56 -0
  118. package/src/utils/rustBridgeGen.js +22 -8
  119. package/src/utils/rustMt.js +9 -0
  120. package/src/utils/rustSysroot.js +7 -5
  121. package/src/utils/scopedEmbind.js +22 -0
  122. package/src/utils/selectRunner.js +81 -0
  123. package/src/utils/sourceFingerprint.js +4 -3
  124. package/src/utils/swigInterface.js +70 -4
  125. package/src/utils/systemConfig.js +13 -0
  126. package/src/utils/systemKeys.js +35 -3
  127. package/src/utils/targets.js +60 -4
  128. package/src/utils/toolchainNotices.js +5 -0
  129. package/src/utils/wasiHttp.js +50 -0
  130. package/src/utils/wasiToolchain.js +14 -1
  131. package/src/utils/windowsToolchain.js +18 -0
  132. package/vitest.config.js +11 -0
@@ -0,0 +1,509 @@
1
+ package wasi:http@0.3.0;
2
+
3
+ /// This interface defines all of the types and methods for implementing HTTP
4
+ /// Requests and Responses, as well as their headers, trailers, and bodies.
5
+ @since(version = 0.3.0)
6
+ interface types {
7
+ use wasi:clocks/types@0.3.0.{duration};
8
+
9
+ /// This type corresponds to HTTP standard Methods.
10
+ @since(version = 0.3.0)
11
+ variant method {
12
+ get,
13
+ head,
14
+ post,
15
+ put,
16
+ delete,
17
+ connect,
18
+ options,
19
+ trace,
20
+ patch,
21
+ other(string),
22
+ }
23
+
24
+ /// This type corresponds to HTTP standard Related Schemes.
25
+ @since(version = 0.3.0)
26
+ variant scheme {
27
+ HTTP,
28
+ HTTPS,
29
+ other(string),
30
+ }
31
+
32
+ /// Defines the case payload type for `DNS-error` above:
33
+ @since(version = 0.3.0)
34
+ record DNS-error-payload {
35
+ rcode: option<string>,
36
+ info-code: option<u16>,
37
+ }
38
+
39
+ /// Defines the case payload type for `TLS-alert-received` above:
40
+ @since(version = 0.3.0)
41
+ record TLS-alert-received-payload {
42
+ alert-id: option<u8>,
43
+ alert-message: option<string>,
44
+ }
45
+
46
+ /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
47
+ @since(version = 0.3.0)
48
+ record field-size-payload {
49
+ field-name: option<string>,
50
+ field-size: option<u32>,
51
+ }
52
+
53
+ /// These cases are inspired by the IANA HTTP Proxy Error Types:
54
+ /// <https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types>
55
+ @since(version = 0.3.0)
56
+ variant error-code {
57
+ DNS-timeout,
58
+ DNS-error(DNS-error-payload),
59
+ destination-not-found,
60
+ destination-unavailable,
61
+ destination-IP-prohibited,
62
+ destination-IP-unroutable,
63
+ connection-refused,
64
+ connection-terminated,
65
+ connection-timeout,
66
+ connection-read-timeout,
67
+ connection-write-timeout,
68
+ connection-limit-reached,
69
+ TLS-protocol-error,
70
+ TLS-certificate-error,
71
+ TLS-alert-received(TLS-alert-received-payload),
72
+ HTTP-request-denied,
73
+ HTTP-request-length-required,
74
+ HTTP-request-body-size(option<u64>),
75
+ HTTP-request-method-invalid,
76
+ HTTP-request-URI-invalid,
77
+ HTTP-request-URI-too-long,
78
+ HTTP-request-header-section-size(option<u32>),
79
+ HTTP-request-header-size(option<field-size-payload>),
80
+ HTTP-request-trailer-section-size(option<u32>),
81
+ HTTP-request-trailer-size(field-size-payload),
82
+ HTTP-response-incomplete,
83
+ HTTP-response-header-section-size(option<u32>),
84
+ HTTP-response-header-size(field-size-payload),
85
+ HTTP-response-body-size(option<u64>),
86
+ HTTP-response-trailer-section-size(option<u32>),
87
+ HTTP-response-trailer-size(field-size-payload),
88
+ HTTP-response-transfer-coding(option<string>),
89
+ HTTP-response-content-coding(option<string>),
90
+ HTTP-response-timeout,
91
+ HTTP-upgrade-failed,
92
+ HTTP-protocol-error,
93
+ loop-detected,
94
+ configuration-error,
95
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
96
+ /// more specific case. It also includes an optional string for an
97
+ /// unstructured description of the error. Users should not depend on the
98
+ /// string for diagnosing errors, as it's not required to be consistent
99
+ /// between implementations.
100
+ internal-error(option<string>),
101
+ }
102
+
103
+ /// This type enumerates the different kinds of errors that may occur when
104
+ /// setting or appending to a `fields` resource.
105
+ @since(version = 0.3.0)
106
+ variant header-error {
107
+ /// This error indicates that a `field-name` or `field-value` was
108
+ /// syntactically invalid when used with an operation that sets headers in a
109
+ /// `fields`.
110
+ invalid-syntax,
111
+ /// This error indicates that a forbidden `field-name` was used when trying
112
+ /// to set a header in a `fields`.
113
+ forbidden,
114
+ /// This error indicates that the operation on the `fields` was not
115
+ /// permitted because the fields are immutable.
116
+ immutable,
117
+ /// This error indicates that the operation would exceed an
118
+ /// implementation-defined limit on field sizes. This may apply to
119
+ /// an individual `field-value`, a single `field-name` plus all its
120
+ /// values, or the total aggregate size of all fields.
121
+ size-exceeded,
122
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
123
+ /// more specific case. Implementations can use this to extend the error
124
+ /// type without breaking existing code. It also includes an optional
125
+ /// string for an unstructured description of the error. Users should not
126
+ /// depend on the string for diagnosing errors, as it's not required to be
127
+ /// consistent between implementations.
128
+ other(option<string>),
129
+ }
130
+
131
+ /// This type enumerates the different kinds of errors that may occur when
132
+ /// setting fields of a `request-options` resource.
133
+ @since(version = 0.3.0)
134
+ variant request-options-error {
135
+ /// Indicates the specified field is not supported by this implementation.
136
+ not-supported,
137
+ /// Indicates that the operation on the `request-options` was not permitted
138
+ /// because it is immutable.
139
+ immutable,
140
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
141
+ /// more specific case. Implementations can use this to extend the error
142
+ /// type without breaking existing code. It also includes an optional
143
+ /// string for an unstructured description of the error. Users should not
144
+ /// depend on the string for diagnosing errors, as it's not required to be
145
+ /// consistent between implementations.
146
+ other(option<string>),
147
+ }
148
+
149
+ /// Field names are always strings.
150
+ ///
151
+ /// Field names should always be treated as case insensitive by the `fields`
152
+ /// resource for the purposes of equality checking.
153
+ @since(version = 0.3.0)
154
+ type field-name = string;
155
+
156
+ /// Field values should always be ASCII strings. However, in
157
+ /// reality, HTTP implementations often have to interpret malformed values,
158
+ /// so they are provided as a list of bytes.
159
+ @since(version = 0.3.0)
160
+ type field-value = list<u8>;
161
+
162
+ /// This following block defines the `fields` resource which corresponds to
163
+ /// HTTP standard Fields. Fields are a common representation used for both
164
+ /// Headers and Trailers.
165
+ ///
166
+ /// A `fields` may be mutable or immutable. A `fields` created using the
167
+ /// constructor, `from-list`, or `clone` will be mutable, but a `fields`
168
+ /// resource given by other means (including, but not limited to,
169
+ /// `request.headers`) might be be immutable. In an immutable fields, the
170
+ /// `set`, `append`, and `delete` operations will fail with
171
+ /// `header-error.immutable`.
172
+ ///
173
+ /// A `fields` resource should store `field-name`s and `field-value`s in their
174
+ /// original casing used to construct or mutate the `fields` resource. The `fields`
175
+ /// resource should use that original casing when serializing the fields for
176
+ /// transport or when returning them from a method.
177
+ ///
178
+ /// Implementations may impose limits on individual field values and on total
179
+ /// aggregate field section size. Operations that would exceed these limits
180
+ /// fail with `header-error.size-exceeded`
181
+ @since(version = 0.3.0)
182
+ resource fields {
183
+ /// Construct an empty HTTP Fields.
184
+ ///
185
+ /// The resulting `fields` is mutable.
186
+ constructor();
187
+ /// Construct an HTTP Fields.
188
+ ///
189
+ /// The resulting `fields` is mutable.
190
+ ///
191
+ /// The list represents each name-value pair in the Fields. Names
192
+ /// which have multiple values are represented by multiple entries in this
193
+ /// list with the same name.
194
+ ///
195
+ /// The tuple is a pair of the field name, represented as a string, and
196
+ /// Value, represented as a list of bytes. In a valid Fields, all names
197
+ /// and values are valid UTF-8 strings. However, values are not always
198
+ /// well-formed, so they are represented as a raw list of bytes.
199
+ ///
200
+ /// An error result will be returned if any header or value was
201
+ /// syntactically invalid, if a header was forbidden, or if the
202
+ /// entries would exceed an implementation size limit.
203
+ from-list: static func(entries: list<tuple<field-name, field-value>>) -> result<fields, header-error>;
204
+ /// Get all of the values corresponding to a name. If the name is not present
205
+ /// in this `fields`, an empty list is returned. However, if the name is
206
+ /// present but empty, this is represented by a list with one or more
207
+ /// empty field-values present.
208
+ get: func(name: field-name) -> list<field-value>;
209
+ /// Returns `true` when the name is present in this `fields`. If the name is
210
+ /// syntactically invalid, `false` is returned.
211
+ has: func(name: field-name) -> bool;
212
+ /// Set all of the values for a name. Clears any existing values for that
213
+ /// name, if they have been set.
214
+ ///
215
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
216
+ ///
217
+ /// Fails with `header-error.size-exceeded` if the name or values would
218
+ /// exceed an implementation-defined size limit.
219
+ set: func(name: field-name, value: list<field-value>) -> result<_, header-error>;
220
+ /// Delete all values for a name. Does nothing if no values for the name
221
+ /// exist.
222
+ ///
223
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
224
+ delete: func(name: field-name) -> result<_, header-error>;
225
+ /// Delete all values for a name. Does nothing if no values for the name
226
+ /// exist.
227
+ ///
228
+ /// Returns all values previously corresponding to the name, if any.
229
+ ///
230
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
231
+ get-and-delete: func(name: field-name) -> result<list<field-value>, header-error>;
232
+ /// Append a value for a name. Does not change or delete any existing
233
+ /// values for that name.
234
+ ///
235
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
236
+ ///
237
+ /// Fails with `header-error.size-exceeded` if the value would exceed
238
+ /// an implementation-defined size limit.
239
+ append: func(name: field-name, value: field-value) -> result<_, header-error>;
240
+ /// Retrieve the full set of names and values in the Fields. Like the
241
+ /// constructor, the list represents each name-value pair.
242
+ ///
243
+ /// The outer list represents each name-value pair in the Fields. Names
244
+ /// which have multiple values are represented by multiple entries in this
245
+ /// list with the same name.
246
+ ///
247
+ /// The names and values are always returned in the original casing and in
248
+ /// the order in which they will be serialized for transport.
249
+ copy-all: func() -> list<tuple<field-name, field-value>>;
250
+ /// Make a deep copy of the Fields. Equivalent in behavior to calling the
251
+ /// `fields` constructor on the return value of `copy-all`. The resulting
252
+ /// `fields` is mutable.
253
+ clone: func() -> fields;
254
+ }
255
+
256
+ /// Headers is an alias for Fields.
257
+ @since(version = 0.3.0)
258
+ type headers = fields;
259
+
260
+ /// Trailers is an alias for Fields.
261
+ @since(version = 0.3.0)
262
+ type trailers = fields;
263
+
264
+ /// Represents an HTTP Request.
265
+ @since(version = 0.3.0)
266
+ resource request {
267
+ /// Construct a new `request` with a default `method` of `GET`, and
268
+ /// `none` values for `path-with-query`, `scheme`, and `authority`.
269
+ ///
270
+ /// `headers` is the HTTP Headers for the Request.
271
+ ///
272
+ /// `contents` is the optional body content stream with `none`
273
+ /// representing a zero-length content stream.
274
+ /// Once it is closed, `trailers` future must resolve to a result.
275
+ /// If `trailers` resolves to an error, underlying connection
276
+ /// will be closed immediately.
277
+ ///
278
+ /// `options` is optional `request-options` resource to be used
279
+ /// if the request is sent over a network connection.
280
+ ///
281
+ /// It is possible to construct, or manipulate with the accessor functions
282
+ /// below, a `request` with an invalid combination of `scheme`
283
+ /// and `authority`, or `headers` which are not permitted to be sent.
284
+ /// It is the obligation of the `handler.handle` implementation
285
+ /// to reject invalid constructions of `request`.
286
+ ///
287
+ /// The returned future resolves to result of transmission of this request.
288
+ new: static func(headers: headers, contents: option<stream<u8>>, trailers: future<result<option<trailers>, error-code>>, options: option<request-options>) -> tuple<request, future<result<_, error-code>>>;
289
+ /// Get the Method for the Request.
290
+ get-method: func() -> method;
291
+ /// Set the Method for the Request. Fails if the string present in a
292
+ /// `method.other` argument is not a syntactically valid method.
293
+ set-method: func(method: method) -> result;
294
+ /// Get the combination of the HTTP Path and Query for the Request. When
295
+ /// `none`, this represents an empty Path and empty Query.
296
+ get-path-with-query: func() -> option<string>;
297
+ /// Set the combination of the HTTP Path and Query for the Request. When
298
+ /// `none`, this represents an empty Path and empty Query. Fails is the
299
+ /// string given is not a syntactically valid path and query uri component.
300
+ set-path-with-query: func(path-with-query: option<string>) -> result;
301
+ /// Get the HTTP Related Scheme for the Request. When `none`, the
302
+ /// implementation may choose an appropriate default scheme.
303
+ get-scheme: func() -> option<scheme>;
304
+ /// Set the HTTP Related Scheme for the Request. When `none`, the
305
+ /// implementation may choose an appropriate default scheme. Fails if the
306
+ /// string given is not a syntactically valid uri scheme.
307
+ set-scheme: func(scheme: option<scheme>) -> result;
308
+ /// Get the authority of the Request's target URI. A value of `none` may be used
309
+ /// with Related Schemes which do not require an authority. The HTTP and
310
+ /// HTTPS schemes always require an authority.
311
+ get-authority: func() -> option<string>;
312
+ /// Set the authority of the Request's target URI. A value of `none` may be used
313
+ /// with Related Schemes which do not require an authority. The HTTP and
314
+ /// HTTPS schemes always require an authority. Fails if the string given is
315
+ /// not a syntactically valid URI authority.
316
+ set-authority: func(authority: option<string>) -> result;
317
+ /// Get the `request-options` to be associated with this request
318
+ ///
319
+ /// The returned `request-options` resource is immutable: `set-*` operations
320
+ /// will fail if invoked.
321
+ ///
322
+ /// This `request-options` resource is a child: it must be dropped before
323
+ /// the parent `request` is dropped, or its ownership is transferred to
324
+ /// another component by e.g. `handler.handle`.
325
+ get-options: func() -> option<request-options>;
326
+ /// Get the headers associated with the Request.
327
+ ///
328
+ /// The returned `headers` resource is immutable: `set`, `append`, and
329
+ /// `delete` operations will fail with `header-error.immutable`.
330
+ get-headers: func() -> headers;
331
+ /// Get body of the Request.
332
+ ///
333
+ /// Stream returned by this method represents the contents of the body.
334
+ /// Once the stream is reported as closed, callers should await the returned
335
+ /// future to determine whether the body was received successfully.
336
+ /// The future will only resolve after the stream is reported as closed.
337
+ ///
338
+ /// This function takes a `res` future as a parameter, which can be used to
339
+ /// communicate an error in handling of the request.
340
+ ///
341
+ /// Note that function will move the `request`, but references to headers or
342
+ /// request options acquired from it previously will remain valid.
343
+ consume-body: static func(this: request, res: future<result<_, error-code>>) -> tuple<stream<u8>, future<result<option<trailers>, error-code>>>;
344
+ }
345
+
346
+ /// Parameters for making an HTTP Request. Each of these parameters is
347
+ /// currently an optional timeout applicable to the transport layer of the
348
+ /// HTTP protocol.
349
+ ///
350
+ /// These timeouts are separate from any the user may use to bound an
351
+ /// asynchronous call.
352
+ @since(version = 0.3.0)
353
+ resource request-options {
354
+ /// Construct a default `request-options` value.
355
+ constructor();
356
+ /// The timeout for the initial connect to the HTTP Server.
357
+ get-connect-timeout: func() -> option<duration>;
358
+ /// Set the timeout for the initial connect to the HTTP Server. An error
359
+ /// return value indicates that this timeout is not supported or that this
360
+ /// handle is immutable.
361
+ set-connect-timeout: func(duration: option<duration>) -> result<_, request-options-error>;
362
+ /// The timeout for receiving the first byte of the Response body.
363
+ get-first-byte-timeout: func() -> option<duration>;
364
+ /// Set the timeout for receiving the first byte of the Response body. An
365
+ /// error return value indicates that this timeout is not supported or that
366
+ /// this handle is immutable.
367
+ set-first-byte-timeout: func(duration: option<duration>) -> result<_, request-options-error>;
368
+ /// The timeout for receiving subsequent chunks of bytes in the Response
369
+ /// body stream.
370
+ get-between-bytes-timeout: func() -> option<duration>;
371
+ /// Set the timeout for receiving subsequent chunks of bytes in the Response
372
+ /// body stream. An error return value indicates that this timeout is not
373
+ /// supported or that this handle is immutable.
374
+ set-between-bytes-timeout: func(duration: option<duration>) -> result<_, request-options-error>;
375
+ /// Make a deep copy of the `request-options`.
376
+ /// The resulting `request-options` is mutable.
377
+ clone: func() -> request-options;
378
+ }
379
+
380
+ /// This type corresponds to the HTTP standard Status Code.
381
+ @since(version = 0.3.0)
382
+ type status-code = u16;
383
+
384
+ /// Represents an HTTP Response.
385
+ @since(version = 0.3.0)
386
+ resource response {
387
+ /// Construct a new `response`, with a default `status-code` of `200`.
388
+ /// If a different `status-code` is needed, it must be set via the
389
+ /// `set-status-code` method.
390
+ ///
391
+ /// `headers` is the HTTP Headers for the Response.
392
+ ///
393
+ /// `contents` is the optional body content stream with `none`
394
+ /// representing a zero-length content stream.
395
+ /// Once it is closed, `trailers` future must resolve to a result.
396
+ /// If `trailers` resolves to an error, underlying connection
397
+ /// will be closed immediately.
398
+ ///
399
+ /// The returned future resolves to result of transmission of this response.
400
+ new: static func(headers: headers, contents: option<stream<u8>>, trailers: future<result<option<trailers>, error-code>>) -> tuple<response, future<result<_, error-code>>>;
401
+ /// Get the HTTP Status Code for the Response.
402
+ get-status-code: func() -> status-code;
403
+ /// Set the HTTP Status Code for the Response. Fails if the status-code
404
+ /// given is not a valid http status code.
405
+ set-status-code: func(status-code: status-code) -> result;
406
+ /// Get the headers associated with the Response.
407
+ ///
408
+ /// The returned `headers` resource is immutable: `set`, `append`, and
409
+ /// `delete` operations will fail with `header-error.immutable`.
410
+ get-headers: func() -> headers;
411
+ /// Get body of the Response.
412
+ ///
413
+ /// Stream returned by this method represents the contents of the body.
414
+ /// Once the stream is reported as closed, callers should await the returned
415
+ /// future to determine whether the body was received successfully.
416
+ /// The future will only resolve after the stream is reported as closed.
417
+ ///
418
+ /// This function takes a `res` future as a parameter, which can be used to
419
+ /// communicate an error in handling of the response.
420
+ ///
421
+ /// Note that function will move the `response`, but references to headers
422
+ /// acquired from it previously will remain valid.
423
+ consume-body: static func(this: response, res: future<result<_, error-code>>) -> tuple<stream<u8>, future<result<option<trailers>, error-code>>>;
424
+ }
425
+ }
426
+
427
+ /// This interface defines a handler of HTTP Requests.
428
+ ///
429
+ /// In a `wasi:http/service` this interface is exported to respond to an
430
+ /// incoming HTTP Request with a Response.
431
+ ///
432
+ /// In `wasi:http/middleware` this interface is both exported and imported as
433
+ /// the "downstream" and "upstream" directions of the middleware chain.
434
+ @since(version = 0.3.0)
435
+ interface handler {
436
+ use types.{request, response, error-code};
437
+
438
+ /// This function may be called with either an incoming request read from the
439
+ /// network or a request synthesized or forwarded by another component.
440
+ handle: async func(request: request) -> result<response, error-code>;
441
+ }
442
+
443
+ /// This interface defines an HTTP client for sending "outgoing" requests.
444
+ ///
445
+ /// Most components are expected to import this interface to provide the
446
+ /// capability to send HTTP requests to arbitrary destinations on a network.
447
+ ///
448
+ /// The type signature of `client.send` is the same as `handler.handle`. This
449
+ /// duplication is currently necessary because some Component Model tooling
450
+ /// (including WIT itself) is unable to represent a component importing two
451
+ /// instances of the same interface. A `client.send` import may be linked
452
+ /// directly to a `handler.handle` export to bypass the network.
453
+ @since(version = 0.3.0)
454
+ interface client {
455
+ use types.{request, response, error-code};
456
+
457
+ /// This function may be used to either send an outgoing request over the
458
+ /// network or to forward it to another component.
459
+ send: async func(request: request) -> result<response, error-code>;
460
+ }
461
+
462
+ /// The `wasi:http/service` world captures a broad category of HTTP services
463
+ /// including web applications, API servers, and proxies. It may be `include`d
464
+ /// in more specific worlds such as `wasi:http/middleware`.
465
+ @since(version = 0.3.0)
466
+ world service {
467
+ import wasi:cli/types@0.3.0;
468
+ import wasi:cli/stdout@0.3.0;
469
+ import wasi:cli/stderr@0.3.0;
470
+ import wasi:cli/stdin@0.3.0;
471
+ import wasi:clocks/types@0.3.0;
472
+ import types;
473
+ import client;
474
+ import wasi:clocks/monotonic-clock@0.3.0;
475
+ import wasi:clocks/system-clock@0.3.0;
476
+ @unstable(feature = clocks-timezone)
477
+ import wasi:clocks/timezone@0.3.0;
478
+ import wasi:random/random@0.3.0;
479
+ import wasi:random/insecure@0.3.0;
480
+ import wasi:random/insecure-seed@0.3.0;
481
+
482
+ export handler;
483
+ }
484
+ /// The `wasi:http/middleware` world captures HTTP services that forward HTTP
485
+ /// Requests to another handler.
486
+ ///
487
+ /// Components may implement this world to allow them to participate in handler
488
+ /// "chains" where a `request` flows through handlers on its way to some terminal
489
+ /// `service` and corresponding `response` flows in the opposite direction.
490
+ @since(version = 0.3.0)
491
+ world middleware {
492
+ import wasi:clocks/types@0.3.0;
493
+ import types;
494
+ import handler;
495
+ import wasi:cli/types@0.3.0;
496
+ import wasi:cli/stdout@0.3.0;
497
+ import wasi:cli/stderr@0.3.0;
498
+ import wasi:cli/stdin@0.3.0;
499
+ import client;
500
+ import wasi:clocks/monotonic-clock@0.3.0;
501
+ import wasi:clocks/system-clock@0.3.0;
502
+ @unstable(feature = clocks-timezone)
503
+ import wasi:clocks/timezone@0.3.0;
504
+ import wasi:random/random@0.3.0;
505
+ import wasi:random/insecure@0.3.0;
506
+ import wasi:random/insecure-seed@0.3.0;
507
+
508
+ export handler;
509
+ }
@@ -0,0 +1,18 @@
1
+ package wasi:random@0.3.0;
2
+
3
+ interface random {
4
+ get-random-bytes: func(max-len: u64) -> list<u8>;
5
+
6
+ get-random-u64: func() -> u64;
7
+ }
8
+
9
+ interface insecure {
10
+ get-insecure-random-bytes: func(max-len: u64) -> list<u8>;
11
+
12
+ get-insecure-random-u64: func() -> u64;
13
+ }
14
+
15
+ interface insecure-seed {
16
+ get-insecure-seed: func() -> tuple<u64, u64>;
17
+ }
18
+
@@ -0,0 +1,6 @@
1
+ package crossbind:http;
2
+
3
+ world crossbind-http {
4
+ import wasi:http/types@0.3.0;
5
+ export wasi:http/handler@0.3.0;
6
+ }
@@ -7,12 +7,32 @@
7
7
 
8
8
  #include <netinet/in.h>
9
9
  #include <sys/socket.h>
10
+ #include <sys/stat.h>
11
+ #include <unistd.h>
10
12
 
11
13
  /* Compiled by the C++ driver at the command link; keep C linkage. */
12
14
  #ifdef __cplusplus
13
15
  extern "C" {
14
16
  #endif
15
17
 
18
+ /* wasi-libc p2/p3 leaves its output stream at the old offset after SEEK_END. SEEK_SET resets
19
+ that stream, so resolve the end offset through fstat and perform an absolute seek instead. */
20
+ off_t __real_lseek(int fd, off_t offset, int whence);
21
+ off_t __wrap_lseek(int fd, off_t offset, int whence)
22
+ {
23
+ if (whence == SEEK_END) {
24
+ struct stat status;
25
+ if (fstat(fd, &status) != 0) return (off_t)-1;
26
+ off_t absolute;
27
+ if (__builtin_add_overflow(status.st_size, offset, &absolute)) {
28
+ errno = EOVERFLOW;
29
+ return (off_t)-1;
30
+ }
31
+ return __real_lseek(fd, absolute, SEEK_SET);
32
+ }
33
+ return __real_lseek(fd, offset, whence);
34
+ }
35
+
16
36
  /* No dynamic loading on WASI; loaders treat NULL as "plugin unavailable". */
17
37
  void *dlopen(const char *file, int mode)
18
38
  {
@@ -79,6 +99,15 @@ int getpeername(int fd, struct sockaddr *addr, socklen_t *len)
79
99
  return crossbind_zeroed_inet(addr, len);
80
100
  }
81
101
 
102
+ /* The WASI SQLite leaves extension loading out, yet SpatiaLite's stored procedures switch it off; this answers
103
+ SQLITE_ERROR as such a build does. Weak, so a SQLite that has the function keeps its own. */
104
+ __attribute__((weak)) int sqlite3_enable_load_extension(void *db, int onoff)
105
+ {
106
+ (void)db;
107
+ (void)onoff;
108
+ return 1;
109
+ }
110
+
82
111
  #ifdef __cplusplus
83
112
  }
84
113
  #endif