I have a GTK app which uses glib resources. It compiles without a problem with Cargo, but then my build.rs
fails when I run the build via Nix. I made a minimal repository that demonstrates this. It’s so minimal that it’s still the “hello world” app, because the problem manifests in the build script, before we get that far.
If you grab the repository, you can build it with a simple nix build
at the root.
Anyway, the error I’m getting is…
rust_resources_demo> Running rustc --crate-name build_script_build build.rs --crate-type bin -C opt-level=3 -C codegen-units=1 --edition 2021 --cfg feature="default" --out-dir target/build/resources_demo --emit=dep-info,link -L dependency=target/buildDeps --extern glib_build_tools=/nix/store/fbbij8hkl76h7886x0an3m8zv6gdd8y2-rust_glib-build-tools-0.18.0-lib/lib/libglib_build_tools-62d120e43c.rlib --cap-lints allow --color always
rust_resources_demo> thread 'main' panicked at /glib-build-tools-0.18.0/src/lib.rs:33:10:
rust_resources_demo> called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
I’ve done some digging. It appears that the build script itself is fine, and the failure I’m getting actually comes from glib-compile-resources
itself. This is not very informative, so I took most of the code out of compile_resources
and just put it right into my build script with some extra debugging. You’ll find that at
So, for this, after building the command, I then ask the command to print out all of the arguments, and I get this:
rust_resources_demo> [Program ] glib-compile-resources
rust_resources_demo> [arg ] --sourcedir
rust_resources_demo> [arg ] /build/source
rust_resources_demo> [arg ] --target
rust_resources_demo> [arg ] /build/source/target/build/resources_demo.out/com.luminescent-dreams.resources-demo
rust_resources_demo> [arg ] /build/source/gresources.xml
rust_resources_demo> [current dir] None
When I dig into the build directory, I can see that all of the relevant paths exist. So, I actually really don’t know that glib-compile-resources
is complaining about.
(I’ve tried a couple of different source and individual file options.)
So, if you are familiar with buildRustCrate, crate2nix, and glib, could you take a look at this and see if you can tell what I’m missing?