bun
bun copied to clipboard
Bun is unable to run llvm-bindings library
Version
0.2.0
Platform
wsl ubuntu
What steps will reproduce the bug?
create a new bun project add llvm-bindings to bun run the same program
import llvm from 'llvm-bindings';
function main(): void {
const context = new llvm.LLVMContext();
const module = new llvm.Module('demo', context);
const builder = new llvm.IRBuilder(context);
const returnType = builder.getInt32Ty();
const paramTypes = [builder.getInt32Ty(), builder.getInt32Ty()];
const functionType = llvm.FunctionType.get(returnType, paramTypes, false);
const func = llvm.Function.Create(functionType, llvm.Function.LinkageTypes.ExternalLinkage, 'add', module);
const entryBB = llvm.BasicBlock.Create(context, 'entry', func);
builder.SetInsertPoint(entryBB);
const a = func.getArg(0);
const b = func.getArg(1);
const result = builder.CreateAdd(a, b);
builder.CreateRet(result);
if (llvm.verifyFunction(func)) {
console.error('Verifying function failed');
return;
}
if (llvm.verifyModule(module)) {
console.error('Verifying module failed');
return;
}
console.log(module.print());
}
main();
How often does it reproduce? Is there a required condition?
Reproduces consistently
What is the expected behavior?
llvm-bindings runs correctly. the sample programs runs and prints the generated IR.
What do you see instead?
rishav@Rishav-SB3:~/testapp$ bun run testapp.ts
164 | }
165 | }
166 | };
167 |
168 | // run the 'prepareStackTrace' function above
169 | Error.captureStackTrace(dummy);
^
TypeError: Error.captureStackTrace is not a function. (In 'Error.captureStackTrace(dummy)', 'Error.captureStackTrace' is undefined)
at getFileName (/home/rishav/testapp/node_modules/bindings/bindings.js:169:2)
at bindings (/home/rishav/testapp/node_modules/bindings/bindings.js:82:39)
at /home/rishav/testapp/node_modules/llvm-bindings/index.js:1:25
at bun:wrap:1:16360
at /home/rishav/testapp/testapp.ts:1:0
Additional information
No response
After some searching through the existing issues, I think my issue is blocked on this https://github.com/oven-sh/bun/issues/258
with https://github.com/oven-sh/bun/issues/258#issuecomment-1309317337 fixed, I will check this in the new bun release and close it.
You can try it now via
bun upgrade --canary
that error is no longer coming. Got a new one now;
bun: symbol lookup error: /home/rishav/bunllvm/node_modules/llvm-bindings/build/Debug/llvm-bindings.node: undefined symbol: napi_create_external
not sure if this has anything to do with bun.
We need to implement napi_create_external
Implemented napi_create_external in https://github.com/oven-sh/bun/commit/dddbce8a41aa266af106b19e583c152126900730
Please try again after the canary builds
Thank you @Jarred-Sumner ! There is a new symbol missing error now;
bun: symbol lookup error: /home/rishav/bunllvm/node_modules/llvm-bindings/build/Debug/llvm-bindings.node: undefined symbol: napi_open_escapable_handle_scope
is there a way get a list of all symbols in the .node file in one go?
Can you try again? That one is stubbed out.
You'll need to add llvm-bindings to your package.json, like so:
{
"dependencies": {
"llvm-bindings": "^0.4.2"
},
"trustedDependencies": [
"llvm-bindings"
]
}
Then run bun install, and the code should work. If you're still experiencing an error, let us know and we'll re-open this issue.