Skip to content

Commit c7c317a

Browse files
committed
Merge branch 'ps/build-meson-fixes' into next
More build fixes and enhancements on meson based build procedure. * ps/build-meson-fixes: ci: wire up Visual Studio build with Meson ci: raise error when Meson generates warnings meson: fix compilation with Visual Studio meson: make the CSPRNG backend configurable meson: wire up fuzzers meson: wire up generation of distribution archive meson: wire up development environments meson: fix dependencies for generated headers meson: populate project version via GIT-VERSION-GEN GIT-VERSION-GEN: allow running without input and output files GIT-VERSION-GEN: simplify computing the dirty marker
2 parents 2196eca + 7304bd2 commit c7c317a

File tree

7 files changed

+218
-38
lines changed

7 files changed

+218
-38
lines changed

.github/workflows/main.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,58 @@ jobs:
248248
with:
249249
name: failed-tests-windows-vs-${{ matrix.nr }}
250250
path: ${{env.FAILED_TEST_ARTIFACTS}}
251+
252+
windows-meson-build:
253+
name: win+Meson build
254+
needs: ci-config
255+
if: needs.ci-config.outputs.enabled == 'yes'
256+
runs-on: windows-latest
257+
concurrency:
258+
group: windows-meson-build-${{ github.ref }}
259+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
260+
steps:
261+
- uses: actions/checkout@v4
262+
- uses: actions/setup-python@v5
263+
- name: Set up dependencies
264+
shell: pwsh
265+
run: pip install meson ninja
266+
- name: Setup
267+
shell: pwsh
268+
run: meson setup build -Dperl=disabled
269+
- name: Compile
270+
shell: pwsh
271+
run: meson compile -C build
272+
- name: Upload build artifacts
273+
uses: actions/upload-artifact@v4
274+
with:
275+
name: windows-meson-artifacts
276+
path: build
277+
windows-meson-test:
278+
name: win+Meson test
279+
runs-on: windows-latest
280+
needs: [ci-config, windows-meson-build]
281+
strategy:
282+
fail-fast: false
283+
matrix:
284+
nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
285+
concurrency:
286+
group: windows-meson-test-${{ matrix.nr }}-${{ github.ref }}
287+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
288+
steps:
289+
- uses: actions/checkout@v4
290+
- uses: actions/setup-python@v5
291+
- name: Set up dependencies
292+
shell: pwsh
293+
run: pip install meson ninja
294+
- name: Download build artifacts
295+
uses: actions/download-artifact@v4
296+
with:
297+
name: windows-meson-artifacts
298+
path: build
299+
- name: Test
300+
shell: pwsh
301+
run: meson test -C build --list | Select-Object -Skip 1 | Select-String .* | Group-Object -Property { $_.LineNumber % 10 } | Where-Object Name -EQ ${{ matrix.nr }} | ForEach-Object { meson test -C build --no-rebuild --print-errorlogs $_.Group }
302+
251303
regular:
252304
name: ${{matrix.vector.jobname}} (${{matrix.vector.pool}})
253305
needs: ci-config

.gitlab-ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,44 @@ test:mingw64:
145145
- git-sdk/usr/bin/bash.exe -l -c 'ci/print-test-failures.sh'
146146
parallel: 10
147147

148+
.msvc-meson:
149+
tags:
150+
- saas-windows-medium-amd64
151+
before_script:
152+
- choco install -y git meson ninja openssl
153+
- Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
154+
- refreshenv
155+
# The certificate store for Python on Windows is broken and fails to fetch
156+
# certificates, see https://bugs.python.org/issue36011. This seems to
157+
# mostly be an issue with how the GitLab image is set up as it is a
158+
# non-issue on GitHub Actions. Work around the issue by importing
159+
# cetrificates manually.
160+
- Invoke-WebRequest https://curl.haxx.se/ca/cacert.pem -OutFile cacert.pem
161+
- openssl pkcs12 -export -nokeys -in cacert.pem -out certs.pfx -passout "pass:"
162+
- Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\Root -FilePath certs.pfx
163+
164+
build:msvc-meson:
165+
extends: .msvc-meson
166+
stage: build
167+
script:
168+
- meson setup build -Dperl=disabled
169+
- meson compile -C build
170+
artifacts:
171+
paths:
172+
- build
173+
174+
test:msvc-meson:
175+
extends: .msvc-meson
176+
stage: test
177+
when: manual
178+
timeout: 6h
179+
needs:
180+
- job: "build:msvc-meson"
181+
artifacts: true
182+
script:
183+
- meson test -C build --list | Select-Object -Skip 1 | Select-String .* | Group-Object -Property { $_.LineNumber % $Env:CI_NODE_TOTAL + 1 } | Where-Object Name -EQ $Env:CI_NODE_INDEX | ForEach-Object { meson test -C build --no-rebuild --print-errorlogs $_.Group }
184+
parallel: 10
185+
148186
test:fuzz-smoke-tests:
149187
image: ubuntu:latest
150188
stage: test

GIT-VERSION-GEN

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,29 @@ DEF_VER=v2.48.GIT
55
LF='
66
'
77

8-
if test "$#" -ne 3
8+
if test "$#" -lt 2 || test "$#" -gt 3
99
then
10-
echo >&2 "USAGE: $0 <SOURCE_DIR> <INPUT> <OUTPUT>"
10+
echo >&2 "USAGE: $0 <SOURCE_DIR> (--format=<STRING>|<INPUT>) [<OUTPUT>]"
1111
exit 1
1212
fi
1313

1414
SOURCE_DIR="$1"
15-
INPUT="$2"
16-
OUTPUT="$3"
1715

18-
if ! test -f "$INPUT"
19-
then
20-
echo >&2 "Input is not a file: $INPUT"
21-
exit 1
22-
fi
16+
case "$2" in
17+
--format=*)
18+
INPUT="${2#--format=}"
19+
;;
20+
*)
21+
if ! test -f "$2"
22+
then
23+
echo >&2 "Input is not a file: $2"
24+
exit 1
25+
fi
26+
INPUT=$(cat "$2")
27+
;;
28+
esac
29+
30+
OUTPUT="$3"
2331

2432
# Protect us from reading Git version information outside of the Git directory
2533
# in case it is not a repository itself, but embedded in an unrelated
@@ -39,13 +47,9 @@ then
3947
test -d "${GIT_DIR:-.git}" ||
4048
test -f "$SOURCE_DIR"/.git;
4149
} &&
42-
VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
50+
VN=$(git -C "$SOURCE_DIR" describe --dirty --match="v[0-9]*" 2>/dev/null) &&
4351
case "$VN" in
4452
*$LF*) (exit 1) ;;
45-
v[0-9]*)
46-
git -C "$SOURCE_DIR" update-index -q --refresh
47-
test -z "$(git -C "$SOURCE_DIR" diff-index --name-only HEAD --)" ||
48-
VN="$VN-dirty" ;;
4953
esac
5054
then
5155
VN=$(echo "$VN" | sed -e 's/-/./g');
@@ -78,19 +82,25 @@ read GIT_MAJOR_VERSION GIT_MINOR_VERSION GIT_MICRO_VERSION GIT_PATCH_LEVEL trail
7882
$(echo "$GIT_VERSION" 0 0 0 0 | tr '.a-zA-Z-' ' ')
7983
EOF
8084

81-
sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
85+
REPLACED=$(printf "%s" "$INPUT" | sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
8286
-e "s|@GIT_MAJOR_VERSION@|$GIT_MAJOR_VERSION|" \
8387
-e "s|@GIT_MINOR_VERSION@|$GIT_MINOR_VERSION|" \
8488
-e "s|@GIT_MICRO_VERSION@|$GIT_MICRO_VERSION|" \
8589
-e "s|@GIT_PATCH_LEVEL@|$GIT_PATCH_LEVEL|" \
8690
-e "s|@GIT_BUILT_FROM_COMMIT@|$GIT_BUILT_FROM_COMMIT|" \
8791
-e "s|@GIT_USER_AGENT@|$GIT_USER_AGENT|" \
88-
-e "s|@GIT_DATE@|$GIT_DATE|" \
89-
"$INPUT" >"$OUTPUT".$$+
92+
-e "s|@GIT_DATE@|$GIT_DATE|"
93+
)
9094

91-
if ! test -f "$OUTPUT" || ! cmp "$OUTPUT".$$+ "$OUTPUT" >/dev/null
95+
if test -z "$OUTPUT"
9296
then
93-
mv "$OUTPUT".$$+ "$OUTPUT"
97+
printf "%s\n" "$REPLACED"
9498
else
95-
rm "$OUTPUT".$$+
99+
printf "%s\n" "$REPLACED" >"$OUTPUT".$$+
100+
if ! test -f "$OUTPUT" || ! cmp "$OUTPUT".$$+ "$OUTPUT" >/dev/null
101+
then
102+
mv "$OUTPUT".$$+ "$OUTPUT"
103+
else
104+
rm "$OUTPUT".$$+
105+
fi
96106
fi

ci/run-build-and-tests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ esac
5353
case "$jobname" in
5454
*-meson)
5555
group "Configure" meson setup build . \
56+
--fatal-meson-warnings \
5657
--warnlevel 2 --werror \
57-
--wrap-mode nofallback
58+
--wrap-mode nofallback \
59+
-Dfuzzers=true
5860
group "Build" meson compile -C build --
5961
if test -n "$run_tests"
6062
then

meson.build

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,22 @@
170170

171171
project('git', 'c',
172172
meson_version: '>=0.61.0',
173-
version: 'v2.47.GIT',
173+
# The version is only of cosmetic nature, so if we cannot find a shell yet we
174+
# simply don't set up a version at all. This may be the case for example on
175+
# Windows systems, where we first have to bootstrap the host environment.
176+
version: find_program('sh', required: false).found() ? run_command(
177+
'GIT-VERSION-GEN', meson.current_source_dir(), '--format=@GIT_VERSION@',
178+
capture: true,
179+
check: true,
180+
).stdout().strip() : 'unknown',
181+
default_options: [
182+
# Git requires C99 with GNU extensions, which of course isn't supported by
183+
# MSVC. Funny enough, C99 doesn't work with MSVC either, as it has only
184+
# learned to define __STDC_VERSION__ with C11 and later. We thus require
185+
# GNU C99 and fall back to C11. Meson only learned to handle the fallback
186+
# with version 1.3.0, so on older versions we use GNU C99 unconditionally.
187+
'c_std=' + (meson.version().version_compare('>=1.3.0') ? 'gnu99,c11' : 'gnu99'),
188+
],
174189
)
175190

176191
fs = import('fs')
@@ -481,6 +496,13 @@ libgit_sources = [
481496
'xdiff/xutils.c',
482497
]
483498

499+
libgit_sources += custom_target(
500+
input: 'command-list.txt',
501+
output: 'command-list.h',
502+
command: [shell, meson.current_source_dir() + '/generate-cmdlist.sh', meson.current_source_dir(), '@OUTPUT@'],
503+
env: script_environment,
504+
)
505+
484506
builtin_sources = [
485507
'builtin/add.c',
486508
'builtin/am.c',
@@ -608,14 +630,7 @@ builtin_sources = [
608630
'builtin/write-tree.c',
609631
]
610632

611-
libgit_sources += custom_target(
612-
input: 'command-list.txt',
613-
output: 'command-list.h',
614-
command: [shell, meson.current_source_dir() + '/generate-cmdlist.sh', meson.current_source_dir(), '@OUTPUT@'],
615-
env: script_environment,
616-
)
617-
618-
libgit_sources += custom_target(
633+
builtin_sources += custom_target(
619634
output: 'config-list.h',
620635
command: [
621636
shell,
@@ -626,7 +641,7 @@ libgit_sources += custom_target(
626641
env: script_environment,
627642
)
628643

629-
libgit_sources += custom_target(
644+
builtin_sources += custom_target(
630645
input: 'Documentation/githooks.adoc',
631646
output: 'hook-list.h',
632647
command: [
@@ -1331,6 +1346,7 @@ if not meson.is_cross_build() and fs.exists('/dev/tty')
13311346
libgit_c_args += '-DHAVE_DEV_TTY'
13321347
endif
13331348

1349+
csprng_backend = get_option('csprng_backend')
13341350
https_backend = get_option('https_backend')
13351351
sha1_backend = get_option('sha1_backend')
13361352
sha1_unsafe_backend = get_option('sha1_unsafe_backend')
@@ -1342,7 +1358,7 @@ if https_backend == 'auto' and security_framework.found()
13421358
https_backend = 'CommonCrypto'
13431359
endif
13441360

1345-
openssl_required = 'openssl' in [https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1361+
openssl_required = 'openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
13461362
openssl = dependency('openssl', required: openssl_required, default_options: ['default_library=static'])
13471363
if https_backend == 'auto' and openssl.found()
13481364
https_backend = 'openssl'
@@ -1427,18 +1443,30 @@ else
14271443
error('Unhandled SHA256 backend ' + sha256_backend)
14281444
endif
14291445

1430-
if compiler.has_header_symbol('stdlib.h', 'arc4random_buf')
1446+
# Backends are ordered to reflect our preference for more secure and faster
1447+
# ones over the ones that are less so.
1448+
if csprng_backend in ['auto', 'arc4random'] and compiler.has_header_symbol('stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random')
14311449
libgit_c_args += '-DHAVE_ARC4RANDOM'
1432-
elif compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf')
1450+
csprng_backend = 'arc4random'
1451+
elif csprng_backend in ['auto', 'arc4random_bsd'] and compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random_bsd')
14331452
libgit_c_args += '-DHAVE_ARC4RANDOM_BSD'
1434-
elif compiler.has_function('getrandom', prefix: '#include <sys/random.h>')
1453+
csprng_backend = 'arc4random_bsd'
1454+
elif csprng_backend in ['auto', 'getrandom'] and compiler.has_header_symbol('sys/random.h', 'getrandom', required: csprng_backend == 'getrandom')
14351455
libgit_c_args += '-DHAVE_GETRANDOM'
1436-
elif compiler.has_function('getentropy', prefix: '#include <unistd.h>')
1456+
csprng_backend = 'getrandom'
1457+
elif csprng_backend in ['auto', 'getentropy'] and compiler.has_header_symbol('unistd.h', 'getentropy', required: csprng_backend == 'getentropy')
14371458
libgit_c_args += '-DHAVE_GETENTROPY'
1438-
elif compiler.has_function('RtlGenRandom', prefix: '#include <windows.h>\n#include <ntsecapi.h>')
1459+
csprng_backend = 'getentropy'
1460+
elif csprng_backend in ['auto', 'rtlgenrandom'] and compiler.has_header_symbol('ntsecapi.h', 'RtlGenRandom', prefix: '#include <windows.h>', required: csprng_backend == 'rtlgenrandom')
14391461
libgit_c_args += '-DHAVE_RTLGENRANDOM'
1440-
elif openssl.found()
1462+
csprng_backend = 'rtlgenrandom'
1463+
elif csprng_backend in ['auto', 'openssl'] and openssl.found()
14411464
libgit_c_args += '-DHAVE_OPENSSL_CSPRNG'
1465+
csprng_backend = 'openssl'
1466+
elif csprng_backend in ['auto', 'urandom']
1467+
csprng_backend = 'urandom'
1468+
else
1469+
error('Unsupported CSPRNG backend: ' + csprng_backend)
14421470
endif
14431471

14441472
if get_option('runtime_prefix')
@@ -1906,6 +1934,10 @@ if get_option('tests')
19061934
subdir('t')
19071935
endif
19081936

1937+
if get_option('fuzzers')
1938+
subdir('oss-fuzz')
1939+
endif
1940+
19091941
subdir('bin-wrappers')
19101942
if get_option('docs') != []
19111943
subdir('Documentation')
@@ -1941,6 +1973,27 @@ configure_file(
19411973
configuration: build_options_config,
19421974
)
19431975

1976+
# Development environments can be used via `meson devenv -C <builddir>`. This
1977+
# allows you to execute test scripts directly with the built Git version and
1978+
# puts the built version of Git in your PATH.
1979+
devenv = environment()
1980+
devenv.set('GIT_BUILD_DIR', meson.current_build_dir())
1981+
devenv.prepend('PATH', meson.current_build_dir() / 'bin-wrappers')
1982+
meson.add_devenv(devenv)
1983+
1984+
# Generate the 'version' file in the distribution tarball. This is used via
1985+
# `meson dist -C <builddir>` to populate the source archive with the Git
1986+
# version that the archive is being generated from.
1987+
meson.add_dist_script(
1988+
shell,
1989+
'-c',
1990+
'"$1" "$2" "$3" --format="@GIT_VERSION@" "$MESON_DIST_ROOT/version"',
1991+
'GIT-VERSION-GEN',
1992+
shell,
1993+
meson.current_source_dir() / 'GIT-VERSION-GEN',
1994+
meson.current_source_dir(),
1995+
)
1996+
19441997
summary({
19451998
'curl': curl.found(),
19461999
'expat': expat.found(),
@@ -1954,6 +2007,7 @@ summary({
19542007
}, section: 'Auto-detected features')
19552008

19562009
summary({
2010+
'csprng': csprng_backend,
19572011
'https': https_backend,
19582012
'sha1': sha1_backend,
19592013
'sha1_unsafe': sha1_unsafe_backend,

meson_options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ option('regex', type: 'feature', value: 'auto',
4949
description: 'Use the system-provided regex library instead of the bundled one.')
5050

5151
# Backends.
52+
option('csprng_backend', type: 'combo', value: 'auto', choices: ['auto', 'arc4random', 'arc4random_bsd', 'getrandom', 'getentropy', 'rtlgenrandom', 'openssl', 'urandom'],
53+
description: 'The backend to use for generating cryptographically-secure pseudo-random numbers.')
5254
option('https_backend', type: 'combo', value: 'auto', choices: ['auto', 'openssl', 'CommonCrypto', 'none'],
5355
description: 'The HTTPS backend to use when connecting to remotes.')
5456
option('sha1_backend', type: 'combo', choices: ['openssl', 'block', 'sha1dc', 'CommonCrypto'], value: 'sha1dc',
@@ -99,3 +101,5 @@ option('tests', type: 'boolean', value: true,
99101
description: 'Enable building tests. This requires Perl, but is separate from the "perl" option such that you can build tests without Perl features enabled.')
100102
option('test_output_directory', type: 'string',
101103
description: 'Path to the directory used to store test outputs')
104+
option('fuzzers', type: 'boolean', value: false,
105+
description: 'Enable building fuzzers.')

0 commit comments

Comments
 (0)