Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@

`xdrgen` is a code generator that takes XDR IDL files (`.x` files) as specified
in [RFC 4506](http://tools.ietf.org/html/rfc4506.html) and provides the AST to
code generators. It can be used as a library with custom generators, or for
legacy purposes as a CLI with any of the built-in legacy generators.
code generators. It is intended to be used as a library with custom generators.

`xdrgen` requires ruby 3.1 to 3.3 to run.

## Status

Xdrgen is an early project but also relatively stable and major changes have
not been made to the library for sometime.
Xdrgen is a relatively stable library and major changes have not been made to
it for sometime.

Aside from the test fixtures in [spec/fixtures](spec/fixtures), the only .x
files that have been tested with it are the .x files used for the [Stellar
protocol](https://github.com/stellar/stellar-xdr).

If you're building a new code generator, the preferred way to provide a code
generator to xdrgen is to use it as a library. See below for examples for how
to do so.
> [!NOTE]
> **Generators are no longer maintained in this repository.**
>
> If you're building a code generator, use xdrgen as a library (see below).
>
> Generators that were previously included (Python, Java, Rust) have been moved
> out to other repositories close to the Stellar XDR libraries they generated.
> This happened in https://github.com/stellar/xdrgen/pull/226 and
> https://github.com/stellar/xdrgen/pull/221.
>
> For any that were not moved but deleted (C#, Elixir, Ruby), they can be found
> in the repository history at commit
> [2efacde](https://github.com/stellar/xdrgen/tree/2efacde612445d97e0548131ed699e8130bdeb7b)
> if they need to be used with the binary, otherwise any new maintenance of code
> generators should happen using xdrgen as a library.
>
> The JavaScript and Go generators still live here at this time.

## Usage as a library

Expand Down Expand Up @@ -67,18 +80,7 @@ The command line:

`xdrgen [-o OUTPUT_DIR] [-l LANGUAGE] [-n NAMESPACE] [INPUT_FILES ...]`

Xdrgen has support for built-in generators via the CLI's `-l` option, but they
are not maintained, not tested, and are preserved for legacy usage.
The CLI still has the following built-in generators:

- ruby: complete support
- javascript: complete support
- golang: currently using a fork of go-xdr, but has complete support
- elixir: support is experimental as the SDK is in early development. Generated
code requires [:exdr](https://github.com/revelrylabs/exdr) in your deps
- C#: complete support

## Contributing new generators / languages

Instead of contributing new generators to this repository, use xdrgen as a
library and maintain the generator independently where you can test and
maintain it.
- javascript
- golang
4 changes: 2 additions & 2 deletions lib/xdrgen/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module CLI
def self.run(args)
args = args.dup
opts = Slop.parse! args do
banner 'Usage: xdrgen -o OUTPUT_DIR INPUT --language=ruby'
banner 'Usage: xdrgen -o OUTPUT_DIR INPUT --language=javascript'
on 'o', 'output=', 'The output directory'
on 'l', 'language=', 'The output language', default: 'ruby'
on 'l', 'language=', 'The output language', default: 'javascript'
on 'n', 'namespace=', '"namespace" to generate code within (language-specific)'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/xdrgen/compilation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Xdrgen
class Compilation
extend Memoist

def initialize(source_paths, output_dir:".", language: :ruby, generator: nil, namespace: nil, options: {})
def initialize(source_paths, output_dir:".", language: nil, generator: nil, namespace: nil, options: {})
raise "An empty list of source paths (.x files) provided. At least one source file must be provided to compile." if source_paths.empty?
@source_paths = source_paths
@output_dir = output_dir
Expand Down
3 changes: 0 additions & 3 deletions lib/xdrgen/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ module Xdrgen::Generators
extend ActiveSupport::Autoload

autoload :Base
autoload :Ruby
autoload :Go
autoload :Javascript
autoload :Elixir
autoload :Csharp

def self.for_language(language)
const_get language.to_s.classify
Expand Down
Loading