rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.23k stars 679 forks source link

`rewriting static` string in generated bindings #2852

Closed robin-nitrokey closed 1 week ago

robin-nitrokey commented 1 week ago

Input C/C++ Header

#define test 0

Bindgen Invocation

$  cargo --version
cargo 1.81.0-nightly (bc89bffa5 2024-06-22)
$ git describe
v0.69.1-94-gcf9b02f5
$ cargo run -- repro.h

Actual Results

/* automatically generated by rust-bindgen 0.69.4 */

rewriting static
pub const test: u32 = 0;

Expected Results

The generated bindings should compile properly and not contain arbitrary strings.

notes:

emilio commented 1 week ago

On which OS? This works for me on trunk and on the crates.io crate... that string is nowhere in the source code...

chrysn commented 1 week ago

We're having similar trouble in our setup. A commonality between those is that we're also more "in the embedded area". We haven't managed to track down the source of the string either, but I did find that it is emitted as part of the bindgen generation (an strace shows that the odd string is written in the same write call as the rest of what our bindings.wrtite_to_file produces).

I can reproduce this on Debian GNU/Linux with a current nightly Rust installed through rustup; the issue does not appear with stable.

chrysn commented 1 week ago

Correction: The string is not necessarily written in the same process: I mistook the contiguious read from the built file for a write.

The write actually originates from a some process writing it to file descriptor 1, its stdout -- which makes the whole thing appear more like some printf that escaped debugging.

chrysn commented 1 week ago

… and it is rustfmt, where it is already reported: https://github.com/rust-lang/rustfmt/issues/6210

(So I'd guess this is a duplicate, and we all wait for a new nightly where the offending line is reverted).

emilio commented 1 week ago

Thanks! Yeah let´s close as a dupe of https://github.com/rust-lang/rustfmt/issues/6210