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

Is there any plans to make it work on MacOS? #41

Closed
backtozero opened this issue Jan 17, 2022 · 27 comments
Closed

Is there any plans to make it work on MacOS? #41

backtozero opened this issue Jan 17, 2022 · 27 comments
Labels
enhancement New feature or request

Comments

@backtozero
Copy link

Since GTK4 got some improvement in supporting Macs

@flxzt flxzt added the enhancement New feature or request label Jan 18, 2022
@ovidius72
Copy link

ovidius72 commented Jan 19, 2022

I'm also interested, thanks.

@nilbot
Copy link

nilbot commented Jan 24, 2022

I have no knowledge in gtk, meson build system and even rust is very new to me. But here I go with the tinkering:

I managed to get dependencies via homebrew on MacOS (M1 chip and arm brew even) and started compilation until following error:

rnote   main  v1.57.0
🕙 13:37:21 ❯ meson setup --prefix=/Users/abc/opt _mesonbuild                                                                                         
The Meson build system
Version: 0.61.1
Source dir: /Users/abc/tmp/rnote
Build dir: /Users/abc/tmp/rnote/_mesonbuild
Build type: native build
Project name: rnote
Project version: 0.2.5
Rust compiler for the host machine: rustc -C linker=cc (rustc 1.57.0)
Rust linker for the host machine: rustc -C linker=cc ld64 711
Host machine cpu family: aarch64
Host machine cpu: arm64
Found pkg-config: /opt/homebrew/bin/pkg-config (0.29.2)
Run-time dependency glib-2.0 found: YES 2.70.2
Run-time dependency gio-2.0 found: YES 2.70.2
Run-time dependency gtk4 found: YES 4.6.0
Run-time dependency libadwaita-1 found: YES 1.0.1
Run-time dependency poppler-glib found: YES 21.12.0
Run-time dependency gstreamer-1.0 found: YES 1.18.5
Program cargo found: YES (/Users/abc/.cargo/bin/cargo)
Program build-aux/cargo.sh found: YES (/bin/sh /Users/abc/tmp/rnote/build-aux/cargo.sh)
Program glib-compile-resources found: YES (/opt/homebrew/bin/glib-compile-resources)
Program glib-compile-schemas found: YES (/opt/homebrew/bin/glib-compile-schemas)
Program desktop-file-validate found: YES (/opt/homebrew/bin/desktop-file-validate)
Program appstream-util found: YES (/opt/homebrew/bin/appstream-util)
Program update-mime-database found: YES (/opt/homebrew/bin/update-mime-database)
Configuring resources.gresource.xml using configuration
Found pkg-config: /opt/homebrew/bin/pkg-config (0.29.2)
Program glib-compile-resources found: YES (/opt/homebrew/bin/glib-compile-resources)
Configuring app.desktop.in using configuration
Configuring com.github.flxzt.rnote.gschema.xml using configuration
Configuring app.metainfo.xml.in using configuration
Configuring config.rs using configuration
Build targets in project: 11

rnote 0.2.5

  User defined options
    prefix: /Users/abc/opt

Found ninja-1.10.2 at /opt/homebrew/bin/ninja

rnote   main  v1.57.0
🕙 13:37:24 ❯ meson compile -C _mesonbuild                                                                                                               
ninja: Entering directory `/Users/abc/tmp/rnote/_mesonbuild'
[5/8] Generating resources/com.github.flxzt.rnote.metainfo.xml with a custom command
FAILED: resources/com.github.flxzt.rnote.metainfo.xml
/opt/homebrew/Cellar/meson/0.61.1/bin/meson --internal msgfmthelper resources/app.metainfo.xml.in resources/com.github.flxzt.rnote.metainfo.xml xml /Users/nilbot/tmp/rnote/po
msgfmt: cannot locate ITS rules for resources/app.metainfo.xml.in
[7/8] Generating resources/resources_gresource with a custom command
ninja: build stopped: subcommand failed.

The dependencies I needed to grab on my end (ymmv) are:

gtk4
gstreamer
poppler
libadwaita
meson
appstream-glib
desktop-file-utils

The error message msgfmt: cannot locate ITS rules for resources/app.metainfo.xml.in baffles me, on google it seems other gnome project encountered same error and the source might be appstream, and it could be a appstream packaging issue, not exclusive to homebrew appstream. issue1260

@eli-schwartz
Copy link

It's possible to check in a copy of the needed its rules files to a local directory, e.g. resources/its/, and pass that directory as data_dirs: 'its' in meson.build so that the local ITS rules files are also considered by gettext.

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 7, 2022

I attempted a build after installing the dependencies @nilbot had listed, and after running meson compile -C _mesonbuild I ended up with the following two messages at the very end

[14/16] Generating rnote-ui/data/com.github.flxzt.rnote.desktop with a custom command
/opt/homebrew/bin/msgfmt: {Absolute path to rnote}/po/LINGUAS does not exist
[15/16] Generating rnote-ui/data/com.github.flxzt.rnote.metainfo.xml with a custom command
/opt/homebrew/bin/msgfmt: {Absolute path to rnote}/po/LINGUAS does not exist

with the absolute path to rnote being /Users/{HOME}/.../rnote. This seems to be different to the cannot locate ITS rules for resources/app.metainfo.xml.in error message, though I'm not entirely sure what's going wrong here either.

Attempting to run the binary with ./_mesonbuild/target/release/rnote would result in the following error message:

thread 'main' panicked at 'Could not load gresource file: Error { domain: g-file-error-quark, code: 4, message: "Failed to open file “/usr/share/rnote/resources.gresource”: open() failed: No such file or directory" }', rnote-ui/src/app/mod.rs:72:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm not sure what a LINGUAS file is supposed to be (I have 0 knowledge regarding msgfmt to begin with), and I don't know what a gresource file is supposed to be, so I'm quite puzzled by this.

Unless someone more knowledgeable happens to comes along, I guess I'll have to Google-fu this some other time.

@eli-schwartz
Copy link

podir = meson.project_source_root() / 'po'

There is a LINGUAS file here: https://github.com/flxzt/rnote/blob/main/rnote-ui/po/LINGUAS

It's just a text file listing the available languages that have translations -- and comes in the same directory as the translations themselves.

But it is not in {rnote-checkout}/po/, it is in {rnote-checkout}/rnote-ui/po/.

I would replace this:

po_dir: podir,

with

po_dir: '../po',

@eli-schwartz
Copy link

This appears to have broken in commit 7d6bc99, which incidentally I think is a good demonstration of why ../po would be more flexible.

flxzt added a commit that referenced this issue Jul 7, 2022
@flxzt
Copy link
Owner

flxzt commented Jul 7, 2022

thanks, fixed!
If you made a successful MacOS build, do you mind documenting all needed deps and build steps in a text file and making a PR to place it in here: https://github.com/flxzt/rnote/tree/main/misc/building ? It would be very appreciated.

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 7, 2022

It seems that PR managed to fix the issues regarding the LINGUA file, but unfortunately attempting to run the executable still results in this same error message:

thread 'main' panicked at 'Could not load gresource file: Error { domain: g-file-error-quark, code: 4, message: "Failed to open file “/usr/share/rnote/resources.gresource”: open() failed: No such file or directory" }', rnote-ui/src/app/mod.rs:72:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm not sure exactly what's going on here, as I'm not familiar with what a gresource file is and how it's being used in this project.

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 7, 2022

I'd forgotten, but it turns out /usr is protected in macOS by SIP, meaning not even a root user is able to modify the contents of the directory. Apparently, the recommended approach is to use /usr/local/share instead, which is not protected by SIP.

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 8, 2022

I tried changing the path to the gresource file to be /usr/local/share/rnote/resources.gresource instead, just so I could actually place the gresource file in there manually. After that, I attempted to build and run once more, but the error this time was something else:

(rnote:18861): GLib-GIO-ERROR **: 14:41:24.597: Settings schema 'com.github.flxzt.rnote' is not installed
zsh: trace trap  ./_mesonbuild/target/release/rnote

I'm not familiar with GTK or Glib at all, so I'd have to look into what's going on here later.

@nilbot
Copy link

nilbot commented Jul 9, 2022

I'm also seeing the same error as @y-mx-b

~/opt/bin/rnote                                                                                                                                               (base)

(rnote:83403): GLib-GIO-ERROR **: 11:18:39.208: Settings schema 'com.github.flxzt.rnote' is not installed
fish: Job 1, '~/opt/bin/rnote' terminated by signal SIGTRAP (Trace or breakpoint trap)

The build and install message shown no error, and gschema can be found in $INSTALL_PREFIX/opt/share/glib-2.0/schemas, I thought that was what the message pointing out.

p.s. the post installation script handles the copying of files, including the resource error you shown earlier. You would need to install one more dependency via homebrew for the post installation script to work

brew install gtk+

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 10, 2022

It turns out I was just missing permissions issues related to setting my prefix as /usr/local (editing requires sudo), so I just changed my prefix to ~ and I ended up getting essentially the same error message as @nilbot.

(rnote:97832): GLib-GIO-ERROR **: 23:32:10.147: Settings schema 'com.github.flxzt.rnote' is not installed
zsh: trace trap  ~/bin/rnote

Also, interestingly, running it from .../_mesonbuild/rnote gave me this:

zsh: killed     ./_mesonbuild/rnote

Running the test showed no errors,

2/3 validate-gschema        OK              0.01s

1/3 validate-desktop        OK              0.15s

3/3 validate-appdata        OK              0.52s
―――――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――
rnote-ui/data/com.github.flxzt.rnote.metainfo.xml: OK
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――


Ok:                 3
Expected Fail:      0
Fail:               0
Unexpected Pass:    0
Skipped:            0
Timeout:            0

so I assume this has to do entirely with runtime-dependencies not being properly copied over?

@flxzt
Copy link
Owner

flxzt commented Jul 10, 2022

It looks like Gio is not finding the compiled gschema.
First I would verify that the schema is installed and compiled in /the/installation/path/share/glib-2.0/schemas. There should be at least two files, com.github.flxzt.rnote.gschema.xml and gschemas.compiled

I believe by default Gio looks for settings in XDG_DATA_DIRS/glib-2.0/schemas and in XDG_DATA_HOME/glib-2.0/schemas. But you can add additional paths by adding a custom path to GSETTINGS_SCHEMA_DIR, so I would try something like export GSETTINGS_SCHEMA_DIR=$GSETTINGS_SCHEMA_DIR:/the/installation/path/share/glib-2.0/schemas before running rnote.

see also:
https://www.freedesktop.org/software/gstreamer-sdk/data/docs/2012.5/gio/ch03.html

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 10, 2022

After exporting the path as @flxzt suggested, I can confirm the app now works. I've tried testing out drawing, erasing, and file saving features, and it all seems functional at the moment.
Screen Shot 2022-07-10 at 5 17 44 AM
Both files were placed in the appropriate directories, it's just that their paths hadn't been exported.

I'll try working on writing up build steps for macOS and adding it to https://github.com/flxzt/rnote/tree/main/misc/building later.

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 10, 2022

I've just made the pull request. I hope I didn't mess anything up 😅

Edit: It as now been merged with master!

@y-mx-b
Copy link
Contributor

y-mx-b commented Jul 10, 2022

Do you think it'd be worth adding macOS-specific build instructions to the build script to have meson generate a proper macOS application (on macOS)? Installing would be as simple as just copying the application to /Applications, but generating the application itself would be a little more complicated (though not by much).

@dehesselle
Copy link

I've been looking into creating a (properly relocatable) application bundle, but that requires some changes to the code which I haven't been able to put together myself (I don't speak Rust). But I assume it's fairly easy for someone who already knows Rust. In a nutshell, instead of hardcoded paths like

pub const LOCALEDIR: &str = @LOCALEDIR@;
pub const PKG_DATA_DIR: &str = @PKG_DATA_DIR@;
pub const RESOURCES_FILE: &str = @RESOURCES_FILE@;

we need paths being set relative to std::env::current_exe(). I also assume we need to set some GTK related environment variables in a similar way, at least for gsettings schemas and gdk pixbuf loaders.

If someone can make the changes to the code, I can help with the rest.

@flxzt
Copy link
Owner

flxzt commented Oct 22, 2022

@dehesselle thanks for attempting this. I am not at all familiar with macos and how bundled applications work there, but it sounds like you are facing similar issues as I was with my (ongoing) attempt of creating a windows installer.

Check out the windows_installer branch, I believe this should be what you are looking for.: https://github.com/flxzt/rnote/blob/windows_installer/rnote-ui/src/meson.build#L19 . There meson inserts relative paths when building on windows instead of absolute paths on linux.

I believe GIO looks for settings in the path specified by GSETTINGS_SCHEMA_DIR. Not sure about GDK pixbuf loaders, I would need to look into that myself too.

@dehesselle
Copy link

@flxzt The solution from the windows_installer branch depends on the program being launched from within its directory (I know the work directory can be set in a .lnk file in Windows), but that doesn't work on macOS. I need the full canonical path at runtime.

Can you provide some working Rust code for:

  1. get full canonical path of main program's parent directory and how to use that in rnote/rnote-ui/src/config.rs.in

  2. a way to set environment variables as first thing in the main function (i.e. before any calls to GTK); I'll need to use that in combination with the path from (1) for the two items I mentioned in my first post

With that I can make the necessary adjustments and PR them back to you.

These are the only two missing pieces of the puzzle, I have everything else covered:

rnote

(screenshot was taken launching Rnote via Terminal)

@flxzt
Copy link
Owner

flxzt commented Oct 27, 2022

will do. I wonder if there is a way to set these paths without using envs in GTK

@flxzt
Copy link
Owner

flxzt commented Jan 23, 2023

@dehesselle I didn't fully understand what you need to make it work on macos.

Regarding the environment variables, I could set up something similar to setup_windows_env, but I would need to know what exactly should be added there.

The current path can be retreived fairly easily with env::current_dir()?.parent() at runtime, but it is not possible to insert that into config.rs.in as that is used by meson to generate config.rs at compile time. You'd need to tell me where it would be needed in the code.

@dehesselle
Copy link

It's probably best to start over in order to avoid misunderstandings.

I need you to put the following into the code however you see fit:

  1. Determine if you're inside an application bundle. A common approach is to check if the canonical path of the main executable contains Contents/MacOS.
  2. If inside an application bundle, set the environment variable
    XDG_DATA_DIRS=<dirname of main_executable>/../Resources/share
    
  3. If inside an application bundle, set the environment variable
    GDK_PIXBUF_MODULE_FILE=<dirname of main_executable>/../Resources/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache
    

@flxzt
Copy link
Owner

flxzt commented Jan 24, 2023

Thanks, that clears things up. See PR #470 with those additions.

What about GSETTINGS_SCHEMA_DIR ?

@dehesselle
Copy link

Thanks for the changes. It might take me a couple of days before I'll get to work on this again, but I'm still committed.

What about GSETTINGS_SCHEMA_DIR ?

XDG_DATA_DIRS takes care of that.

@realcarlos
Copy link

realcarlos commented Feb 20, 2023

I followed "https://github.com/flxzt/rnote/blob/main/misc/building/rnote-macos-build.md"
There is maybe sth missed:
meson setup --prefix=usr/local _mesonbuild => meson setup --prefix=/usr/local _mesonbuild

and don't forget :
sudo chown -R whoami:admin /usr/local/share
brew link glib
brew install libadwaita

@realcarlos
Copy link

realcarlos commented Feb 21, 2023

(rnote:86171): Gdk-ERROR **: 14:55:13.482: Resource path /com/github/flxzt/rnote/icons/scalable/actions/cursor-dot-medium.svg is not a valid image: Unrecognized image file format

brew install librsvg

finally it works !

@flxzt
Copy link
Owner

flxzt commented Mar 12, 2023

thanks to @dehesselle Rnote is now available on MacOS as an app bundle! I added links how to get it to the README and website.

@flxzt flxzt closed this as completed Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants