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

Add macros for include ttrpc gen code #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jokemanfire
Copy link
Contributor

Give macros for more convenient to use, if it is in Default dir

Give macros for more convenient to use, if it is in Default dir

Signed-off-by: jokemanfire <[email protected]>
/// This is only work on out_dir not set.
/// ```rust,ignore
/// mod protocals {
/// include_ttrpc!("helloworld");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how to include helloworld.rs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I think is that this macro only provides the code for *_ttrpc.rs generated by ttrpc-code gen The generated proto's rs code is not within the scope of this macro.

@Tim-Zhang
Copy link
Member

@jokemanfire I have a question, how useful is the development of these API? After all, the more open the API is, the more disadvantageous it is for us to maintain compatibility.

@jokemanfire
Copy link
Contributor Author

jokemanfire commented Jan 15, 2025

@jokemanfire I have a question, how useful is the development of these API? After all, the more open the API is, the more disadvantageous it is for us to maintain compatibility.

What I add is for the interface , "include!(concat!(env!("OUT_DIR"), "/mod.rs"));" is ugly , and is not friendly to caller. In tonic they provide a marco which I think it is useful and more friendly https://github.com/hyperium/tonic/blob/5ad89bf5c2ec651afca73f946fff3ae5b996481c/tonic/src/macros.rs . So i add it.
And I think this interface should be controllable for developers because it is relatively simple in itself.

@Tim-Zhang
Copy link
Member

Tim-Zhang commented Jan 15, 2025

@jokemanfire I have a question, how useful is the development of these API? After all, the more open the API is, the more disadvantageous it is for us to maintain compatibility.

The sentence include!(concat!(env!("OUT_DIR"), "/mod.rs")) is internal and appear only once. So do we really need the macro include_mod?

The macro include_ttrpc is not general for it only works for *_ttrpc.rs in OUT_DIR.

Still I don't think we need these two macros. welcome to discuss, thanks.

@jokemanfire
Copy link
Contributor Author

@jokemanfire I have a question, how useful is the development of these API? After all, the more open the API is, the more disadvantageous it is for us to maintain compatibility.

The sentence include!(concat!(env!("OUT_DIR"), "/mod.rs")) is internal and appear only once. So do we really need the macro include_mod?

The macro include_ttrpc is not general for it only works for *_ttrpc.rs in OUT_DIR.

Still I don't think we need these two macros. welcome to discuss, thanks.

At that time, adding two interfaces was for the convenience of one of my projects, May be we can use

macro_rules! include_ttrpc {
    ($name:expr) => {
        include!(concat!(env!("OUT_DIR"), concat!("/", $name, ".rs")));
    };
}

If it is more greater?

@jokemanfire
Copy link
Contributor Author

This scenario is that I do not want to keep the code generated by codegen, and developers do not need to pay attention to the code generated by ttrpc codegen. At this point, the code is generated in the directory of the OUT_SIR environment variable. Then I want to reference this * _ttrpc.rs code. I have to include a rather ugly code
include!(concat!(env!("OUT_DIR"), "/mod.rs"))
(Newcomers who have just started reading the document know that they need to use include to include it). If this macro is provided, the caller will be more happy to include this file (at least it doesn't look so ugly, at least to me)

@Tim-Zhang
Copy link
Member

Tim-Zhang commented Jan 22, 2025

Firstly, The output dir of generated code may not in env!("OUT_DIR").
Secondly in my opinion include generated files is the job of users, we'd better leave it alone.

Any suggests? @lifupan @teawater

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

Successfully merging this pull request may close these issues.

2 participants