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

prost_build does not work on no_std #344

Closed
benma opened this issue Jun 21, 2020 · 4 comments
Closed

prost_build does not work on no_std #344

benma opened this issue Jun 21, 2020 · 4 comments

Comments

@benma
Copy link

benma commented Jun 21, 2020

Hi

I am trying to use prost in a no_std target. Everything works great, except that build.rs, which uses prost_build::compile_protos, does not work as it relies on std:

error[E0463]: can't find crate for `std`
 --> src/vendor/getrandom/src/error_impls.rs:8:1
  |
8 | extern crate std;
  | ^^^^^^^^^^^^^^^^^ can't find crate
  |

(via prost-build -> tempfile -> rand -> getrandom).

The funny thing is that compiling the .proto files does not actually depend on my target, as it's a build-step and could be done on std.

In fact this is how I currently work around it: I can compile the .proto files fine if I compile my project on a standard std target, and then copy the resulting .rs files from the build directory and add it directly to my project.

It would be really good to fix up prost-build to run on no_std also, OR to provide a CLI tool which I can run to manually generate the .rs file outside of build.rs.

@danburkert
Copy link
Collaborator

I assume you are using unreleased prost from git? Anyway, this is more-or-less expected. I don't do much no-std work with Rust, but my understanding was that most of the time you cross-compiled to the target platform, as getting rustc and/or cargo to run in the no-std environments was next to impossible. When cross-compiling I don't think it should matter that a build dependency requires std?

@benma
Copy link
Author

benma commented Jun 23, 2020

I assume you are using unreleased prost from git?

Yes exactly.

When cross-compiling I don't think it should matter that a build dependency requires std?

This is what I expected, and yet it seems that build.rs also uses no_std if I cross compile to a no_std target, somehow.

Anyway, in this case I guess I'll close this and just use a handrolled CLI tool that calls prost_build::compile_protos(), and run this outside of Rust's build.rs infrastructure. Thanks.

@benma benma closed this as completed Jun 23, 2020
@benma
Copy link
Author

benma commented Jun 28, 2020

When cross-compiling I don't think it should matter that a build dependency requires std?

This is what I expected, and yet it seems that build.rs also uses no_std if I cross compile to a no_std target, somehow.

For the record, this is a bug and tracked here:

rust-lang/cargo#7915

It is resolved on nightly with an unstable feature. Let's hope it will stabilize soon.

@dzimmanck
Copy link

I am also experiencing this issue. I am trying to use prost in an embedded application (ARM M4), and have to build the data structures in a separate script. The issue is still there with nightly. Do I need something special in my Cargo.toml file to tell Cargo it can use std in the build dependencies?

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

3 participants