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

Problem with ffi on mac m1 #6517

Open
xgrommx opened this issue Oct 15, 2023 · 6 comments
Open

Problem with ffi on mac m1 #6517

xgrommx opened this issue Oct 15, 2023 · 6 comments
Labels
bug Something isn't working bun:ffi Something related with FFI in Bun bun.js Something to do with a Bun-specific API

Comments

@xgrommx
Copy link

xgrommx commented Oct 15, 2023

What version of Bun is running?

1.0.6

What platform is your computer?

Darwin 22.6.0 x86_64 i386

What steps can reproduce the bug?

Create main.rs with some simple rust function like

#[no_mangle]
pub extern "C" fn math(a: isize, b: isize) -> isize {
    a + b
}

Run this command rustc --crate-type cdylib ./math.rs

Create index.ts with following code

import { dlopen, FFIType } from "bun:ffi";

const symbols = dlopen('./libmath.dylib', {
  math: {
    args: [FFIType.i32, FFIType.i32],
    returns: FFIType.i32
  },
});

Run this command bun .

What is the expected behavior?

Should be ok.

What do you see instead?

But I got this error

56 |       break;
57 |     }
58 |   }
59 |   return wrap.native = functionToCall, wrap.ptr = functionToCall.ptr, wrap;
60 | 
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

@xgrommx xgrommx added the bug Something isn't working label Oct 15, 2023
@Electroid Electroid added the bun:ffi Something related with FFI in Bun label Oct 16, 2023
@zigster64
Copy link

Can’t reproduce this

no probs here using dlopen on M1 or M2, with bun 1.0.5, 1.0.6, 1.0.7

Using both Zig and Rust dynamic libs .. in production

can the OP please check the original post - it says your platform is Darwin x86, and not M1 as per the title ? Can you check that your dynlib is the same architecture as your system please.

@noah-wardlow
Copy link

I'm seeing this too

@btakita
Copy link

btakita commented Oct 25, 2023

This also occurs on arch linux using both bun-bin aur package & the curl install

@zigster64
Copy link

https://github.com/zigster64/bun-issue-6517

Just for testing. Wouldn't mind some more data points on this, would be good to fix, thx

@xgrommx
Copy link
Author

xgrommx commented Nov 5, 2023

Still doesn't work even with new version of bun 1.0.9

@rokicki
Copy link

rokicki commented Feb 27, 2024

I just fought through this on my Mac; it turned out that there were lurking x86 executables in ~/.cargo/bin. By deleting ~/.cargo and ~/.rustup completely and reinstalling Rust from scratch the problem went away.

To see if this is your problem type:

file ~/.cargo/bin/*

and if you see anything that says x86 that's probably your issue.

@RiskyMH RiskyMH added the bun.js Something to do with a Bun-specific API label Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun:ffi Something related with FFI in Bun bun.js Something to do with a Bun-specific API
Projects
None yet
Development

No branches or pull requests

7 participants