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

Allow running the demo from the build dir #151

Closed
wants to merge 1 commit into from

Conversation

whot
Copy link
Contributor

@whot whot commented Aug 7, 2023

This sits on top of #150 so it builds on my machine but can be split out if need be.

Unless there's a trick I'm missing, we can't easily run the demo from the meson build dir because it looks in /usr/local/share/ for the gresources file. This could (possibly?) be worked around by setting the datadir in meson but another hack is to build the same binary with a .devel suffix, check for that suffix in argv0 and load the gresources from the builddir instead. Not overly pretty but for this use-case it's probably good enough.

@whot whot force-pushed the wip/allow-local-execution branch from 62602c8 to 9763c8e Compare August 7, 2023 21:20
@bilelmoussaoui
Copy link
Owner

Could use a rebase

Running the demo from the builddir fails with the missing gresources
file. Hack around this by copying the binary into a ashpd-demo.devel
and, if argv0 ends with .devel, loading the gresources file from the
meson builddir instead.
@whot whot force-pushed the wip/allow-local-execution branch from 9763c8e to dc74a5a Compare August 14, 2023 01:34
@whot whot marked this pull request as draft August 14, 2023 02:24
@whot
Copy link
Contributor Author

whot commented Aug 14, 2023

Rebased but switched back to draft. I tried running this on a new machine and luckily caught the error: the current branch still requires that the schemas are installed. Simply adding to XDG_DATA_DIRS isn't enough, we need to also compile the schemas in the builddir but that's where I ran into a bit of a rabbit hole. I'm not sure when I'll find time to complete this :(

@bilelmoussaoui
Copy link
Owner

Rebased but switched back to draft. I tried running this on a new machine and luckily caught the error: the current branch still requires that the schemas are installed. Simply adding to XDG_DATA_DIRS isn't enough, we need to also compile the schemas in the builddir but that's where I ran into a bit of a rabbit hole. I'm not sure when I'll find time to complete this :(

For the schemas, you can use GSETTINGS_SCHEMA_DIR

Comment on lines -27 to +32
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
let argv0 = std::env::args().next();
let res = if argv0.is_some() && argv0.unwrap().ends_with(".devel") {
gio::Resource::load(BUILDDIR_RESOURCES_FILE)
} else {
gio::Resource::load(RESOURCES_FILE)
}.expect("Could not load gresource file");
Copy link
Owner

Choose a reason for hiding this comment

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

I am not particularly happy with this approach of checking the binary name. I think a viable path forward is to have a separate meson build option that would influence from where we load the gresource file making the changes to config.rs/main.rs not needed at all. The other option is to embed the gresource into the final binary but nobody took the time to figure out a nice way to do it that integrates well with the hackish meson/cargo thing we are doing

@whot
Copy link
Contributor Author

whot commented Aug 25, 2023

For the schemas, you can use GSETTINGS_SCHEMA_DIR

So from what I've gathered so far

  • gio::Resource::load() apparently requires a full path to the file, so we need to hack around that anyway
  • gio::Settings::new() requires compiled schemas but meson's gnome.compile_schemas() can only compile in the source directory. We generate the gschema.xml files so they are in the build directory. That seems like a strangely missing part of the meson gnome module and needs to be fixed there. Manually compiling in the builddir and setting GSETTINGS_SCHEMA_DIR works.

If I hack around the two above, I get a segfault somewhere deep inside GTK4's gdk_wayland_toplevel_focus() which I'm assuming is not ashpd's fault :)

But I agree, the hackish way right now is not nice and since it doesn't work anyway, let's close this PR - I'm not sure when I'll have time to look at this again in the near future.

@whot whot closed this Aug 25, 2023
@eli-schwartz
Copy link

  • gio::Settings::new() requires compiled schemas but meson's gnome.compile_schemas() can only compile in the source directory. We generate the gschema.xml files so they are in the build directory. That seems like a strangely missing part of the meson gnome module and needs to be fixed there. Manually compiling in the builddir and setting GSETTINGS_SCHEMA_DIR works.

It feels a bit awkward, mostly because glib-compile-schemas only compiles a single directory, and we hacked it up with --target to place the compiled version in a different tree hierarchy. I don't know that it's feasible to merge the two together, so we'd either need to pick one, or generate another directory as an internal implementation detail and append to the GSETTINGS_SCHEMA_DIR directory.

Of course this is all nothing users can't do manually, the main value of the module is to guarantee it is correct...

@whot
Copy link
Contributor Author

whot commented Sep 4, 2023

Thanks for the explanation! From what I can tell from a quick browse glib-compile-schemas does take a srcdir argument (argv[1]), and I suspect during autotools builds srcdir == builddir in most cases anyway (also given the need for --target to be added), so my random guess is that passing an optional srcdir to the module to be passed through would probably work? but that's just that, a random guess :)

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

Successfully merging this pull request may close these issues.

3 participants