Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewriting static string in generated bindings #2852

Closed
robin-nitrokey opened this issue Jun 24, 2024 · 10 comments
Closed

rewriting static string in generated bindings #2852

robin-nitrokey opened this issue Jun 24, 2024 · 10 comments

Comments

@robin-nitrokey
Copy link

robin-nitrokey commented Jun 24, 2024

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:

  • even occurs with 0.69.4 from crates.io and when invoking Builder::generate from build.rs
  • only occurs since nightly-2024-06-23, nightly-2024-06-22 still works
@robin-nitrokey robin-nitrokey changed the title rewriting static string in generated header rewriting static string in generated bindings Jun 24, 2024
@emilio
Copy link
Contributor

emilio commented Jun 24, 2024

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

@chrysn
Copy link
Contributor

chrysn commented Jun 24, 2024

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
Copy link
Contributor

chrysn commented Jun 24, 2024

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
Copy link
Contributor

chrysn commented Jun 24, 2024

… and it is rustfmt, where it is already reported: rust-lang/rustfmt#6210

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

@emilio
Copy link
Contributor

emilio commented Jun 24, 2024

Thanks! Yeah let´s close as a dupe of rust-lang/rustfmt#6210

@ghenry
Copy link

ghenry commented Jul 25, 2024

I'm getting this when converting SentryPeer conf to its Rust bindings

868 times! Any ideas?

Running:

bindgen conf.h -o ../sentrypeer_rust/src/sentrypeer_conf_.rs

@chrysn
Copy link
Contributor

chrysn commented Jul 25, 2024 via email

@ghenry
Copy link

ghenry commented Jul 25, 2024

Ah, I totally forgot I was on nightly. I was doing some miri stuff for finding a leak for a book I'm writting. Thanks!

How did you spot that?

@chrysn
Copy link
Contributor

chrysn commented Jul 25, 2024 via email

@ghenry
Copy link

ghenry commented Jul 25, 2024

Oh, wow. Something hard to forget then! Thanks for replying so quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants