Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(bindgen): check for corresponding .zig file #15896

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/codegen/bindgen-lib-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// always produce correct code, or bail with an error.
import { expect } from "bun:test";
import type { FuncOptions, Type, t } from "./bindgen-lib";
import fs from "node:fs";
import * as path from "node:path";
import assert from "node:assert";

Expand Down Expand Up @@ -806,6 +807,12 @@ export function registerFunction(opts: FuncOptions) {
const filename = stackTraceFileName(snapshot);
expect(filename).toEndWith(".bind.ts");
const zigFile = path.relative(src, filename.replace(/\.bind\.ts$/, ".zig"));
if (!fs.existsSync(zigFile)) {
const bindName = path.basename(filename);
throw new Error(
`$[bindName] is missing a corresponding Zig file at ${zigFile}. Please create it and make sure it matches signatures in ${bindName}.`,
);
}
let file = files.get(zigFile);
if (!file) {
file = { functions: [], typedefs: [] };
Expand Down
25 changes: 23 additions & 2 deletions src/codegen/bindgen-lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// This is the public API for `bind.ts` files
// It is aliased as `import {} from 'bindgen'`
/**
* This is the public API for `bind.ts` files
DonIsaac marked this conversation as resolved.
Show resolved Hide resolved
* It is aliased as `import {} from 'bindgen'`
* @see https://bun.sh/docs/project/bindgen
*/

import {
isType,
dictionaryImpl,
Expand Down Expand Up @@ -196,6 +200,23 @@ export namespace t {
export const ByteString = builtinType<string>()("ByteString");
/**
* DOMString but encoded as `[]const u8`
*
* @example
* ```ts
DonIsaac marked this conversation as resolved.
Show resolved Hide resolved
* // foo.bind.ts
* import { fn, t } from "bindgen";
*
* export const foo = fn({
* args: { bar: t.UTF8String },
* })
* ```
*
* ```zig
* // foo.zig
* pub fn foo(bar: []const u8) void {
* // ...
* }
* ```
*/
export const UTF8String = builtinType<string>()("UTF8String");

Expand Down
Loading