-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle typedef with postfix struct name; bunAllocArray hepler added
- Loading branch information
Showing
11 changed files
with
121 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
node_modules | ||
generate-wgpu-bindings_cache_*.json | ||
test-bindings_cache_*.json | ||
generate-bindings_tmp_exec | ||
example.ts | ||
src | ||
test.h | ||
test.ts | ||
.vscode |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "bun", | ||
"internalConsoleOptions": "neverOpen", | ||
"request": "launch", | ||
"name": "Debug File", | ||
"program": "test.ts", | ||
"cwd": "${workspaceFolder}", | ||
"stopOnEntry": false, | ||
"watchMode": true | ||
} | ||
] | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
typedef struct { | ||
int a; | ||
int b; | ||
} Foo; | ||
|
||
int sum(Foo* f); |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ClangTypeInfoCache, clangGetAstJson, CodeGen, parseClangAst, clangClean, addIncludeDir } from "./src"; | ||
import { LogLevel, setLogLevel } from "./src/log"; | ||
import path from "path"; | ||
|
||
const HEADER_PATH = "./test.h"; | ||
const TYPE_CACHE_PATH = "./test-bindings_cache"; | ||
|
||
setLogLevel(LogLevel.verbose); | ||
|
||
// add include dirs for clang | ||
addIncludeDir(path.resolve("my_include_dir")); | ||
|
||
// get header ast from clang | ||
const wgpuAst = await clangGetAstJson(HEADER_PATH); | ||
|
||
// create clang types cache (for sizeof / offsetof) | ||
const clangTypeInfoCache = await ClangTypeInfoCache.create(TYPE_CACHE_PATH); | ||
|
||
// parse ast | ||
const result = parseClangAst(wgpuAst, HEADER_PATH, clangTypeInfoCache); | ||
|
||
// update clang cache | ||
await clangTypeInfoCache.save(); | ||
|
||
// prepare code generation | ||
const codeGen = new CodeGen({ | ||
// see more options below | ||
funcSymbolsImportLibPathCode(out) { | ||
out.push(` | ||
let _LIB_PATH: string = ""; | ||
if (process.platform == "darwin") { | ||
_LIB_PATH = | ||
import.meta.dir + | ||
"/../wgpu/libwgpu_native.dylib"; | ||
} else { | ||
throw new Error("not supported wgpu bindings platform"); | ||
} | ||
`); | ||
|
||
return "_LIB_PATH"; | ||
}, | ||
}); | ||
|
||
codeGen.generateAll(result); | ||
|
||
if (codeGen.failedSymbols.size) { | ||
console.log("ffi failed for:"); | ||
console.log(Array.from(codeGen.failedSymbols)); | ||
} | ||
|
||
// write output | ||
codeGen.writeToFile("./test_out.ts"); | ||
|
||
// cleanup | ||
await clangTypeInfoCache.save(); | ||
await clangClean(); |