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

Generate Cargo build files and make the crate template more accepting #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jadahl
Copy link

@jadahl jadahl commented Jun 1, 2016

Hi,

Sorry for the catch-all pull request, but with these patches I can generate for example glib, gio and gtk without any special template (though with plenty of compiler warnings still), while also not having to also generate all the other dependencies those would have. I also have them generate the Cargo.toml and a build.rs to build.

In summary, the patches do

  • Adds an option to genaret Cargo.toml and build.rs build file for the -sys crate
  • Makes it so that any typedef/alias that ends up with a va_list gets for now silently ignored (since va_lists are not portable compiler/libc specific)
  • Makes it so that any struct that contains a bitmask becomes an opaque struct (since there is no portable way to determine the width of the resulting mask).
  • Makes it possible to either include a set (default to exclude), or exclude a set (default to include) dependencies when generating a crate. This makes it possible to for example generate the gtk-sys crate without any references to cairo, x11 etc.

Let me know what you think.

jadahl added 7 commits May 5, 2016 14:47
The type must still be a pointer so that for example function arguments
continue to be pointers if they are an array of something.
Use the data available from the gir file to add dependencies. For now
these dependencies are assumed to be placed in the same directory as
the crate itself is place in.
The va_list type cannot be used from Rust, so don't generate any
mapping for functions or aliases that lead to it.
If a struct cannot be mapped because it has bit fields or unions, make
it opaque instead of just ignoring it.
In order to generate a crate without having to also depend on a set of
crates that won't ever be used, add options to include or exclude
crates from being referenced.

Including crates will result in only the crates specified via the
--include option will ever be referenced, and any declaration
referencing any other crate will be excluded from being generated.

Excluding works the other way around, meaning all crates are included,
except the ones specified using the --exclude option.
We need to properly deal with the pkg-config description to manage to
build packages where the GIR package name differs from the pkg-config
package (such as GTK+ 3.0).
Copy link
Member

@mzabaluev mzabaluev left a comment

Choose a reason for hiding this comment

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

Good work overall!

I'd like to think more about versioning for dependency packages: if the .pc specified a certain version number for an introspected library dependency, we'd be interested to map it to a version of the generated crate. The latest idea was to encode crate's major version as the "grust-gen epoch" to allow breaking changes in the generator, and the crate's minor version to equal the minor version of the library package (the package major version is, by convention, encoded in the pkgconfig module name and the crate name derived from it).

@@ -206,11 +207,15 @@ pub struct ${node.ctype}(gpointer);
pub enum ${node.ctype} { }
% else:
#[repr(C)]
% if not mapper.struct_is_valid(node):
pub struct ${node.ctype};
Copy link
Member

Choose a reason for hiding this comment

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

This might work for objects and some boxed types, but I wouldn't like to get unusable types for copyable values. What I did in the few crate-specific templates I created in repo gi-rust/crates is suppress the unmappable structures and place manual representations in the crate template. With support for unions available in stable Rust, there will be less need for these overrides.

Bit fields could be automated too, if there is a equivalent #[repr(C)] guaranteed by the C standard.

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

Successfully merging this pull request may close these issues.

2 participants