mbox series

[v2,00/11] meson: a couple of additions

Message ID 20250114-b4-pks-meson-additions-v2-0-8d7ec676cfd9@pks.im (mailing list archive)
Headers show
Series meson: a couple of additions | expand

Message

Patrick Steinhardt Jan. 14, 2025, 11:56 a.m. UTC
Hi,

this small patch series backfills in a couple of missing features into
Meson. It also improves test coverage of our Meson-based CI jobs so that
we compile with Meson with Visual Studio and compile fuzzers. CI runs
for GitLab and GitHub can be found at [1] and [2], respectively.

The series is built on top of fbe8d3079d (Git 2.48, 2025-01-10) with
ps/meson-weak-sha1-build at 6a0ee54f9a (meson: provide a summary of
configured backends, 2024-12-30) merged into it.

Changes in v2:
  - Consistently use `meson.has_header_symbol()` to fix warnings for
    features not yet available in Meson 0.61, which is our minimum
    required version.
  - Add another patch that makes use use `--fatal-meson-warnings` so
    that such warnings will cause the build to fail.
  - Fix a bug that made GIT-VERSION-GEN always return tags as version.
  - Adapt the approach we use to populate the project and distribution
    tarball versions.
  - Link to v1: https://lore.kernel.org/r/20250113-b4-pks-meson-additions-v1-0-97f6a93f691d@pks.im

Thanks!

Patrick

[1]: https://gitlab.com/gitlab-org/git/-/merge_requests/280
[2]: https://github.com/git/git/pull/1870

---
Patrick Steinhardt (11):
      GIT-VERSION-GEN: simplify computing the dirty marker
      GIT-VERSION-GEN: allow running without input and output files
      meson: populate project version via GIT-VERSION-GEN
      meson: fix dependencies for generated headers
      meson: wire up development environments
      meson: wire up generation of distribution archive
      meson: wire up fuzzers
      meson: make the CSPRNG backend configurable
      meson: fix compilation with Visual Studio
      ci: raise error when Meson generates warnings
      ci: wire up Visual Studio build with Meson

 .github/workflows/main.yml | 52 +++++++++++++++++++++++++++
 .gitlab-ci.yml             | 38 ++++++++++++++++++++
 GIT-VERSION-GEN            | 50 ++++++++++++++++----------
 ci/run-build-and-tests.sh  |  4 ++-
 meson.build                | 87 +++++++++++++++++++++++++++++++++++++---------
 meson_options.txt          |  4 +++
 oss-fuzz/meson.build       | 20 +++++++++++
 7 files changed, 219 insertions(+), 36 deletions(-)

Range-diff versus v1:

 1:  9cceb5db4d !  1:  a546dd43be GIT-VERSION-GEN: simplify computing the dirty marker
    @@ GIT-VERSION-GEN: then
      			test -f "$SOURCE_DIR"/.git;
      		} &&
     -		VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
    -+		VN=$(git -C "$SOURCE_DIR" describe --match --dirty "v[0-9]*" 2>/dev/null) &&
    ++		VN=$(git -C "$SOURCE_DIR" describe --dirty --match="v[0-9]*" 2>/dev/null) &&
      		case "$VN" in
      		*$LF*) (exit 1) ;;
     -		v[0-9]*)
 2:  00b9586887 <  -:  ---------- GIT-VERSION-GEN: move default version into a separate file
 -:  ---------- >  2:  3079bcc87a GIT-VERSION-GEN: allow running without input and output files
 -:  ---------- >  3:  aab1945e47 meson: populate project version via GIT-VERSION-GEN
 3:  a7712e6874 =  4:  782b9677c3 meson: fix dependencies for generated headers
 4:  0b30d76c7a =  5:  a9efaebe7b meson: wire up development environments
 5:  71081feccf !  6:  92913a6b20 meson: wire up generation of distribution archive
    @@ Metadata
      ## Commit message ##
         meson: wire up generation of distribution archive
     
    -    Meson knows to generate distribution archives via `meson dist`. Despite
    -    generating the archive itself, this target also knows to compile and
    -    execute tests from that archive, which helps to ensure that the result
    -    is an adequate drop-in replacement for the versioned project.
    +    Meson knows to generate distribution archives via `meson dist`. In
    +    addition to generating the archive itself, this target also knows to
    +    compile and execute tests from that archive, which helps to ensure that
    +    the result is an adequate drop-in replacement for the versioned project.
     
         While this already works as-is, one omission is that we don't propagate
         the commit that this is built from into the resulting archive. This can
    @@ Commit message
         version into the "version" file, which GIT-VERSION-GEN knows to read if
         present.
     
    -    Use GIT-VERSION-GEN itself to populate that file. There are two smallish
    -    gotchas:
    -
    -      - The script is executed in the build directory, not in the directory
    -        where we generate the archive. The target directory is propagated
    -        via the "MESON_DIST_ROOT" environment variable, but because we don't
    -        use a shell to execute GIT-VERSION-GEN we cannot populate the envvar
    -        into its arguments. We thus adapt GIT-VERSION-GEN to handle this for
    -        us.
    -
    -      - We use the "GIT-VERSION-FILE.in" template to generate the version,
    -        which contains a "GIT_VERSION=" prefix that we need to strip after
    -        reading the "version" file. We could avoid this extra logic if we
    -        used a template that only had the `@GIT_VERSION@` placeholder, but
    -        it would require us to add one more template file.
    +    Use GIT-VERSION-GEN to populate that file. As the script is executed in
    +    the build directory, not in the directory where we generate the archive,
    +    we have adapt it to honor the "MESON_DIST_ROOT" environment variable.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
      ## GIT-VERSION-GEN ##
    -@@ GIT-VERSION-GEN: then
    - 	exit 1
    - fi
    +@@ GIT-VERSION-GEN: case "$2" in
    + esac
      
    + OUTPUT="$3"
     +if test -n "$OUTPUT" && test -n "$MESON_DIST_ROOT"
     +then
     +    OUTPUT="$MESON_DIST_ROOT/$OUTPUT"
     +fi
    -+
    - DEF_VER=$(cat "$SOURCE_DIR"/GIT-VERSION)
      
      # Protect us from reading Git version information outside of the Git directory
    -@@ GIT-VERSION-GEN: then
    - 	# then try git-describe, then default.
    - 	if test -f "$SOURCE_DIR"/version
    - 	then
    --		VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
    -+		VN=$(cat "$SOURCE_DIR"/version) && VN=${VN#GIT_VERSION=} || VN="$DEF_VER"
    - 	elif {
    - 			test -d "$SOURCE_DIR/.git" ||
    - 			test -d "${GIT_DIR:-.git}" ||
    + # in case it is not a repository itself, but embedded in an unrelated
     
      ## meson.build ##
     @@ meson.build: devenv.set('GIT_BUILD_DIR', meson.current_build_dir())
    @@ meson.build: devenv.set('GIT_BUILD_DIR', meson.current_build_dir())
     +  shell,
     +  meson.current_source_dir() / 'GIT-VERSION-GEN',
     +  meson.current_source_dir(),
    -+  meson.current_source_dir() / 'GIT-VERSION-FILE.in',
    ++  '--format=@GIT_VERSION@',
     +  'version',
     +)
     +
 6:  5dd6be9be7 =  7:  4bde8aee4c meson: wire up fuzzers
 7:  88e2935e52 !  8:  2f33403322 meson: make the CSPRNG backend configurable
    @@ meson.build: else
      endif
      
     -if compiler.has_header_symbol('stdlib.h', 'arc4random_buf')
    ++# Backends are ordered to reflect our preference for more secure and faster
    ++# ones over the ones that are less so.
     +if csprng_backend in ['auto', 'arc4random'] and compiler.has_header_symbol('stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random')
        libgit_c_args += '-DHAVE_ARC4RANDOM'
     -elif compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf')
    @@ meson.build: else
        libgit_c_args += '-DHAVE_ARC4RANDOM_BSD'
     -elif compiler.has_function('getrandom', prefix: '#include <sys/random.h>')
     +  csprng_backend = 'arc4random_bsd'
    -+elif csprng_backend in ['auto', 'getrandom'] and compiler.has_function('getrandom', prefix: '#include <sys/random.h>', required: csprng_backend == 'getrandom')
    ++elif csprng_backend in ['auto', 'getrandom'] and compiler.has_header_symbol('sys/random.h', 'getrandom', required: csprng_backend == 'getrandom')
        libgit_c_args += '-DHAVE_GETRANDOM'
     -elif compiler.has_function('getentropy', prefix: '#include <unistd.h>')
     +  csprng_backend = 'getrandom'
    -+elif csprng_backend in ['auto', 'getentropy'] and compiler.has_function('getentropy', prefix: '#include <unistd.h>', required: csprng_backend == 'getentropy')
    ++elif csprng_backend in ['auto', 'getentropy'] and compiler.has_header_symbol('unistd.h', 'getentropy', required: csprng_backend == 'getentropy')
        libgit_c_args += '-DHAVE_GETENTROPY'
     -elif compiler.has_function('RtlGenRandom', prefix: '#include <windows.h>\n#include <ntsecapi.h>')
     +  csprng_backend = 'getentropy'
    -+elif csprng_backend in ['auto', 'rtlgenrandom'] and compiler.has_function('RtlGenRandom', prefix: '#include <windows.h>\n#include <ntsecapi.h>', required: csprng_backend == 'rtlgenrandom')
    ++elif csprng_backend in ['auto', 'rtlgenrandom'] and compiler.has_header_symbol('ntsecapi.h', 'RtlGenRandom', prefix: '#include <windows.h>', required: csprng_backend == 'rtlgenrandom')
        libgit_c_args += '-DHAVE_RTLGENRANDOM'
     -elif openssl.found()
     +  csprng_backend = 'rtlgenrandom'
 8:  f6ee13d6dc <  -:  ---------- meson: fix compilation with Visual Studio
 -:  ---------- >  9:  d56a24e15a meson: fix compilation with Visual Studio
 -:  ---------- > 10:  c624f1d554 ci: raise error when Meson generates warnings
 9:  946c31f452 = 11:  c7f7e2309a ci: wire up Visual Studio build with Meson

---
base-commit: 35a417ddf0eab983e4d5eb69e628aa198114bb05
change-id: 20250107-b4-pks-meson-additions-055c16b3052b

Comments

Junio C Hamano Jan. 14, 2025, 5:46 p.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

>      -		VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
>     -+		VN=$(git -C "$SOURCE_DIR" describe --match --dirty "v[0-9]*" 2>/dev/null) &&
>     ++		VN=$(git -C "$SOURCE_DIR" describe --dirty --match="v[0-9]*" 2>/dev/null) &&

Ahh, you only said "found the issue" and it was building suspense
;-)

It turns out that I wasn't affected while testing because my build
infrastructure around "make" computes the version string by itself
independently from what "make/GIT-VERSION-GEN" does, and stuffs it
in the 'version' file, before running "make install".  And that is
why I didn't notice the breakage before Ramsay reported X-<.

This fix looks obviously good.

Thanks.