Crates.io | gbuild |
lib.rs | gbuild |
version | 0.1.0 |
source | src |
created_at | 2021-05-23 13:03:59.535262 |
updated_at | 2021-05-23 13:03:59.535262 |
description | A build-time dependency for Cargo build scripts to enable easy integration with glib/gio/gtk non-compile build tasks. For now it only supports bundling data files using GResource. |
homepage | https://github.com/kov/gbuild |
repository | https://github.com/kov/gbuild |
max_upload_size | |
id | 401097 |
size | 8,237 |
A library to perform the usual non-compile build tasks on glib/gio/gtk-based libray and applications.
Right now it only supports embedding gio GResources into the final binary.
First, you'll want to both add a build script for your crate (build.rs
) and
also add this crate to your Cargo.toml
via:
[build-dependencies]
gbuild = "0.1"
Next up, you'll want to write a build script like so:
// build.rs
fn main() {
gbuild::Resource::builder()
.src_dir("src")
.definition_file("src/br.kov.duplikat.gresource.xml")
.build()
.expect("Bad arguments for gresource compilation")
.compile();
}
That will generate the .c
file from the xml
description, build it, and it will
be linked into your rust binary, making it possible to use resources from your
code without any further registration like this, for instance:
fn load_readme() -> Result<String, String>
let gfile = gio::File::for_uri("resource:///br/kov/duplikat/README");
match gfile.load_contents(gio::NONE_CANCELLABLE) {
Ok((bytes, _string)) => {
std::str::from_utf8(&bytes).unwrap().to_string()
},
Err(e) => format!("Could not load test file: {}", e),
}
This crate uses the pkg-config
binary (not the crate) to obtain the flags for
including and linking gio-2.0
, so it will be affected by any environment variable
that affects pkg-config
.
For building the resulting C file, this crate uses the cc
crate,
which can also be affected by various environment variables. Do note that at the moment
this crate will replace any existing CFLAGS
variable with its own while building the
resources c
file.
This project is licensed under the MIT license, see the (LICENSE file.