-
Notifications
You must be signed in to change notification settings - Fork 27
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
Use Meson to build and install #133
Conversation
I whole-heartedly approve of the suggestion of Meson as it is an excellent tool and makes for much easier to read and maintain build systems in my experience. I think you will find too the ability for it to use subprojects and wrap along with its excellent support for cross-compilation will be of enormous help, combined with its blazing fast reconfigure times that never require deleting the build directory. |
Looks cool! Not sure if it has anything to do with this but I've got a question/remark:
So I guess the problem is not how the fract4d_stdlib is built but how it's loaded: cmap_module_handle = dlopen(new_filename, RTLD_GLOBAL | RTLD_NOW); By then I found a workaround but it involved to patch every fract4dc import with something like: import DLFCN
sys.setdlopenflags(sys.getdlopenflags() | DLFCN.RTLD_GLOBAL) So the question is: Is it possible somehow in the install process to tell python how that extension should be loaded afterwards? |
Well, that's plenty of encouragement! I think we will need a consensus for a change like this, but before that, as a minimum better get the tests passing. |
Thanks
As long it is not for me - I am just a (plain) Python person. |
I am not a big fan of setuptools for sure. Since we are an app rather than a python lib it has always been a bit awkward. I do want to make sure it is as easy as possible for a user to try gnofract4d. So as long as the steps a user has to do don't get much worse, I'm ok. (Ideally I would like to restart releasing binaries, maybe a snap or something built with pyoxidizer, but that is a problem for another PR) I will try this out this weekend, rather busy at the moment. Thanks for looking into it Chris! |
Added a bit more, I think that is about as far as I can take it. It does install and appears to run but pytest segfaults. Hopefully there is an easy (when you know how) compile or link fix for that.
Can run from source directory as now (version is set to "test"), or else:
The new default strip and LTO options can be overridden by passing: |
If you've not used setuptools on a given clone, you don't need to stick an _ in the name 'build', and it doesn't necessarily need to be called build
You can change settings on the fly by, in your build directory, running |
A couple of general notes about Meson usage: It intelligently tracks what values are assigned to all available settings for a project and automatically reconfigures on changes to meson.build files it knows about, and config via You can also have multiple builds configured differently co-existing via running |
fract4d/c/meson.build
Outdated
|
||
dependencies : [jpeg, png, py_dep], | ||
include_directories : ['fract4dc', 'model'], | ||
cpp_args : ['-D_REENTRANT=1', '-DTHEREADS=1', '-DPNG_ENABLED=1', '-DJPG_ENABLED=1'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, THEREADS should be THREADS. (I can't remember what that define actually does, there is some chance it is obsolete)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, definitely not obsolete - that was what was causing pytest to crash!
) | ||
|
||
pytest = find_program('pytest') | ||
test('testing', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I'd like to try and take this forward and help you get to the finishing line, I have done a clone and build, however.. when I try running ninja test
(or meson test -v
to see what's going wrong), this step fails on account of:
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --cov=fract4d --cov=fract4dgui --cov=fract4d_compiler
inifile: /data/Programming/Gnofract4d/meson/pytest.ini
rootdir: /data/Programming/Gnofract4d/meson
1/1 testing FAIL 0.32s (exit status 4)
I run Arch, so this is clearly a change working its way towards production.. Python is 3.8.3, pytest is 5.4.3. I'm not familiar enough with pytest to debug this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe arch has pytest3 or pylint3 or something?
My concern with the meson change is that we are making it harder for someone to just download the source, build and run. Now they have to install ninja and meson (using pip3, the distro one probably isn't recent enough). Would be good to understand what the readme will look like. Perhaps we can keep a setup.py which simplifies the steps...
Another avenue of course is to come up with an easily-consumable binary package. If we can produce that it's less important how easy build-from-source is. I will try and find the time to see how much hassle it is to build a snap image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I'd like to try and take this forward and help you get to the finishing line, I have done a clone and build, however.. when I try running
ninja test
(ormeson test -v
to see what's going wrong), this step fails on account of:ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: --cov=fract4d --cov=fract4dgui --cov=fract4d_compiler inifile: /data/Programming/Gnofract4d/meson/pytest.ini rootdir: /data/Programming/Gnofract4d/meson 1/1 testing FAIL 0.32s (exit status 4)
I run Arch, so this is clearly a change working its way towards production.. Python is 3.8.3, pytest is 5.4.3. I'm not familiar enough with pytest to debug this
https://pypi.org/project/pytest-cov/ missing by the look of it. (pytest 5.4.3 working fine here, although I see now I've broken the version tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edyoung I think the same argument can be made about cmake as this is not a tool that comes out the box on most distros and even after Debian/Ubuntu's build-essential
is installed.. however, I think you may find the argument for Meson's inbuilt packaging support to be compelling:
Meson supports destdir on install out the box which makes writing packaging descriptions considerably easier - for example: https://github.com/DX-MON/crunch/blob/master/package/PKGBUILD or in the case of Debian, the hilariously simple https://github.com/DX-MON/crunch/blob/master/package/debian/rules
So I think you'll find building an installable package this way very easy to do and low maintenance. You also get a dist archive out of the process (meson dist
) that is ready for upload to a GitHub release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I would just like to see what instructions we need to put in README.md to cover the 'install source dist; build; run locally' path.
f96eee7
to
66a54ef
Compare
Had to rebase because of the removal of fract4d_stdlib, took advantage to do a few tidy ups and reduce the number of commits. Needed to increase the timeout for the test target but now passes (a few new skips for the comparison of the version to the website and documentation). So, still things to think about but we have got to the point of passing tests. |
README change would look something like this: --- a/README.md
+++ b/README.md
@@ -14,7 +14,8 @@ Basic Installation
Run:
- ./setup.py build
+ meson builddir
+ meson compile -C builddir
You can then run Gnofract 4D in the local directory:
@@ -22,7 +23,7 @@ You can then run Gnofract 4D in the local directory:
You can also install it:
- sudo ./setup.py install
+ sudo meson install -C builddir
You can then run it as:
@@ -44,19 +45,20 @@ On Ubuntu, these can be installed with:
sudo apt install gir1.2-gtk-3.0 python3-gi-cairo python3-cairo
To build from source you also need:
+- Meson and Ninja
- headers for libpng and libjpeg
- Python headers
- pkg-config
On Ubuntu, these can be installed with:
- sudo apt install libjpeg-dev libpng-dev pkg-config python3-dev
+ sudo apt install libjpeg-dev libpng-dev meson pkg-config python3-dev
If FFmpeg is installed it will be possible to create videos.
On MacOS, you can install the dependencies using brew:
- brew install librsvg python3 pkg-config cairo gtk+3 pygobject3 py3cairo libpng jpeg
+ brew install meson librsvg python3 pkg-config cairo gtk+3 pygobject3 py3cairo libpng jpeg On Ubuntu meson pulls in ninja-build, I haven't tried MacOS although brew.sh does include meson which depends on ninja. The problem would be that Ubuntu 18.04 only has meson 0.45, so we might need a fallback to |
I still think meson is better for development and maintenance but at the moment, without e.g. a Flatpak available, for the user pip seems easier to use. I don't suggest proceeding with this for now. |
I haven't had the time to try this myself, I had a glance at your comments and it looks very promising from the developer perspective. Nevertheless, I'm yet not familiar enough with Python packaging to give a useful insight when I do. In this discussion they mention this module that might be interesting:
|
I'll see if I can find the time (probably Friday) to see where this is at against the current state of master as it ties in really nicely with #109. Meson supports sanitisers out the box, allowing all the C++ code to be put through ASAN, TSAN, UBSAN etc by simply saying |
I had rebased this on master but stopped because more work is needed on tox and the GitHub workflow. I've pushed it here now anyway in case it saves time. One change included is to avoid a dependency on pytest unless the test target is actually run, and even then drop pytest-cov. |
Tox and checks working (not here though, maybe draft PRs are ignored), by going back to the way setup.py does things - building in the workflow and copying the fract4dc file instead of linking (pylint target doesn't like the link). Seems I was a bit optimistic that I had removed the pytest dependency from meson, maybe that target should just go. Updated the codecov-action used, we aren't getting reports written to PRs, unfortunately not sure this fixes it. |
2c89dd2
to
cbe0113
Compare
Great work! Moving to Meson is a really great development! :) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #133 +/- ##
==========================================
- Coverage 85.74% 85.70% -0.04%
==========================================
Files 55 55
Lines 10418 10424 +6
==========================================
+ Hits 8933 8934 +1
- Misses 1485 1490 +5 ☔ View full report in Codecov by Sentry. |
Just a refresh to get it working with master again (GTK 4 was the least of the changes). Would need more work I expect - and setup.py is still working! |
I'm getting some pressure from Gentoo to not use setup.py any more. I've just copied this PR to it's own branch here on the project, which makes it look a bit more "official" (and it's a bit big to carry as a patch) - I think that will do for that now. Not sure how much more would be needed here. Plus setup.py still seems easier for the ordinary user, while it still works. |
Do feel free to merge whenever you feel it's ready, btw. Unfortunately I don't have much time at the moment to do reviews |
Copy fract4dc instead of linking else pylint fails on GitHub.
OK. Let's go for it. There are housekeeping changes that will be needed and will just create conflicts. Rebased on master. |
I got so fed up with setup.py/distutils/setuptools in trying to get the installation paths right that I wondered what it would like to completely replace them with Meson. It seems the Python packaging tools are great if you are creating a Python package or even a command-line script but not so easy for a desktop application.
This isn't ready to merge. e.g. I think there may well be some things missing in the extension compilation but at least it does install an application that starts. The first commit removes the Hugo submodule, this is just to make my testing quicker, not a suggestion.
This was a good bit of learning for me, I'm happy with that for its own sake. I think it could be easier to read and maintain. Sharing in case there is any interest.