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