peterwmwong / metal-cpp-rs

A failed attempt to generate Rust bindings for the Apple Metal API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A failed attempt to generate Rust bindings for the Apple Metal API

Currently, the bindings don't seem to be good enough to actually use.

  • ApplicationDelegate's vtable isn't filled out to even open a window.

Directories metal-cpp/ and metal-cpp-extensions/ are copied (with one exception noted below) from Learn Metal with C++ sample code.

NS_Defines.hpp has been modified to disable _NS_INLINE, which prevented methods/functions from being included in the static library used by the bindings generated by Bindgen.

Build

# Install master branch build of rust-bindgen that includes `vtable-generation`
cargo install --git https://github.com/rust-lang/rust-bindgen --branch master bindgen

# Build/Run
cargo run

Overall approach

  1. Generate Rust bindings using Bindgen (see gen-metal-cpp-rs-bindings.sh), output is included in source metal_cpp_rs_bindings.rs.
  2. Using a build.rs....
    1. Create a static library (metal_cpp_rs_bindings.o) from metal_cpp_rs_bindings.cpp, which only includes the necessary header files from metal-cpp and metal-cpp-extensions.
    2. Create an archive libmetal_cpp_rs_bindings.a
    3. Emit Cargo directives to the compiler to link against libmetal_cpp_rs_bindings.a and necessary frameworks (Foundation, Cocoa, CoreGraphics, Metal, MetalKit).

About

A failed attempt to generate Rust bindings for the Apple Metal API


Languages

Language:Rust 54.5%Language:C++ 45.0%Language:Python 0.4%Language:Shell 0.0%