Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move gio::compile_resources to its own crate #670

Merged
merged 1 commit into from May 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Expand Up @@ -116,6 +116,8 @@ jobs:
- name: Check two levels glib dependent
run: cargo check
working-directory: tests/two-levels-glib-dependent
- name: "glib-build-tools: build"
run: cargo build --manifest-path glib-build-tools/Cargo.toml
# examples
- name: "examples"
run: cargo build --manifest-path examples/Cargo.toml --bins --examples --all-features
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Expand Up @@ -38,7 +38,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: doc
args: -p cairo-rs -p cairo-sys-rs -p gdk-pixbuf -p gdk-pixbuf-sys -p gio -p gio-sys -p glib -p gobject-sys -p glib-sys -p glib-macros -p graphene-rs -p graphene-sys -p pango -p pango-sys -p pangocairo -p pangocairo-sys --features dox --no-deps
args: -p cairo-rs -p cairo-sys-rs -p gdk-pixbuf -p gdk-pixbuf-sys -p gio -p gio-sys -p glib -p gobject-sys -p glib-sys -p glib-macros -p glib-build-tools -p graphene-rs -p graphene-sys -p pango -p pango-sys -p pangocairo -p pangocairo-sys --features dox --no-deps
- run: echo "RELEASE=$(echo '${{ github.event.release.tag_name }}' | grep -Po '(\d+)\.(\d+)')" >> ${GITHUB_ENV}
- run: echo "DEST=$(if [ "$GITHUB_EVENT_NAME" == "release" ]; then echo 'stable/${{ env.RELEASE }}'; else echo 'git'; fi)" >> ${GITHUB_ENV}
- name: Grab gtk-rs LOGO
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/windows.yml
Expand Up @@ -74,6 +74,7 @@ jobs:
- { name: "gdk-pixbuf", test: true, args: "--features v2_40" }
- { name: "gio", test: true, args: "--features v2_66" }
- { name: "glib", test: true, args: "--features v2_66" }
- { name: "glib-build-tools", test: false, args: "--features dox" }
- { name: "graphene", test: false, args: "" }
- { name: "pango", test: true, args: "--features v1_46" }
- { name: "pangocairo", test: true, args: "" }
Expand Down Expand Up @@ -117,7 +118,7 @@ jobs:
with:
command: test
args: --manifest-path ${{ matrix.conf.name }}/sys/Cargo.toml ${{ matrix.conf.args }}
if: matrix.conf.name != 'examples'
if: matrix.conf.name != 'examples' && matrix.conf.name != 'glib-build-tools'

- name: build
uses: actions-rs/cargo@v1
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -6,6 +6,7 @@ members = [
"gdk-pixbuf/sys",
"gio",
"gio/sys",
"glib-build-tools",
"glib",
"glib/gobject-sys",
"glib/sys",
Expand Down
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Expand Up @@ -20,8 +20,8 @@ path = "../gio"
version = "0.11"
optional = true

[build-dependencies.gio]
path = "../gio"
[build-dependencies.glib-build-tools]
path = "../glib-build-tools"


[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion examples/build.rs
@@ -1,5 +1,5 @@
fn main() {
gio::compile_resources(
glib_build_tools::compile_resources(
"resources",
"resources/resources.gresource.xml",
"compiled.gresource",
Expand Down
2 changes: 1 addition & 1 deletion gio/src/lib.rs
Expand Up @@ -63,7 +63,7 @@ pub use crate::pollable_input_stream::InputStreamAsyncRead;
mod pollable_output_stream;
pub use crate::pollable_output_stream::OutputStreamAsyncWrite;
mod resource;
pub use crate::resource::{compile_resources, resources_register_include_impl};
pub use crate::resource::resources_register_include_impl;
mod settings;
pub use crate::settings::BindingBuilder;
mod simple_proxy_resolver;
Expand Down
49 changes: 1 addition & 48 deletions gio/src/resource.rs
Expand Up @@ -2,10 +2,7 @@

use crate::{resources_register, Resource};
use glib::translate::*;
use std::env;
use std::mem;
use std::path::Path;
use std::process::Command;
use std::ptr;

impl Resource {
Expand All @@ -32,50 +29,6 @@ impl Resource {
}
}

// rustdoc-stripper-ignore-next
/// Call from build script to run `glib-compile-resources` to generate compiled gresources to embed
/// in binary with [resources_register_include]. `target` is relative to `OUT_DIR`.
///
/// ```no_run
/// gio::compile_resources(
/// "resources",
/// "resources/resources.gresource.xml",
/// "compiled.gresource",
/// );
/// ```
pub fn compile_resources<P: AsRef<Path>>(source_dir: P, gresource: &str, target: &str) {
let out_dir = env::var("OUT_DIR").unwrap();

let status = Command::new("glib-compile-resources")
.arg("--sourcedir")
.arg(source_dir.as_ref())
.arg("--target")
.arg(&format!("{}/{}", out_dir, target))
.arg(gresource)
.status()
.unwrap();

assert!(
status.success(),
"glib-compile-resources failed with exit status {}",
status
);

println!("cargo:rerun-if-changed={}", gresource);
let output = Command::new("glib-compile-resources")
.arg("--sourcedir")
.arg(source_dir.as_ref())
.arg("--generate-dependencies")
.arg(gresource)
.output()
.unwrap()
.stdout;
let output = String::from_utf8(output).unwrap();
for dep in output.split_whitespace() {
println!("cargo:rerun-if-changed={}", dep);
}
}

#[doc(hidden)]
pub fn resources_register_include_impl(bytes: &'static [u8]) -> Result<(), glib::Error> {
let bytes = glib::Bytes::from_static(bytes);
Expand All @@ -85,7 +38,7 @@ pub fn resources_register_include_impl(bytes: &'static [u8]) -> Result<(), glib:
}

// rustdoc-stripper-ignore-next
/// Include gresources generated with [compile_resources] and register with glib. `path` is
/// Include gresources generated with `glib_build_tools::compile_resources` and register with glib. `path` is
/// relative to `OUTDIR`.
///
/// ```ignore
Expand Down
1 change: 1 addition & 0 deletions glib-build-tools/COPYRIGHT
20 changes: 20 additions & 0 deletions glib-build-tools/Cargo.toml
@@ -0,0 +1,20 @@
[package]
name = "glib-build-tools"
license = "MIT"
homepage = "https://gtk-rs.org/"
authors = ["The gtk-rs Project Developers"]
keywords = ["glib", "gio", "gtk-rs", "gnome", "build-dependencies"]
readme = "README.md"
documentation = "https://gtk-rs.org/gtk-rs-core/stable/latest/docs/glib-build-tools"
version = "0.1.0"
description = "Rust bindings for the Gio library, build script utils crate"
repository = "https://github.com/gtk-rs/gtk-rs-core"
edition = "2021"
rust-version = "1.57"

[dependencies]
gio = { path = "../gio", optional = true }

[features]
# We only depend on gio so that we may link it in our documentation
dox = ["gio"]
1 change: 1 addition & 0 deletions glib-build-tools/LICENSE
16 changes: 16 additions & 0 deletions glib-build-tools/README.md
@@ -0,0 +1,16 @@
# GIO build helpers

Crate containing helpers for building GIO-based applications.

## Minimum supported Rust version

Currently, the minimum supported Rust version is `1.57.0`.

## Documentation

* [Stable API](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/glib-build-tools)
* [Development API](https://gtk-rs.org/gtk-rs-core/git/latest/docs/glib-build-tools)

### See Also

* [gio](http://crates.io/crates/gio)
51 changes: 51 additions & 0 deletions glib-build-tools/src/lib.rs
@@ -0,0 +1,51 @@
// Take a look at the license at the top of the repository in the LICENSE file.

#![doc = include_str!("../README.md")]

use std::env;
use std::path::Path;
use std::process::Command;

// rustdoc-stripper-ignore-next
/// Call to run `glib-compile-resources` to generate compiled gresources to embed
/// in binary with [`gio::resources_register_include`]. `target` is relative to `OUT_DIR`.
///
/// ```no_run
/// glib_build_tools::compile_resources(
/// "resources",
/// "resources/resources.gresource.xml",
/// "compiled.gresource",
/// );
/// ```
pub fn compile_resources<P: AsRef<Path>>(source_dir: P, gresource: &str, target: &str) {
let out_dir = env::var("OUT_DIR").unwrap();

let status = Command::new("glib-compile-resources")
.arg("--sourcedir")
.arg(source_dir.as_ref())
.arg("--target")
.arg(&format!("{}/{}", out_dir, target))
.arg(gresource)
.status()
.unwrap();

assert!(
status.success(),
"glib-compile-resources failed with exit status {}",
status
);

println!("cargo:rerun-if-changed={}", gresource);
let output = Command::new("glib-compile-resources")
.arg("--sourcedir")
.arg(source_dir.as_ref())
.arg("--generate-dependencies")
.arg(gresource)
.output()
.unwrap()
.stdout;
let output = String::from_utf8(output).unwrap();
for dep in output.split_whitespace() {
println!("cargo:rerun-if-changed={}", dep);
}
}