-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coverall2 and Rondpoint working with WASM! (#191)
This PR adds: - lowlevel structures - RustBuffers, - Floats and - c_void Void Pointers. - high level mechanisms to do in a browser context: - encoding and decoding strings, using `TextEncoder` and `TextDecoder`. - tie Objects into the Garbage Collector with a `FinalizationRegistry`. This is in service of getting the `rondpoint` fixture running. Several things to note here: ### `error: rondpointpm::Optionneur is a private type` Structs which derive the `uniffi::Object` currently need to have visibility `pub`. If they're not, then errors like: `error: rondpointpm::Optionneur is a private type` are shown. This is due to `uniffi-rs` generating a public C ABI which uses the private struct as part of its trait bounds. This feels like it's a Rust bug (I hate saying that). Next steps: - File an issue: - `uniffi-rs` could generate a simpler ABI which didn't contain the private type. - `uniffi-rs` could prevent non-`pub` structs - Document: `uniffi-bindgen-react-native` should add this to a trouble-shooting page. ### Additing a procmacro version of rondpoint and coverall2 This is due to mozilla/uniffi-rs#2329 not yet being release. Since we have now released to CocoaPods and npm, I can build against uniffi-main. This is o k a y for a little project like this, but I do worry about that a chem-spill requiring a rapid fix and release may get messy. ### Default attribute values not seeming to work in proc-macro `uniffi::Record` I don't seem to be able to get default attributes working for records going: as in the typescript isn't getting generated. If this is a bug, this is almost certainly a uniffi-rs bug. Will file.
- Loading branch information
Showing
19 changed files
with
926 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
crates/ubrn_bindgen/src/bindings/gen_typescript/templates/RecordTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 21 additions & 39 deletions
60
crates/ubrn_bindgen/src/bindings/gen_typescript/templates/StringHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,24 @@ | ||
{{- self.import_infra("RustBuffer", "ffi-types") }} | ||
{{- self.import_infra_type("UniffiByteArray", "ffi-types") }} | ||
{{- self.import_infra("FfiConverterInt32", "ffi-converters") }} | ||
{{- self.import_infra_type("FfiConverter", "ffi-converters") }} | ||
{{- self.import_infra("uniffiCreateFfiConverterString", "ffi-converters") }} | ||
|
||
const stringToArrayBuffer = (s: string): UniffiByteArray => | ||
uniffiCaller.rustCall((status) => {% call ts::fn_handle(ci.ffi_function_string_to_arraybuffer()) %}(s, status)); | ||
|
||
const arrayBufferToString = (ab: UniffiByteArray): string => | ||
uniffiCaller.rustCall((status) => {% call ts::fn_handle(ci.ffi_function_arraybuffer_to_string()) %}(ab, status)); | ||
|
||
const stringByteLength = (s: string): number => | ||
uniffiCaller.rustCall((status) => {% call ts::fn_handle(ci.ffi_function_string_to_bytelength()) %}(s, status)); | ||
|
||
const FfiConverterString = (() => { | ||
const lengthConverter = FfiConverterInt32; | ||
type TypeName = string; | ||
class FFIConverter implements FfiConverter<UniffiByteArray, TypeName> { | ||
lift(value: UniffiByteArray): TypeName { | ||
return arrayBufferToString(value); | ||
} | ||
lower(value: TypeName): UniffiByteArray { | ||
return stringToArrayBuffer(value); | ||
} | ||
read(from: RustBuffer): TypeName { | ||
const length = lengthConverter.read(from); | ||
const bytes = from.readBytes(length); | ||
return arrayBufferToString(new Uint8Array(bytes)); | ||
} | ||
write(value: TypeName, into: RustBuffer): void { | ||
const buffer = stringToArrayBuffer(value).buffer; | ||
const numBytes = buffer.byteLength; | ||
lengthConverter.write(numBytes, into); | ||
into.writeBytes(buffer); | ||
} | ||
allocationSize(value: TypeName): number { | ||
return lengthConverter.allocationSize(0) + stringByteLength(value); | ||
} | ||
} | ||
|
||
return new FFIConverter(); | ||
{%- if flavor.supports_text_encoder() %} | ||
const stringConverter = (() => { | ||
const encoder = new TextEncoder(); | ||
const decoder = new TextDecoder(); | ||
return { | ||
stringToBytes: (s: string) => encoder.encode(s), | ||
bytesToString: (ab: UniffiByteArray) => decoder.decode(ab), | ||
stringByteLength: (s: string) => encoder.encode(s).byteLength, | ||
}; | ||
})(); | ||
{%- else %} | ||
const stringConverter = { | ||
stringToBytes: (s: string) => | ||
uniffiCaller.rustCall((status) => {% call ts::fn_handle(ci.ffi_function_string_to_arraybuffer()) %}(s, status)), | ||
bytesToString: (ab: UniffiByteArray) => | ||
uniffiCaller.rustCall((status) => {% call ts::fn_handle(ci.ffi_function_arraybuffer_to_string()) %}(ab, status)), | ||
stringByteLength: (s: string) => | ||
uniffiCaller.rustCall((status) => {% call ts::fn_handle(ci.ffi_function_string_to_bytelength()) %}(s, status)), | ||
}; | ||
{%- endif %} | ||
const FfiConverterString = uniffiCreateFfiConverterString(stringConverter); |
1 change: 1 addition & 0 deletions
1
crates/ubrn_bindgen/src/bindings/gen_typescript/templates/Types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.