[ 
https://issues.apache.org/jira/browse/THRIFT-2835?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15172058#comment-15172058
 ] 

Aki Sukegawa commented on THRIFT-2835:
--------------------------------------

I've devised a quick overview of what the patch is doing.
If there's no concern, I'll do the rebase and merge.
Any input is appreciated.
(As the next release is imminent, it may be good idea to wait a bit and do it 
right after the release ?)

h3. How it works

When \-gen <lib name> is passed as a compiler command argument, the compiler 
invokes thrift-gen-<lib name> process in the PATH.
It's similar to git commands or protobuf extensions.
It serializes the AST using Thrift binary protocol and passes it to the plugin 
process through stdin.
The plugin executable is responsible for deserializing the Thrift struct then 
generating code.

So basically, the patch is only doing conversion between AST and Thrift struct.
Thrift struct definition can be found 
[here|https://github.com/apache/thrift/pull/368/files#diff-27feb1bc4c6ea2be5d81e9007aeaa229R19].

Slightly off topic, as I see it today, naming styles can be improved.
For example, "t_program" -> "TProgram" or even "Program" since we're in a 
namespace etc.

h3. Future work

The communication between plugin and compiler can be made bi-directional so 
that it can be used to extend existing generators.
I.e., we can selectively replace or insert certain part of code generation.
The current patch is not doing bi-directional because existing generators use 
stdout directly and I wanted plugin implementation to be exactly identical to 
them.
Introducing simple logger interface to existing generators would solve this 
problem.

Another possibility is to use the Thrift IDL as a safety layer for migrating 
core lex/yacc part.
As long as the same Thrift message is constructed, every existing generator 
works out of the box.
To be clear, I'm not advocating such a migration, but just in case.

> Add possibility to distribute generators separately from thrift core, and 
> load them dynamically
> -----------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-2835
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2835
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (General)
>            Reporter: Anatol Pomozov
>              Labels: fbthrift
>
> It is a follow-up for discussion with Facebook's fbthrift 
> https://github.com/facebook/fbthrift/issues/48
> fbthrift adds its own generator that creates C++ classes based on their 
> libraries. I do not know how upstreamable this generator but I think other 
> companies would want to do the same - create their own custom generators.
> Currently there is no way to distribute generators separately from the thrift 
> core. Thus the company have to fork whole project and add their own 
> generator. It is what Facebook did.
> The idea is that thrift should be able to load language generators 
> dynamically. i.e. a company foo creates its own generator and puts it to 
> system /usr/lib/thrift/generators/cpp_foo.so When thrift compiler starts - it 
> checks /usr/lib/thrift/generators/ and uses dlopen() to load the shared 
> libraries. The shared library contains information about the generator (name, 
> options, ...) thus it allows thrift core to use this custom third-party 
> generator.
> This allows companies to create and distribute generator will less pain and 
> no need to fork the project.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to