-
Notifications
You must be signed in to change notification settings - Fork 117
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
Expose toolchain and sysroot to downstream crates #211
Comments
Most, if not all, of the metadata about the build environment of the
To create instances of The esp-idf build script also saves this information to a JSON file in the out dir of the esp-idf-sys crate, though the path to that file is currently not exposed as build script metadata. The |
Hey, Sorry for the delay. We do need to get the sysroot somehow since As an example, after installing the toolchain with let bindings = bindgen::Builder::default()
.header_contents(
"wrapper.h",
r#"
#include <stdint.h>
uint8_t foo(void);
"#,
)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.unwrap(); fails with
|
FWIW, I'm currently working around this by setting a bunch of env variables. Here's an exact copy for some version of the esp-rs toolchains:
Notes:
I place the above at the bottom of the |
That's using the C toolchain downloaded by |
All of the above should be unnecessary. Please use - in your
|
I guess that works, but |
Ah, no, it does not work properly. It ends up pulling in some of the necessary things, but it doesn't pull in the full sysroot and so including e.g. |
I have difficulties believing that, as what you get via |
(... modulo headers for custom components, but these are a separate topic altogether.) |
Look at the link from my previous comment as to how to split it and pass it to bindgen. Not perfect, and might break if the ESP IDF directories contain whitespace (which they shouldn't, as that's not officially supported by ESP IDF), but all in all - a three-liner. |
That's not exatly true, we pass the sysroot and include directory for the sysroot explicitly too, and some other things So I'd recommend, using let bindgen_fact = embuild::bindgen::Factory {
clang_args,
linker: Some(compiler),
mcu: None,
force_cpp: false, // set to true if C++ instead of C
sysroot: None // builder() will try to get the sysroot using `linker`
};
let bindgen = bindgen_fact.builder().expect("creating bindgen builder failed"); You'd have to have some logic to get the correct compiler executable path out of What esp-idf-sys does:
|
But then again, if you're trying to create bindings for C code that uses the esp-idf, it's better to use the extra components mechanism instead. If not, using some custom logic, it is indeed possible to get the
Hope this helps. |
And this is why it would be nice if this was exposed in an explicitly supported and documented manner, because this ends up being rather complicated to do something that's simple if you're not using ESP-IDF. Though it feels like Edit: For the record, we're building C code that is not using ESP-IDF. |
I think what to expose and where the rough edges currently are would be easiest to pinpoint if someone tries to use what we already have, and then show - in actual code - how much the additional overhead is - which then needs to be folded in the form of utility functions in either |
My point isn't that "you guys need to provide a more convenient API", but that "you guys should provide a documented way of doing this thing that I can't figure out how to do." For starters, I don't know what would be the "logic to get the correct compiler executable path out of |
Well, to provide the documentation you are asking for, I have to essentially go back and review the code I (and @N3xed) have written more than a year ago. And in the meantime I'm forgetting it - case in point - the sysroot thing, which I actually implemented in the past - at least for the PIO build. So I still maintain that if you learn the code a bit and then try to use it, it would be more efficient in that we'll know what else to document and where exactly the pain points are. Also, you have a concrete use case at hand which would be driving you. I don't have this use case. Instead, I have a ton of other projects I'm supporting in my free time (just like this one), so lifting the task a bit on your shoulders doesn't sound that wrong to me. |
To be able to build C code and use bindgen it's necessary to have access to an appropriate C toolchain and sysroot. So far it's been possible to get this by using the toolchain downloaded by
espup
, but the plan is for it to stop downloading a toolchain at all oncelld
is capable of taking care of all of the linking.Since
esp-idf-sys
ends up downloading the appropriate C toolchain for building code for the relevant targets it would be convenient if it would expose the appropriate paths to the toolchain and sysroot for downstream crates to use in theirbuild.rs
scripts.This isn't a complete solution since it means that any crates that builds C code would need to depend on this crate to get access to the paths, but at least it would be strictly better than the current situation.
C.f. esp-rs/rust-build#127.
The text was updated successfully, but these errors were encountered: