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 build system #149

Merged
merged 6 commits into from
Mar 3, 2024
Merged

Meson build system #149

merged 6 commits into from
Mar 3, 2024

Conversation

edmonds
Copy link
Contributor

@edmonds edmonds commented Mar 2, 2024

Hi, Frank!

This branch adds a meson.build file for building libhydrogen. Not sure if you want another build system in your tree, but since I saw you have a few Makefiles and CMake already, I thought I would check :-)

If you aren't familiar with meson and its wrap dependency system , this makes it easy for a meson project to take a dependency on another one, especially and even if the dependency is not available from the OS.

E.g., I want to depend on libhydrogen from a project that I'm working on that uses meson, but libhydrogen is not available from my OS's packages repository, so I added these commits to my project:

edmonds/vacon@045c920
edmonds/vacon@82bce87

Meson then takes care of automatically downloading libhydrogen and building it into my project if the dependency can't be satisfied from the system:

$ meson setup build
[…]
Run-time dependency libhydrogen found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency libhydrogen
Initialized empty Git repository in /home/edmonds/proj/vacon/subprojects/libhydrogen/.git/
remote: Enumerating objects: 69, done.
remote: Counting objects: 100% (69/69), done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 69 (delta 10), reused 25 (delta 3), pack-reused 0
Unpacking objects: 100% (69/69), 51.52 KiB | 2.58 MiB/s, done.
From https://github.com/edmonds/libhydrogen
 * branch            f8782bf07b5211ff0cb37b5b7a6f7b5c6b52626b -> FETCH_HEAD
HEAD is now at f8782bf Add meson build system

Executing subproject libhydrogen

libhydrogen| Project name: libhydrogen
libhydrogen| Project version: undefined
libhydrogen| C compiler for the host machine: sccache cc (gcc 13.2.0 "cc (Debian 13.2.0-16.1) 13.2.0")
libhydrogen| C linker for the host machine: cc ld.bfd 2.42
libhydrogen| Compiler for C supports arguments -Wbad-function-cast: YES
libhydrogen| Compiler for C supports arguments -Wcast-align: YES
libhydrogen| Compiler for C supports arguments -Wcast-qual: YES
libhydrogen| Compiler for C supports arguments -Wdiv-by-zero: YES
libhydrogen| Compiler for C supports arguments -Wfloat-equal: YES
libhydrogen| Compiler for C supports arguments -Wmissing-declarations: YES
libhydrogen| Compiler for C supports arguments -Wmissing-prototypes: YES
libhydrogen| Compiler for C supports arguments -Wnested-externs: YES
libhydrogen| Compiler for C supports arguments -Wno-type-limits: YES
libhydrogen| Compiler for C supports arguments -Wno-unknown-pragmas: YES
libhydrogen| Compiler for C supports arguments -Wpointer-arith: YES
libhydrogen| Compiler for C supports arguments -Wredundant-decls: YES
libhydrogen| Compiler for C supports arguments -Wstrict-prototypes: YES
libhydrogen| Compiler for C supports arguments -Wswitch-enum: YES
libhydrogen| Compiler for C supports arguments -fno-exceptions: YES
libhydrogen| Compiler for C supports arguments -mtune=native: YES
libhydrogen| Build targets in project: 3
libhydrogen| Subproject libhydrogen finished.

Dependency libhydrogen from subproject subprojects/libhydrogen found: YES undefined
[…]

I also added pkg-config .pc file generation, but if you want a meson.build without that functionality that commit can be omitted.

Thanks!

@jedisct1
Copy link
Owner

jedisct1 commented Mar 3, 2024

Hi!

Could you add some tests for this to the CI scripts?

I don't use Meson nor CMake, so having this tested at least in CI can help to make sure that it doesn't unintentionally break.

https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/

    On December 13, 2023, we released CodeQL Action v3, which runs on
    the Node.js 20 runtime. CodeQL Action v2 will be deprecated at the
    same time as GHES 3.11, which is currently scheduled for December
    2024.

https://github.com/github/codeql-action/blob/main/CHANGELOG.md

    Note that the only difference between v2 and v3 of the CodeQL Action
    is the node version they support, with v3 running on node 20 while
    we continue to release v2 to support running on node 16.
    Analyze (c-cpp)

    Node.js 16 actions are deprecated. Please update the following
    actions to use Node.js 20: actions/checkout@v3. For more information
    see:

    https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
…d CMake and meson

There does not seem to be any documentation about how the
codeql-action/autobuild step actually works, what order it tries build
systems in, what files it uses to detect the presence of a particular
build system, if it supports any configuration variables, etc.

This commit introduces a `autobuild_force_build_system` matrix
configuration variable with values `cmake` and `meson`. If running under
the `cmake` configuration, all the non-CMake build systems are removed
before invoking the codeql-action/autobuild step. If running under the
`meson` configuration, all the non-Meson build systems are removed
before invoking the codeql-action/autobuild step. This seems to be
sufficient to force codeql-action/autobuild to pick a particular build
system but of course it's super ugly.

I did not want to get rid of the codeql-action/autobuild step entirely
and manually run the builds for each build system since there appears to
be magic auto-installation functionality in the codeql-action/autobuild
step that makes sure the right packages for each build system are
installed. Also, it automatically takes care of invoking the right
setup/build commands for the build system selected.

On the CMake build, I see this in the build log:

    cpp/autobuilder: auto installed the following packages:
    cpp/autobuilder:   libc6-dev-amd64-cross
    cpp/autobuilder:   libgcc-s1-amd64-cross

On the Meson build, I see this in the build log:

    cpp/autobuilder: auto installed the following packages:
    cpp/autobuilder:   meson
    cpp/autobuilder:   libc6-dev-amd64-cross
    cpp/autobuilder:   libgcc-s1-amd64-cross
    cpp/autobuilder:   clang-tools
    cpp/autobuilder:   cscope

So doing it using this hacky way by tricking the codeql-action/autobuild
step avoids needing to maintain manual code to ensure that the right
build systems are installed.

This seems to partially match up with the documentation of the Ubuntu
22.04 GitHub actions runner image here:

https://github.com/actions/runner-images/blob/ubuntu22/20240225.1/images/ubuntu/Ubuntu2204-Readme.md

Which says that CMake is installed in the image, but omits any mention
of Meson or Ninja. It seems the codeql-action/autobuild automatically
installed meson (but not ninja), so maybe ninja actually is installed in
the image but the Readme neglects to list it.

It looks like the build environment ends up with Meson version 0.61.2
and Ninja version 1.10.1 which correspond to the versions shipped in
Ubuntu 22.04. So if a dependency on a newer version of Meson is
introduced, it would have to be manually updated (e.g. by calling `sudo
pip install meson`). However, breaking compatibility with the Meson
shipped with Ubuntu 22.04 is probably undesired, at least for now.
@edmonds
Copy link
Contributor Author

edmonds commented Mar 3, 2024

Hi!

Could you add some tests for this to the CI scripts?

I don't use Meson nor CMake, so having this tested at least in CI can help to make sure that it doesn't unintentionally break.

Sure. I just pushed some additional commits that run the three build systems (CMake, Make, Meson) in CI and also fixed a few deprecation warnings.

@jedisct1
Copy link
Owner

jedisct1 commented Mar 3, 2024

Awesome, thank you!

@jedisct1 jedisct1 merged commit 8672ac1 into jedisct1:master Mar 3, 2024
4 checks passed
edmonds added a commit to edmonds/vacon that referenced this pull request Mar 4, 2024
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.

2 participants