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

how to generate cpp2 client/server source files of fbthrift? #303

Closed
IvanJobs opened this issue Nov 2, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@IvanJobs
Copy link

commented Nov 2, 2018

Hi guys,
Anyway, I used python module thrift_compiler to generate cpp2 source files, but it seemed not right.
Generated by command:

/usr/bin/python -mthrift_compiler.main --gen cpp2 kv.thrift

Generated files looks like the below, seems wrong:

root@d30f24e6439e# ls -lh gen-cpp2
-rw-r--r-- 1 root root 4.2K Nov  2 11:00 kv_fatal.h
-rw-r--r-- 1 root root  248 Nov  2 11:00 kv_fatal_all.h
-rw-r--r-- 1 root root  212 Nov  2 11:00 kv_fatal_constant.h
-rw-r--r-- 1 root root  282 Nov  2 11:00 kv_fatal_enum.h
-rw-r--r-- 1 root root  275 Nov  2 11:00 kv_fatal_service.h
-rw-r--r-- 1 root root  11K Nov  2 11:00 kv_fatal_struct.h
-rw-r--r-- 1 root root  220 Nov  2 11:00 kv_fatal_types.h
-rw-r--r-- 1 root root  322 Nov  2 11:00 kv_fatal_union.h

There were such a few lines of code there, but I defined a total service in kv.thrift, what's the problem?

BTW, it's really hard to make thrift_compiler module work, I spend tons of hours to search the internet and to try. Is there any easy to make fbthrift work for CXX programmers?

@stevegury

This comment has been minimized.

Copy link
Contributor

commented Nov 6, 2018

You should build the thrift compiler like indicated in the README.md, then call the generated binary like this:

./build/bin/thrift1 --gen mstch_cpp2 --templates ./thrift/compiler/generate/templates --out /tmp/ ./thrift/example/if/chatroom.thrift
$ ll /tmp/thrift_test/
total 224K
-rw-r--r-- 1 stevegury  285 Nov  6 10:48 chatroom_constants.cpp
-rw-r--r-- 1 stevegury  340 Nov  6 10:48 chatroom_constants.h
-rw-r--r-- 1 stevegury  180 Nov  6 10:48 chatroom_data.cpp
-rw-r--r-- 1 stevegury  266 Nov  6 10:48 chatroom_data.h
-rw-r--r-- 1 stevegury  26K Nov  6 10:48 ChatRoomServiceAsyncClient.cpp
-rw-r--r-- 1 stevegury 8.3K Nov  6 10:48 ChatRoomServiceAsyncClient.h
-rw-r--r-- 1 stevegury 6.4K Nov  6 10:48 ChatRoomService.cpp
-rw-r--r-- 1 stevegury  543 Nov  6 10:48 ChatRoomService_custom_protocol.h
-rw-r--r-- 1 stevegury 9.3K Nov  6 10:48 ChatRoomService.h
-rw-r--r-- 1 stevegury  366 Nov  6 10:48 ChatRoomService_processmap_binary.cpp
-rw-r--r-- 1 stevegury  366 Nov  6 10:48 ChatRoomService_processmap_compact.cpp
-rw-r--r-- 1 stevegury  16K Nov  6 10:48 ChatRoomService.tcc
-rw-r--r-- 1 stevegury  15K Nov  6 10:48 chatroom_types.cpp
-rw-r--r-- 1 stevegury  471 Nov  6 10:48 chatroom_types_custom_protocol.h
-rw-r--r-- 1 stevegury  28K Nov  6 10:48 chatroom_types.h
-rw-r--r-- 1 stevegury  23K Nov  6 10:48 chatroom_types.tcc
-rw-r--r-- 1 stevegury 8.3K Nov  6 10:48 EchoAsyncClient.cpp
-rw-r--r-- 1 stevegury 3.1K Nov  6 10:48 EchoAsyncClient.h
-rw-r--r-- 1 stevegury 3.4K Nov  6 10:48 Echo.cpp
-rw-r--r-- 1 stevegury  532 Nov  6 10:48 Echo_custom_protocol.h
-rw-r--r-- 1 stevegury 4.9K Nov  6 10:48 Echo.h
-rw-r--r-- 1 stevegury  344 Nov  6 10:48 Echo_processmap_binary.cpp
-rw-r--r-- 1 stevegury  344 Nov  6 10:48 Echo_processmap_compact.cpp
-rw-r--r-- 1 stevegury 5.0K Nov  6 10:48 Echo.tcc
@IvanJobs

This comment has been minimized.

Copy link
Author

commented Nov 7, 2018

@stevegury thanks a lot, it works. sorry for not looking deeply into the README file.

@IvanJobs IvanJobs closed this Nov 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.