Comments (14)
Hey @kevingzhang, rustfmt can be disabled with a feature flag on tonic-build. You can turn it off like so:
[build-dependencies]
tonic-build = { git = "https://github.com/hyperium/tonic", default-features = false, features = ["transport"] }
Replae git = "",
with version = ""
if you're using a release from crates.io!
from tonic.
BTW, Tower-gRPC compile and works fine. since it doesn't require rustfmt.
so the worst case I can use Tower-gRPC instead going all the way back to Hyper. :)
from tonic.
thanks, it works !!
from tonic.
Yeah, the one issue with not rustfmting the code is that you get super super super nasty errors since it puts all the code into one line and the compiler cant figure out how to show it.
from tonic.
Alternatively, can tonic import rustfmt as a library and do the text processing at string-build-time instead of calling the external cli tool? Maybe that has tradeoffs, but at least then consumers of this library who do not want or cannot install rustfmt can get nice error messages.
from tonic.
@xmclark last I checked that was not possible, or I couldn't figure it out. If someone could figure that out that would be amazing!
from tonic.
I have done that in another crate of mine.
#[cfg(feature = "rustfmt")]
fn format(input_rust_code: String) -> Option<String> {
use rustfmt_nightly::{Config, Input, Session};
let mut config = Config::default();
config.set().emit_mode(rustfmt_nightly::EmitMode::Stdout);
config.set().verbose(rustfmt_nightly::Verbosity::Quiet);
let mut out = Vec::with_capacity(input_rust_code.len() * 2);
let r = Session::new(config, Some(&mut out)).format(Input::Text(input_rust_code));
match r {
Err(e) => {
format_err!("rustfmt error: {:?}", e);
None
}
_ => match out.len() {
0 => None,
// Unwrap should be safe here, rustfmt generates utf8 only
_ => Some(String::from_utf8(out).unwrap()),
},
}
}
from tonic.
@davidgraeff can this code run on stable?
from tonic.
To be honest, I don't know. Because of the current async situation in the rust ecosystem I'm on rust nightly. I haven't found a toolchain file in their repo, so I assume it works on stable, but also haven't checked their dependencies.
from tonic.
Yeah, unfortunately, this depends on unstable nightly features :(
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /Users/lucio/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-graphviz-606.0.0/lib.rs:277:1
|
277 | #![feature(rustc_private, nll)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /Users/lucio/.cargo/registry/src/github.com-1ecc6299db9ec823/smallvec-0.6.10/lib.rs:33:32
|
33 | #![cfg_attr(feature = "union", feature(untagged_unions))]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /Users/lucio/.cargo/registry/src/github.com-1ecc6299db9ec823/smallvec-0.6.10/lib.rs:35:37
|
35 | #![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
from tonic.
I encounter a same situation.
I'm using yocto with meta-rust-bin to build rust application. a rustfmt doesn't exist in meta-rust-bin.
Although I can disable rustfmt feature for yocto build, but it will also disabled in normal development environment.
I think there is no way to set to use "rustfmt" in development environment, and no "rustfmt" when build for yocto ( build script is built for HOST same like the development environment )
from tonic.
I am not familiar with yocto but is it possible to pass a feature flag to the create that contains tonic build? that way you can do something like:
[features]
fmt = ["tonic-build/rustfmt"]
then you can build it with
cargo build --features fmt
from tonic.
I am not familiar with yocto but is it possible to pass a feature flag to the create that contains tonic build? that way you can do something like:
[features] fmt = ["tonic-build/rustfmt"]then you can build it with
cargo build --features fmt
I mean meta-rust-bin doesn't include a rustfmt, so I had to disable fmt feature, not enable it.
from tonic.
I am not familiar with yocto but is it possible to pass a feature flag to the create that contains tonic build? that way you can do something like:
[features] fmt = ["tonic-build/rustfmt"]then you can build it with
cargo build --features fmtI mean meta-rust-bin doesn't include a rustfmt, so I had to disable fmt feature, not enable it.
I encountered the same issue with yocto. However, I'm using meta-rust
which should have rustfmt
. Yet somehow it complains about rustfmt
missing. I couldn't figure out a way to configure yocto to work. Eventually, I found that it works if you just disable format using configure
. That is, change build.rs
to the following instead of using tonic_build::compile_protos("proto/helloworld.proto")?;
like in the example.
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.format(false)
.compile(
&["proto/helloworld.proto"],
&["proto/"],
)?;
Ok(())
}
The side-effect is of course all generated code in one line.
from tonic.
Related Issues (20)
- Make the TimeoutExpired a public tonic type rather than a transport type
- tonic_build clone server
- long headers from the server hang tonic HOT 5
- Non-Anonymous Authentication
- The trait `Message` is not implemented HOT 1
- Remove trait bound on generated server struct
- NamedService makes it impossible to wrap individual services with non-intercept layers HOT 2
- After tonic is updated from 0.8.3 to 0.11.0 in the csi driver, an error message "PROTOCOL_ERROR" is displayed when kubelet calls the get_info interface.
- Share tonic server port with other http routes HOT 3
- Protobuf bytes field incorrectly parsed as String when generating gRPC code with tonic_build HOT 1
- tonic-build can no longer build code with rust < 1.77.0, due to newer build-script syntax HOT 1
- Tonic v0.13 fails to build what worked on v0.12
- The tonic server process exit unexpected when the client get a wrong tls config HOT 3
- Implement prost::Name for message types
- 0.12 reports invalid cert where 0.11 succeeded HOT 4
- Version 12.2 still doesn't support rustc < 1.77.0
- `tonic-health` required services
- envoy wasm-proxy send grpc message to tonic server failed
- Calling ClientTlsConfig::with_enabled_roots deletes any previous config
- Handling error layer / converting fallible services/layers to infallible
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tonic.