mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
Add new bindings generator; port SSLConfig (#23169)
Add a new generator for JS → Zig bindings. The bulk of the conversion is done in C++, after which the data is transformed into an FFI-safe representation, passed to Zig, and then finally transformed into idiomatic Zig types. In its current form, the new bindings generator supports: * Signed and unsigned integers * Floats (plus a “finite” variant that disallows NaN and infinities) * Strings * ArrayBuffer (accepts ArrayBuffer, TypedArray, or DataView) * Blob * Optional types * Nullable types (allows null, whereas Optional only allows undefined) * Arrays * User-defined string enumerations * User-defined unions (fields can optionally be named to provide a better experience in Zig) * Null and undefined, for use in unions (can more efficiently represent optional/nullable unions than wrapping a union in an optional) * User-defined dictionaries (arbitrary key-value pairs; expects a JS object and parses it into a struct) * Default values for dictionary members * Alternative names for dictionary members (e.g., to support both `serverName` and `servername` without taking up twice the space) * Descriptive error messages * Automatic `fromJS` functions in Zig for dictionaries * Automatic `deinit` functions for the generated Zig types Although this bindings generator has many features not present in `bindgen.ts`, it does not yet implement all of `bindgen.ts`'s functionality, so for the time being, it has been named `bindgenv2`, and its configuration is specified in `.bindv2.ts` files. Once all `bindgen.ts`'s functionality has been incorporated, it will be renamed. This PR ports `SSLConfig` to use the new bindings generator; see `SSLConfig.bindv2.ts`. (For internal tracking: fixes STAB-1319, STAB-1322, STAB-1323, STAB-1324) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Alistair Smith <hi@alistair.sh>
This commit is contained in:
@@ -6,8 +6,9 @@ pub const PathString = @import("./string/PathString.zig").PathString;
|
||||
pub const SmolStr = @import("./string/SmolStr.zig").SmolStr;
|
||||
pub const StringBuilder = @import("./string/StringBuilder.zig");
|
||||
pub const StringJoiner = @import("./string/StringJoiner.zig");
|
||||
pub const WTFStringImpl = @import("./string/WTFStringImpl.zig").WTFStringImpl;
|
||||
pub const WTFStringImplStruct = @import("./string/WTFStringImpl.zig").WTFStringImplStruct;
|
||||
pub const WTFString = @import("./string/wtf.zig").WTFString;
|
||||
pub const WTFStringImpl = @import("./string/wtf.zig").WTFStringImpl;
|
||||
pub const WTFStringImplStruct = @import("./string/wtf.zig").WTFStringImplStruct;
|
||||
|
||||
pub const Tag = enum(u8) {
|
||||
/// String is not valid. Observed on some failed operations.
|
||||
@@ -47,7 +48,7 @@ pub const String = extern struct {
|
||||
pub const empty = String{ .tag = .Empty, .value = .{ .ZigString = .Empty } };
|
||||
|
||||
pub const dead = String{ .tag = .Dead, .value = .{ .Dead = {} } };
|
||||
pub const StringImplAllocator = @import("./string/WTFStringImpl.zig").StringImplAllocator;
|
||||
pub const StringImplAllocator = @import("./string/wtf.zig").StringImplAllocator;
|
||||
|
||||
pub fn toInt32(this: *const String) ?i32 {
|
||||
const val = bun.cpp.BunString__toInt32(this);
|
||||
|
||||
Reference in New Issue
Block a user