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

--use-core bindings refers std #1015

Closed
pepyakin opened this issue Sep 22, 2017 · 9 comments
Closed

--use-core bindings refers std #1015

pepyakin opened this issue Sep 22, 2017 · 9 comments

Comments

@pepyakin
Copy link
Contributor

pepyakin commented Sep 22, 2017

Input C/C++ Header

// bindgen-flags: --impl-debug --use-core --raw-line "extern crate core;"

class C {
    bool a: 1;
    bool b: 7;
    int large_array[50];
};

Bindgen Invocation

See bindgen-flags above

Actual Results

// ... stripped

extern crate core;

#[repr(C)]
#[derive(Copy)]
pub struct C {
    pub _bitfield_1: u8,
    pub large_array: [::std::os::raw::c_int; 50usize]
}

// stripped ...

Expected Results

Despite that --use-core flag is provided large_array field having a type which refers std.
I expect that either error is printed stating that bindings couldn't be generated with --use-core or bindings which don't use std generated.

@fitzgen
Copy link
Member

fitzgen commented Sep 22, 2017

Nice catch!

I expect the fix for this is really easy (just forgetting to look at the prefix and emitting std regardless somewhere in src/codegen/mod.rs), but I hesitate marking it E-easy without being able to add clear instructions on how to fix this. Needs a little bit of investigation, so marking it E-less-easy.

@emilio
Copy link
Contributor

emilio commented Sep 24, 2017

This is working as expected, --use-core doesn't replace std, since it doesn't include them. You need to manually point to somewhere, e.g., libc, using --ctypes-prefix.

Worth pointing it out in the FAQ or something though, I guess.

@joshlf
Copy link
Contributor

joshlf commented Jul 29, 2018

To clarify: The issue is that some types are present in std and not in core, and thus --use-core has to still rely on std for those types? Would it be feasible to add the offending types to core to fix this problem?

@emilio
Copy link
Contributor

emilio commented Jul 29, 2018

Either that, or using the --ctypes-prefix option, which is meant just for that. I'm not sure the c_* types are meant to be in core.

@emilio
Copy link
Contributor

emilio commented Jul 29, 2018

Closing per #1015 (comment), since as things stand ctypes-prefix should be used. If rust puts the ctypes in core, then another issue can be opened to make bindgen adapt to that.

@emilio emilio closed this as completed Jul 29, 2018
@joshlf
Copy link
Contributor

joshlf commented Jul 29, 2018

If these types aren't in core, what would we pass to ctypes-prefix?

Also, I've asked about moving them to core.

@emilio
Copy link
Contributor

emilio commented Jul 30, 2018

You should pass, e.g., libc, to use the libc crate, or a module / crate of your own that defines the needed types for the target architecture.

Though usually you'd want libc, I suspect.

@coffeenotfound
Copy link

The description of --use-core is "Use types from Rust core instead of std."
If it doesn't do that how in gods name is it "working as intended". What does it do?

@emilio
Copy link
Contributor

emilio commented Dec 28, 2020

Well, there is not (or didn't use to be at least) any alternative for std::os::raw::c_* types in core, so it's not clear to me what output do you expect?

We provide an option to not use std types for those and use a crate or module of your choice. Maybe the description should include "when possible" or something.

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

No branches or pull requests

6 participants
@fitzgen @joshlf @emilio @pepyakin @coffeenotfound and others