Questions tagged [rust-bindgen]

44 questions
1
vote
1 answer

How to convert pointer to multidimensional slice/array

I'm writing a c-binding to a Rust function. The Rust function takes a 3D slice where 2 dimensions are of size two. Essentially it's a slice of 2D line segments where a line segment is represented by 2 points. This means the segments have…
John Smith
  • 179
  • 4
1
vote
0 answers

How can I enable different features of bindgen dependening on the host env?

Rustup's musl toolchain breaks dynamic libraries by design, meaning that bindgen's runtime feature which loads libclang.so at runtime cannot be used. Now, I want my crate to compile in both musl and gnu environments, so I'm trying to detect the…
msrd0
  • 7,816
  • 9
  • 47
  • 82
1
vote
1 answer

How to include Windows.h with rust bindgen?

I am starting a new addon for MSFS2020 in rust with the SimConnect SDK written in c++. I am using the bingen crates to create the binding with the SDK. I need to include Windows.h for the binding to work but I get the following error: error: header…
P.E. Joëssel
  • 1,393
  • 10
  • 18
1
vote
0 answers

Linking C library in rust build script

I am trying to learn how to use bindgen. I am following the documentation(https://rust-lang.github.io/rust-bindgen/tutorial-3.html) and I have the following code to link to a C library: extern crate bindgen; use std::env; use…
nico.user
  • 483
  • 2
  • 5
  • 15
1
vote
1 answer

Rust bindgen and systems/compilers where char is wider than 8 bits

I have a C header file which contains string constants #define SOLCLIENT_SESSION_PROP_USERNAME "SESSION_USERNAME" and bindgen translates them to pub const SOLCLIENT_SESSION_PROP_USERNAME: &'static [u8; 17usize] = b"SESSION_USERNAME\0"; (1) How…
Radek Micek
  • 447
  • 2
  • 9
1
vote
0 answers

What's the best way to write a wrapper for a C++ library, when rust-bindgen doesn't work on the original headers?

I'm trying to port a C++ library to Rust. One dependency isn't open-source, and I only have access to the header files. rust-bindgen doesn't generate valid bindings from these header files, and after searching online for a while, I came to the…
object-Object
  • 1,587
  • 1
  • 12
  • 14
1
vote
0 answers

What are the solutions for wrapping a C-style `static const` global constant in Rust using Bindgen?

I am creating Rust bindings for a C library that defines lists of standard constant default values: // C typedef struct RMW_PUBLIC_TYPE rmw_qos_profile_t { size_t depth; enum rmw_qos_reliability_policy_t reliability; // ... }…
deb0ch
  • 1,133
  • 2
  • 16
  • 25
1
vote
0 answers

How do I convert a static global variable generated by Bindgen into a global const?

Bindgen generates this from a static const C-style global structure: pub struct rmw_qos_profile_t { pub depth: usize, pub deadline: rmw_time_t, // ... } extern "C" { #[link_name = "\u{1}rmw_qos_profile_sensor_data"] pub static…
deb0ch
  • 1,133
  • 2
  • 16
  • 25
0
votes
1 answer

How to deal with a pointer to array of C strings in Rust?

I'm trying to write a Rust wrapper over the C++ library, where the pointer to array of C-style string is defined as: char ***name; In C++ I can iterate over strings easily: for(int i=0;i
yesint
  • 145
  • 9
0
votes
0 answers

Cargo panics with FromBytesWithNulError when using bindgen with C++

Solved! People seem to agree on it being a bug that's fixed, just not in the current version. Am currently learning Rust, cause it's the hot shit and will dethrone C++, bluh, bluh, and came across bindgen, which seems obviously important when…
Tidemor
  • 138
  • 1
  • 7
0
votes
0 answers

use a dylib & header files in rust missing fstream

I want to use the ctranslate2 library in rust. To use it it needs to be compiled. The result is a dylib file and the includes. How can I use this code?. I found bindgen which makes this possible, but i get this error. …
filif96770
  • 55
  • 5
0
votes
0 answers

Access/Generate all Android SDK classes in a Rust library

I want to access all Android SDK classes in a Rust library, and perform some operations on the Android system. Here is the example list of classes/packages that I want to access android.hardware.usb.* (UsbManager,…
0
votes
0 answers

Rust bindgen use of pointer addresse `*mut i8` for allocating memory for camera, getting "cannot be sent between threads safely"

tl&dr: How to work with *mut i8 so it is thread safe for use in lazy_static! Mutex ? I have a function that generates a pointer address in the form of *mut i8, which I want to store in a struct that is initiated by lazy_static! {static ref…
will.mendil
  • 752
  • 2
  • 6
  • 21
0
votes
1 answer

Coerce anyhow::Error to NjError for node-bindgen

I want to wrap a rust function with node-bindgen to return a promise in JavaScript. The function in question returns an anyhow:Error. This is my goofy attempt: #[tokio::main] #[node_bindgen] async fn warprometo(offset: u32) -> Result<(), NjError> { …
Skylar Saveland
  • 11,116
  • 9
  • 75
  • 91
0
votes
1 answer

Pass 2D array of bytes to C in Rust

I've written a function in C with this signature: write_stuff(char **pages, uint32 page_count); pages will be an array of 128 elements, with each element either NULL or pointing to a char array of 8192 bytes. So, an array of arrays with fixed,…
ccleve
  • 15,239
  • 27
  • 91
  • 157