Skip to content
Merged
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
108 changes: 51 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
# Xdrgen

[![Build Status](https://travis-ci.org/stellar/xdrgen.svg)](https://travis-ci.org/stellar/xdrgen)
[![Code Climate](https://codeclimate.com/github/stellar/xdrgen/badges/gpa.svg)](https://codeclimate.com/github/stellar/xdrgen)

`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 spits code out in
various languages.
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.

`xdrgen` requires ruby 2.1 or later to run.
`xdrgen` requires ruby 3.1 to 3.3 to run.

## Status

Xdrgen is a very early project. Aside from the test fixtures in
[spec/fixtures](spec/fixtures), the only .x files that have been thrown at it
are the .x files used for the
[stellar-core project](https://github.com/stellar/stellar-core).

Xdrgen presently supports these output languages: ruby, javacript, java,
golang, elixir and Python:

- ruby: complete support
- javascript: complete support
- java: complete support
- golang: currently using a fork of go-xdr, but has complete support
- rust: support is experimental. Default arms and floats are not supported.
- 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
- Python: complete support

Testing is _very_ sparse, but will improve over time.

## Usage as a binary

Xdrgen is a rubygem, compatible with ruby 2.1 or higher

$ gem install xdrgen

The command line:

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

### Language Specific Options
Xdrgen is an early project but also relatively stable and major changes have
not been made to the library for sometime.

### Rust
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).

`--rust-types-custom-str-impl`: Used to specify a comma-separated list of type names that should not have string conversion code generated as it will be provided by custom implementations provided by the developer using the generated code.
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.

## Usage as a library

Expand All @@ -57,36 +30,57 @@ gem 'xdrgen'

And then execute:

$ bundle
```
$ bundle
```

Example usage:

```ruby
require 'xdrgen'
Copy link
Member Author

Choose a reason for hiding this comment

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

Telling folks to use the gem as published on xdrgen doesn't really work today because this library hasn't been released to rubygems since 2021 and the released version doesn't have features like the custom generator.

I'm working with ops to get this repo setup to be able to publish again:

Copy link
Member Author

Choose a reason for hiding this comment

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


# create a compilation object, specifying your options
class Generator < Xdrgen::Generators::Base
def generate
out = @output.open("#{@namespace}.rs")
# Use @top to access the top of the AST.
# Use @options to access any options passed via the compile.
# Use out.puts to write code.
end
end

c = Xdrgen::Compilation.new(
Xdrgen::Compilation.new(
["MyProgram.x"],
output_dir:"src/generated",
language: :ruby,
generator: Generator,
namespace: "MyProgram::XDR",
options: {
rust_types_custom_str_impl: [],
rust_types_custom_jsonschema_impl: [],
},
)
options: { }, # any option your generator needs
).compile
```

# then run compile
## Usage as a binary (legacy)

c.compile
Xdrgen is a rubygem, compatible with ruby 2.1 or higher

```
$ gem install xdrgen

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.

- ruby: complete support
- javascript: complete support
- java: 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
- Python: complete support

## Contributing
## Contributing new generators / languages

1. Fork it ( https://github.com/[my-github-username]/xdrgen/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
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.