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

Adding bindgen to build-dependencies prevents crate from being no_std #1439

Closed
aleksanb opened this issue Nov 11, 2018 · 3 comments
Closed

Comments

@aleksanb
Copy link

This doesn't really seem intentional, although this might be more of a cargo issue than a bindgen issue.

Minimal example that doesn't work when you add bindgen to build-rependencies:
main.rs:

#![feature(lang_items, start)]
#![no_std]

use core::panic::PanicInfo;
use libc;

#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! { 
    loop {}
}

#[lang = "eh_personality"]
extern "C" fn eh_personality() {}

#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
    0   
}

Cargo.toml:

[package]
name = "yolo"
version = "0.1.0"
authors = ["aleksanb"]
edition = "2018"

[dependencies]
libc = {version = "0.2.*", default-features = false}

[build-dependencies]
bindgen = "*"

I used to invoke bindgen via the shell, which would work fine with my no_std crate, but using it in a build.rs prevents me from using no_std at all.

@emilio
Copy link
Contributor

emilio commented Nov 11, 2018

Hmm, this definitely used to work. This looks to have regressed because a few of the bindgen dependencies use libc with the default features, and cargo only knows about a single dependency graph.

emilio added a commit to emilio/clang-sys that referenced this issue Nov 11, 2018
It's not needed, and prevents some bindgen users from being able to run bindgen
at build time in no_std crates, see:

  rust-lang/rust-bindgen#1439
@emilio
Copy link
Contributor

emilio commented Nov 11, 2018

So this is fixable to some extent, by going through bindgen's dependencies and ensuring that libc isn't built with default features. I just checked and it can be done for some, like clang-sys (KyleMayes/clang-sys#85).

Probably we can do the same for all others, or find a way to remove that dependency using a bindgen feature or what not. I cannot commit to do all the work, though I'm happy to help if I find time :)

In any case this is rust-lang/cargo#2589.

bcmyers added a commit to bcmyers/num-format that referenced this issue Feb 11, 2019
@emilio
Copy link
Contributor

emilio commented Feb 23, 2019

I don't think there's something actionable here on bindgen's side, but please reopen if you think otherwise.

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

2 participants