Static FFI library that provides an entry point to the Rust wlan-mlme library for the C++ wlansoftmac driver.
The cbindgen program reads a locally generated Cargo.toml manifest to create the bindings.h header for the wlansoftmac-c static Rust library, and its dependencies, to expose a public C API.
There are four steps to create/update the bindings.h header:
Cargo.toml manifest for wlansoftmac-c.bindings.h header.bindings.h header.The stable Rust toolchain cannot process Fuchsia-generated Cargo.toml manifests. You therefore must link the Fuchsia toolchain in your environment:
rustup toolchain link fuchsia "$FUCHSIA_DIR/prebuilt/third_party/rust/linux-x64"
If you cannot link this toolchain in your environment, you may alternately use the nightly Rust toolchain instead.
We currently pin cbindgen at version 0.26.0 to avoid unexpected behavior with cbindgen updates. You can install it with the following:
cargo install --version 0.26.0 --force cbindgen
Cargo.toml manifest for wlansoftmac-cGenerate a Cargo.toml for wlansoftmac-c by following the instructions on fuchsia.dev for the build target //src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding:wlansoftmac-c.
As of this writing, this is done in the following way.
Using fx args, add //build/rust:cargo_toml_gen to host_labels.
Using fx args, add //src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding:_wlansoftmac_c_rustc_static to build_only_labels.
Build the cargo_toml_gen target and generate the Cargo.toml manifest:
fx args # then append "//build/rust:cargo_toml_gen" to `host_labels`
fx args # then append "//src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding:_wlansoftmac_c_rustc_static"
# to `build_only_labels`
fx build //build/rust:cargo_toml_gen
fx gen-cargo //src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding:_wlansoftmac_c_rustc_static
bindings.h headerThe following command uses the Fuchsia toolchain and cbindgen to create/update the bindings.h header. If you could not link the Fuchsia toolchain, you may substitute RUSTUP_TOOLCHAIN=nightly.
RUSTUP_TOOLCHAIN=fuchsia cbindgen $FUCHSIA_DIR/src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding/ -o $FUCHSIA_DIR/src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding/bindings.h
NOTE: The wlan-mlme library and wlansoftmac driver each use bindings for their respective language. This means cbindgen cannot properly identify whether the types in those libraries exist or not. Therefore, it is is normal to see WARN logs like the following for some types:
WARN: Can't find zx_status_t. This usually means that this type was incompatible or not found.
bindings.hcbindgen uses a /* */ style comment for the header guard which is incompatible with fx format-code. Change this final comment line in bindings.h to
#endif // SRC_CONNECTIVITY_WLAN_DRIVERS_WLANSOFTMAC_RUST_DRIVER_C_BINDING_BINDINGS_H_
and then run fx format-code
fx format-code --files=$FUCHSIA_DIR/src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding/bindings.h
cargo metadataRemove the local Cargo.toml manifest and Cargo.lock and re-run fx gen-cargo.
wlansoftmac_c: can't find dependency version for xyzRebuild Fuchsia with fx build and re-run fx gen-cargo //src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding:_wlansoftmac_c_rustc_static.
Try running cbindgen with -v argument to get a better understand what types and functions were found and why they may have been rejected.
cargo +nightly metadata --all-features --format-version 1 --manifest-path Cargo.toml > metadata.json
RUSTUP_TOOLCHAIN=fuchsia cbindgen $FUCHSIA_DIR/src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding/ -o $FUCHSIA_DIR/src/connectivity/wlan/drivers/wlansoftmac/rust_driver/c-binding/bindings.h --metadata metadata.json