Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Implement the generator #1

Open
mzabaluev opened this issue Apr 7, 2013 · 9 comments
Open

Implement the generator #1

mzabaluev opened this issue Apr 7, 2013 · 9 comments
Assignees

Comments

@mzabaluev
Copy link
Member

We need a GIR-to-Rust code generator to automate most of the dirty work.

@mstewartgallus
Copy link

How are we going to read, and process the GIR files? We should probable focus on using an XML library which is easy to use rather than blazing fast because GIR files aren't going to be processed that often (only at compile-time.)

As I understand the situation there are no existing bindings to XML parsers for Rust, and we'd have to write our own. Luckily, there is https://github.com/crabtw/rust-bindgen which could help out a bit. I don't have any preference towards any XML libraries in particular so I'd appreciate some input.

Alternatively, we could write the binding generator in a different language from Rust. This seems like a bad idea to me though because deciding on a proper language would be difficult.

There has been some work towards dynamically loadable compiler plugins but it is still very preliminary. I think the best idea would be to have a program which generates the bindings.

@mzabaluev
Copy link
Member Author

My idea is to take the Python generator from gobject-introspection and modify or extend it to generate Rust.

@mstewartgallus
Copy link

@mzabaluev Right, that'd be a sensible approach.

@mstewartgallus
Copy link

So I chatted on Gnome's IRC channel for introspection, and apparently the typelib libraries don't expose enough information to create static bindings. I think we'll have to parse the GIR files ourselves like Vala does.

@fabiand
Copy link

fabiand commented Jul 9, 2013

I wonder if an xslt sheet could be used to transform the gir into something usable.
Is e.g. the gio.rc file such a target we are looking for?

@mzabaluev
Copy link
Member Author

Yes, the files under fauxgen are meant to test out the eventually generated bindings.

I have mixed experience with XSLT; it's good for basic transformations, but the trouble begins when your needs exceed the standard feature set. The output is not XML, which tends to make XSLT rules cumbersome.
I'm more inclined to write the generator in Python. GObject-introspection already has a Python generator to use as a template, or even a base class.
I plan to give the generator some time over the next 1.5 weeks.

@ghost ghost assigned mzabaluev Jul 11, 2013
@mstewartgallus
Copy link

I've been spending a while trying to write bindings to libxml2 for Rust, and it's been very painful so far. I've already had experience generating Rust code from Python to create asset data (see http://gitorious.org/p-x/p-x/trees/master/pX-x_assets), and it has been quite fun, and elegant so far. I would support the use of Python to write the generator.

@sp3d
Copy link

sp3d commented Aug 14, 2013

What information is missing from Typelib libraries? Looking at it a bit, it seems that information about whether integers are "system-sized" or a fixed number of bits may be elided, as well as information about aliases. Are these critical omissions, or is there something else fundamental which isn't wrapped? Could we submit patches upstream that would make the typelib libraries sufficient for generating static bindings?

In my mind, it's nonsense to have a library for working with GIR data but also require half of the users of the data to roll their own alternative.

@mzabaluev
Copy link
Member Author

I have started a code generator in Python in the codegen branch. The modules girparser and ast of gobject-introspection are really helpful in getting at GIR XML data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants