Skip to content
New issue

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

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

Already on GitHub? # to your account

Mojo FFI: Mojo Call XXX - Binding C/C++/Rust libraries to Mojo libraries. #432

Open
hhstore opened this issue Oct 10, 2024 · 8 comments
Open

Comments

@hhstore
Copy link
Owner

hhstore commented Oct 10, 2024

📖 Abstract:

  • ✅ 基于 C FFI, 把 C/C++/Rust 库 binding 成 Mojo 库, 供 Mojo 调用。

💯 Related:

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

Mojo FFI 方案

  • FFI(Foreign function interface).

🌞 Mojo Call XXX

  • XXX: 通常是静态语言(No GC), C/C++/Rust/Zig 这种。
  • ✅ 把 其他静态语言库 binding 成 Mojo 库, 供 mojo 使用.

工具人语言(C/C++/Rust)

  • 🔥 Mojo Call C/C++
  • 🔥 Mojo Call Rust

🌝 YYY Call Mojo

👇🏻 说明
  • YYY: 不限,可以是 Python/Go/Java, 也可以是 C/C++/Rust/Zig 等。
  • ✅ 把 Mojo 库 binding 成 其他语言库, 供其他语言使用。

Python Call Mojo

  • 当前是 subprocess + cmd 方式来调用,后续应该有更简单方案。

Rust Call Mojo

  • 待支持

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

Mojo FFI: 🔥 Call C/C++

  • TODO

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

Mojo FFI: 🔥 Call Rust

Mojo 侧

Rust 侧

🛠️ Rust 工具链

safer_ffi

diplomat

uniffi-rs

cbindgen

💼 Rust FFI 示例项目

项目案例:

🛑 注意事项

🙅🏻 内存泄漏问题

  • Rust FFI 需要注意跨语言,内存分配后,需要手动 + 显式释放资源,否则,会出现内存泄漏问题.

🙅🏻 数据类型转换

  • 要把 Rust 数据类型,转成 C 数据类型

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

Mojo FFI 案例:

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

1

3 similar comments
@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

1

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

1

@hhstore
Copy link
Owner Author

hhstore commented Oct 10, 2024

1

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant