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

Meson update #658

Merged
merged 5 commits into from
Feb 15, 2023
Merged

Conversation

amcnulty-fermat
Copy link
Contributor

This PR is heavily based on existing work by Owen Torres (@optorres) in #546. I aim to get his excellent work merged.

As stated by @optorres in #546 :

This updates the meson build scripts to bring them more-or-less up to parity with the CMake script and adds a meson build script to one of the project examples.

Build script additions:

Library version is now retrieved from unity.h instead of being left as undefined.
Extensions (fixture and memory) are now supported.
The library, headers, and package configuration files (using pkg-config instead of CMake's config format) are now installed with ninja install / meson compile install.

My additions to his work are mainly around hygiene for Meson. I try to use the cross-platform / operator to join paths, which was introduced in version '0.49.0' and use meson.project_source_root() which is introduced in Meson version 0.56.0 in place of the deprecated function meson.source_root().

1. Use cross-platform `/` operator for path construction.

2. Use `meson.project_source_root()` for correct path resolution of
   generate_test_runner.rb path when used as a subproject.

3. Bump the minimum required Meson version to '0.56.0' as this is
   needed for the above changes.
The following features from the CMake build have been implemented:
 * Library version retrieved from unity.h.
 * Extension support.
 * Library, header, and package configuration file installation.

This commit is entirely based on existing work by Owen Torres.
@amcnulty-fermat
Copy link
Contributor Author

@maintainers, many thanks for the CI approval. Given that it seems to pass the CI check I will mark this as ready for review.

@amcnulty-fermat amcnulty-fermat marked this pull request as ready for review February 13, 2023 16:58
@amcnulty-fermat
Copy link
Contributor Author

I can't set reviewers but it would be good to get feedback from @optorres, and @pmembrey as their Meson build scripts are being modified here. @eli-schwartz, being a Meson developer, is well-placed to offer good feedback.

Copy link
Contributor

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

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

My pleasure. :) Some comments which are largely copied from the original PR:

meson.build Outdated
# Set project version to value extracted from unity.h header
version: run_command(
[
find_program('python', 'python3'),
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to find python here, because the extract_version.py script is runnable on its own as a regular program (it's executable and has a shebang). On Windows, Meson will scan the shebang and detect that it needs to be run with python.

Copy link
Contributor Author

@amcnulty-fermat amcnulty-fermat Feb 14, 2023

Choose a reason for hiding this comment

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

This has been implemented. I didn't know about Meson doing the right thing on Windows.

The version in #546 resulted in Meson not finding python3 on Ubuntu Jammy with Meson 1.0.0 installed via pip3, hence why I added 'python3' to the find_program() invokation, although this might be because the python-is-python3 package was not installed.

I had also tried import('python').find_installation('python3') as a cross-platform way to find the Python interpreter but this caused an internal Meson error. I will see if I can reproduce it and then check if it hasn't already been reported before reporting it to Meson upstream. EDIT: Meson bug report.

meson.build Outdated
Comment on lines 28 to 29
build_fixture = get_option('extension_fixture').enabled()
build_memory = get_option('extension_memory').enabled()
Copy link
Contributor

Choose a reason for hiding this comment

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

You're just using these like booleans, it seems misleading to allow people to specify either =auto or =disabled and have auto really just mean disabled.

What about defining the options as type boolean, and just checking the option value directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense. Implemented.

meson.build Outdated
# Create a generator that can be used by consumers of our build system to generate
# test runners.
gen_test_runner = generator(
find_program(meson.project_source_root() / 'auto' / 'generate_test_runner.rb'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
find_program(meson.project_source_root() / 'auto' / 'generate_test_runner.rb'),
find_program('auto/generate_test_runner.rb'),

find_program() will already search for local files relative to the current context meson.build file so you don't need to prepend an absolute path.

This also means you don't need to bump the minimum version just to use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. This simplifies things a lot.

1. Call the version extraction script directly instead
   of through a Python returned from `find_program()`.

2. We don't need to use `meson.project_source_root()` as
   `find_program()` will search relative to the current meson.build
   script.

3. Lower the required version back to `>= 0.37.0`, and modify
   some things to get rid of warnings with this version selected.
   The use of `summary()`, `dict`, and positional arguments in
   `pkgconfig.generate()` generate warnings with this version so
   remove `summary()` and dict()`, also pass keyword arguments to
   `pkgconfig.generate()`.
@amcnulty-fermat
Copy link
Contributor Author

Thanks @eli-schwartz for your review!

I have implemented your feedback. In the process of lowering the minimum required version of Meson, I have made some other changes to the toplevel meson.build in order to avoid generating warnings. Please let me know what you think.

Given that most users of Meson with Unity will be using it as a subproject, I thought it wise to avoid as many warnings as possible to avoid causing noise or confusion for users. Let me know if this is the right call or not, @mvandervoord.

@eli-schwartz
Copy link
Contributor

You need at least 0.47.0 for the check: argument to run_command(), but that version is practically everywhere anyway.

It's not present in distros that are as old as, for example, Debian Jessie or Ubuntu 18.04, but I don't think that's a serious downside.

@amcnulty-fermat
Copy link
Contributor Author

amcnulty-fermat commented Feb 14, 2023

You need at least 0.47.0 for the check: argument to run_command(), but that version is practically everywhere anyway.

Interesting. Currently when I set meson_version: '0.37.0' and specify check: true in run_command(), Meson 1.0.0 does not seem to generate a warning. Should it generate one?

Using other functionality like summary() and dict while setting meson_version to '0.37.0' did cause Meson to warn about there being a mismatch between the features used and the version of meson required.

@eli-schwartz
Copy link
Contributor

I think that just happens because it's parsed before the meson_version is set, since it's inline in the project() function. :) It's a hard problem to solve, but then again, we don't typically recommend inlining functions into project() -- with the exception of, well, the "version" kwarg (run_command() or files())

@amcnulty-fermat
Copy link
Contributor Author

I think that just happens because it's parsed before the meson_version is set, since it's inline in the project() function. :) It's a hard problem to solve, but then again, we don't typically recommend inlining functions into project() -- with the exception of, well, the "version" kwarg (run_command() or files())

So I was curious about this and modified the project() call to make meson_version be the first kwarg, thus parsed before the run_command, and in this case as well Meson does not issue a warning. It seems as though in the implementation, it should issue one, right?

Thank you for your time and insight!

The use of the check kwarg in run_command() was
introduced in meson version 0.47.0
@eli-schwartz
Copy link
Contributor

eli-schwartz commented Feb 14, 2023

No, the issue is that run_command() is evaluated before project() is evaluated, and then project() just sees a string. :)

The warning is issued if the run_command occurs on any line after the project() function has run.

Possible solutions for handling this could include double parsing or remembering non-issued warnings and repeating them later.

@amcnulty-fermat
Copy link
Contributor Author

No, the issue is that run_command() is evaluated before project() is evaluated, and then project() just sees a string. :)

The warning is issued if the run_command occurs on any line after the project() function has run.

Possible solutions for handling this could include double parsing or remembering non-issued warnings and repeating them later.

Ah that makes sense. Thanks for clarifying it for me.

Could a Unity maintainer take a look at this PR and let me know if there's anything left to do before it's ready for merging?

@mvandervoord mvandervoord merged commit 0854f3d into ThrowTheSwitch:master Feb 15, 2023
nirs added a commit to nirs/blkhash that referenced this pull request Feb 21, 2023
The reason for the unwanted unity installation is unity PR[1] enabling
installation of the static library, pkgconfig file, and headers.

We got this commit because we use `head` instead of a latest release.
Fix by pinning unity to v2.5.2, which does not have the issue, and
remove the unneeded --skip-subprojects option.

[1] ThrowTheSwitch/Unity#658
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