Skip to content

tonic_build-based build.rs crashes #1196

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

Closed
soenkehahn opened this issue Sep 1, 2021 · 2 comments
Closed

tonic_build-based build.rs crashes #1196

soenkehahn opened this issue Sep 1, 2021 · 2 comments

Comments

@soenkehahn
Copy link

I tried to use rustc_codegen_cranelift in a project that has a build.rs file using the tonic_build crate. It seems that the compiled build.rs executable is crashing. I put up a repo that reproduces this here: https://github.com/soenkehahn/cranelift-bug. In that repo, cargo build works successfully, but path_to_rustc_codegen_cranelift/build/cargo build does not. I get the following error:

error: failed to run custom build command for `foo v0.0.1 (/home/shahn/cranelift-bug)`

Caused by:
  process didn't exit successfully: `/home/shahn/cranelift-bug/target/debug/build/foo-39185742e3e011c8/build-script-build` (signal: 6, SIGABRT: process abort signal)

Passing in -vvv to get a more informative error message does not yield anything more interesting, as far as I can tell.

I'm using rustc_codegen_cranelift from commit e9eac6bd on linux.

@bjorn3
Copy link
Member

bjorn3 commented Sep 1, 2021

Duplicate of https://github.com/bjorn3/rustc_codegen_cranelift/issues/1101

tl;dr: tonic_build uses proc_macro2 which checks if it runs inside a proc_macro by calling a proc_macro function that panics if it is called outside of a proc macro. cg_clif doesn't yet support catching panics and as such aborts.

You could try adding proc_macro2 as build-dependency and then calling proc_macro2::fallback::force() before tonic_build inside the build script. This will force it to assume that it isn't running inside a proc macro.

@bjorn3 bjorn3 closed this as completed Sep 1, 2021
@soenkehahn
Copy link
Author

I see. Thanks for the explanation. proc_macro2::fallback::force() does the trick. Unfortunately the real project that I was trying to use rustc_codegen_cranelift in, also depends on cssparser, which fails for the same reason (as described in #1101).

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