oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.54k stars 2.71k forks source link

Dlopen error when compiling a FFI library #11598

Open crystalthoughts opened 4 months ago

crystalthoughts commented 4 months ago

What version of Bun is running?

1.1.12

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

import { Webview } from "webview-bun"

const webview = new Webview();

let counter = 0;

const workerURL = new URL("server/staticSrvWorker.ts", import.meta.url).href;
const worker = new Worker(workerURL);

worker.postMessage("hello");
worker.onmessage = event => {
  console.log(event.data);
};

async function initWebView(){
    webview.bind("press", (a, b, c) => {
        console.log("Bun: Got data from client:",a, b, c);
        return { times: counter++ };
    });

    webview.bind("log", (...args) => console.log(...args));
    webview.navigate('http://127.0.0.1:1010/')

    webview.title = 'Substrate'
    // webview.setHTML(html);
    webview.run();

}
let initWebViewPromise = new Promise(async (resolve, reject) => {
    try {
        await initWebView();
        resolve();
    } catch (error) {
        reject(error);
    }
});

Promise.all([initWebViewPromise, /* other promises or functions */])
    .then(() => console.log('All tasks completed'))
    .catch((error) => console.log('An error occurred:', error));

When running a compiled exe the following error is reported:

What is the expected behavior?

It should run as if bun ./main.ts was called. Libraries could be packaged in?

What do you see instead?

56 |       wrap = (...args2) => func(functionToCall, ...args2);
57 |       break;
58 |     }
59 |   }
60 |   return wrap.native = functionToCall, wrap.ptr = functionToCall.ptr, wrap;
61 | }, dlopen = function(path, options) {
               ^
ERR_DLOPEN_FAILED: Failed to open library. This is usually caused by a missing library or an invalid library path.
 syscall: "dlopen"

Additional information

No response

mvolkmann commented 3 months ago

I simpler way to reproduce this issue is to follow the instructions at https://bun.sh/docs/api/ffi. The example of a Zig function that adds two integers gives me the same error when I run the TypeScript code. I copied the code from that documentation page exactly and I get the error "ERR_DLOPEN_FAILED: Failed to open library. This is usually caused by a missing library or an invalid library path."