LinuxCommandLibrary

thrift

TLDR

Generate code for a specific language from a Thrift file

$ thrift --gen [language] [file.thrift]
copy
Generate code in a specific output directory
$ thrift --gen [language] -o [output_directory] [file.thrift]
copy
Generate code with language-specific options
$ thrift --gen [language]:key1=val1,key2=val2 [file.thrift]
copy
Generate code including all referenced Thrift files
$ thrift -r --gen [language] [file.thrift]
copy
Add include search paths for Thrift imports
$ thrift -I [include_dir] --gen [language] [file.thrift]
copy
List all available generators
$ thrift --help
copy

SYNOPSIS

thrift [-o dir] [-out dir] [-I dir] [-nowarn] [-strict] [-v] [-r] [-debug] --gen lang[:options] file.thrift

DESCRIPTION

thrift is the compiler for Apache Thrift, a framework for scalable cross-language services development. It combines a software stack with a code generation engine to build efficient and seamless services between languages like C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, JavaScript, Node.js, and more.
The compiler reads a Thrift Interface Definition Language (IDL) file containing struct and service definitions, then generates language-specific implementation code. This enables developers to define data types and service interfaces once and generate the boilerplate code for multiple programming languages.
Common generators include: cpp, java, py, rb, php, js, go, rs (Rust), swift, and many others. Run thrift without arguments to see all available generators for your installation.

PARAMETERS

--gen lang[:key=val,...]

Generate code with the specified generator. Language options can be passed as comma-separated key=value pairs.
-o dir
Set the output directory for gen-* packages. Default is the current directory.
-out dir
Set the output location directly without creating a gen-* folder.
-I dir
Add a directory to search for include directives. Can be specified multiple times.
-r, --recurse
Also generate code for included Thrift files recursively.
-nowarn
Suppress all compiler warnings.
-strict
Enable strict compiler warnings.
-v, --verbose
Enable verbose output mode.
-debug
Print parse debug trace to stdout.
-version
Print the compiler version and exit.

CAVEATS

Generated code structure and options vary significantly between language generators. Some generators may require additional runtime libraries to be installed. The -nowarn flag is generally discouraged as it can hide important compatibility issues.

HISTORY

Apache Thrift was originally developed at Facebook in 2007 and was open-sourced in April 2008. It became an Apache Incubator project in May 2008 and graduated to a top-level Apache project in October 2010. The framework was designed to enable efficient and reliable communication across programming languages at scale.

SEE ALSO

protoc(1), grpc(1)

Copied to clipboard