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

unable to use type_attribute multiple times #717

Closed
horacimacias opened this issue Jul 12, 2021 · 4 comments
Closed

unable to use type_attribute multiple times #717

horacimacias opened this issue Jul 12, 2021 · 4 comments
Labels
A-build C-bug Category: Something isn't working

Comments

@horacimacias
Copy link

horacimacias commented Jul 12, 2021

Bug Report

I'm building .rs files from .proto files and using type_attribute to add some extra attributes to the .rs files.
Trying to use type_attribute multiple times seems to not work. Only the last type_attribute set is kept.
I'm using the same path on both type attributes; not sure if this is related to the issue or this is a misuse of such method.

Doing the same using tonic-build 0.4 shows the expected behaviour.

Version

tonic-build v0.5.0

Platform

Darwin computer.local 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64

Crates

tonic-build

Description

I tried this code:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    tonic_build::configure()
        .out_dir("proto/helloworld/")
        .type_attribute(".", "// first attribute")
        .type_attribute(".", "// second attribute")
        .build_server(false)
        .compile(
            &["proto/helloworld/helloworld.proto"],
            &["proto/helloworld"],
        )?;
    Ok(())
}

This is a brand new cargo new tonic-build project with only tonic-build as dependency:

[package]
name = "tonic-build"
version = "0.1.0"
edition = "2018"

[dependencies]
tonic-build = "0.5.0"

I expected to see both "// first attribute" and "// second attribute" on the generated code.

Instead, I only see "// second attribute" on the generated code.
If I swap the type_attribute invocations, I only see "// first attribute" and not "// second attribute".

am I doing something wrong? Same code is working on tonic-build 0.4

as a workaround, I'm using something like:

.type_attribute(".", "// first attribute\n// second attribute")
@davidpdrsn davidpdrsn added A-build C-bug Category: Something isn't working labels Jul 12, 2021
@davidpdrsn
Copy link
Member

That appears to be a bug in prost then. Tonic just forwards those attributes directly here. If you use prost-build directly, without tonic-build, does it work as expected?

@horacimacias
Copy link
Author

thanks, and sorry I did not realise that.

Indeed, using the same sample project with prost-build = "0.8.0" dependency shows the same issue, so it does not look like it's caused by tonic.

I'll open an issue on prost.

@horacimacias
Copy link
Author

FYI, issue already existed in prost: tokio-rs/prost#502

@davidpdrsn
Copy link
Member

Thanks! It can sometimes be hard to know where the boundaries is between prost and tonic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build C-bug Category: Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants