170
170
171
171
project (' git' , ' c' ,
172
172
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
+ ],
174
189
)
175
190
176
191
fs = import (' fs' )
@@ -481,6 +496,13 @@ libgit_sources = [
481
496
' xdiff/xutils.c' ,
482
497
]
483
498
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
+
484
506
builtin_sources = [
485
507
' builtin/add.c' ,
486
508
' builtin/am.c' ,
@@ -608,14 +630,7 @@ builtin_sources = [
608
630
' builtin/write-tree.c' ,
609
631
]
610
632
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 (
619
634
output : ' config-list.h' ,
620
635
command : [
621
636
shell,
@@ -626,7 +641,7 @@ libgit_sources += custom_target(
626
641
env : script_environment,
627
642
)
628
643
629
- libgit_sources += custom_target (
644
+ builtin_sources += custom_target (
630
645
input : ' Documentation/githooks.txt' ,
631
646
output : ' hook-list.h' ,
632
647
command : [
@@ -1325,6 +1340,7 @@ if not meson.is_cross_build() and fs.exists('/dev/tty')
1325
1340
libgit_c_args += ' -DHAVE_DEV_TTY'
1326
1341
endif
1327
1342
1343
+ csprng_backend = get_option (' csprng_backend' )
1328
1344
https_backend = get_option (' https_backend' )
1329
1345
sha1_backend = get_option (' sha1_backend' )
1330
1346
sha1_unsafe_backend = get_option (' sha1_unsafe_backend' )
@@ -1336,7 +1352,7 @@ if https_backend == 'auto' and security_framework.found()
1336
1352
https_backend = ' CommonCrypto'
1337
1353
endif
1338
1354
1339
- openssl_required = ' openssl' in [https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1355
+ openssl_required = ' openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1340
1356
openssl = dependency (' openssl' , required : openssl_required, default_options : [' default_library=static' ])
1341
1357
if https_backend == ' auto' and openssl.found()
1342
1358
https_backend = ' openssl'
@@ -1421,18 +1437,30 @@ else
1421
1437
error (' Unhandled SHA256 backend ' + sha256_backend)
1422
1438
endif
1423
1439
1424
- if compiler.has_header_symbol(' stdlib.h' , ' arc4random_buf' )
1440
+ # Backends are ordered to reflect our preference for more secure and faster
1441
+ # ones over the ones that are less so.
1442
+ if csprng_backend in [' auto' , ' arc4random' ] and compiler.has_header_symbol(' stdlib.h' , ' arc4random_buf' , required : csprng_backend == ' arc4random' )
1425
1443
libgit_c_args += ' -DHAVE_ARC4RANDOM'
1426
- elif compiler.has_header_symbol(' bsd/stdlib.h' , ' arc4random_buf' )
1444
+ csprng_backend = ' arc4random'
1445
+ elif csprng_backend in [' auto' , ' arc4random_bsd' ] and compiler.has_header_symbol(' bsd/stdlib.h' , ' arc4random_buf' , required : csprng_backend == ' arc4random_bsd' )
1427
1446
libgit_c_args += ' -DHAVE_ARC4RANDOM_BSD'
1428
- elif compiler.has_function(' getrandom' , prefix : ' #include <sys/random.h>' )
1447
+ csprng_backend = ' arc4random_bsd'
1448
+ elif csprng_backend in [' auto' , ' getrandom' ] and compiler.has_header_symbol(' sys/random.h' , ' getrandom' , required : csprng_backend == ' getrandom' )
1429
1449
libgit_c_args += ' -DHAVE_GETRANDOM'
1430
- elif compiler.has_function(' getentropy' , prefix : ' #include <unistd.h>' )
1450
+ csprng_backend = ' getrandom'
1451
+ elif csprng_backend in [' auto' , ' getentropy' ] and compiler.has_header_symbol(' unistd.h' , ' getentropy' , required : csprng_backend == ' getentropy' )
1431
1452
libgit_c_args += ' -DHAVE_GETENTROPY'
1432
- elif compiler.has_function(' RtlGenRandom' , prefix : ' #include <windows.h>\n #include <ntsecapi.h>' )
1453
+ csprng_backend = ' getentropy'
1454
+ elif csprng_backend in [' auto' , ' rtlgenrandom' ] and compiler.has_header_symbol(' ntsecapi.h' , ' RtlGenRandom' , prefix : ' #include <windows.h>' , required : csprng_backend == ' rtlgenrandom' )
1433
1455
libgit_c_args += ' -DHAVE_RTLGENRANDOM'
1434
- elif openssl.found()
1456
+ csprng_backend = ' rtlgenrandom'
1457
+ elif csprng_backend in [' auto' , ' openssl' ] and openssl.found()
1435
1458
libgit_c_args += ' -DHAVE_OPENSSL_CSPRNG'
1459
+ csprng_backend = ' openssl'
1460
+ elif csprng_backend in [' auto' , ' urandom' ]
1461
+ csprng_backend = ' urandom'
1462
+ else
1463
+ error (' Unsupported CSPRNG backend: ' + csprng_backend)
1436
1464
endif
1437
1465
1438
1466
if get_option (' runtime_prefix' )
@@ -1900,6 +1928,10 @@ if get_option('tests')
1900
1928
subdir (' t' )
1901
1929
endif
1902
1930
1931
+ if get_option (' fuzzers' )
1932
+ subdir (' oss-fuzz' )
1933
+ endif
1934
+
1903
1935
subdir (' bin-wrappers' )
1904
1936
if get_option (' docs' ) != []
1905
1937
subdir (' Documentation' )
@@ -1935,6 +1967,27 @@ configure_file(
1935
1967
configuration : build_options_config,
1936
1968
)
1937
1969
1970
+ # Development environments can be used via `meson devenv -C <builddir>`. This
1971
+ # allows you to execute test scripts directly with the built Git version and
1972
+ # puts the built version of Git in your PATH.
1973
+ devenv = environment ()
1974
+ devenv.set(' GIT_BUILD_DIR' , meson .current_build_dir())
1975
+ devenv.prepend(' PATH' , meson .current_build_dir() / ' bin-wrappers' )
1976
+ meson .add_devenv(devenv)
1977
+
1978
+ # Generate the 'version' file in the distribution tarball. This is used via
1979
+ # `meson dist -C <builddir>` to populate the source archive with the Git
1980
+ # version that the archive is being generated from.
1981
+ meson .add_dist_script(
1982
+ shell,
1983
+ ' -c' ,
1984
+ ' "$1" "$2" "$3" --format="@GIT_VERSION@" "$MESON_DIST_ROOT/version"' ,
1985
+ ' GIT-VERSION-GEN' ,
1986
+ shell,
1987
+ meson .current_source_dir() / ' GIT-VERSION-GEN' ,
1988
+ meson .current_source_dir(),
1989
+ )
1990
+
1938
1991
summary ({
1939
1992
' curl' : curl.found(),
1940
1993
' expat' : expat.found(),
@@ -1948,6 +2001,7 @@ summary({
1948
2001
}, section : ' Auto-detected features' )
1949
2002
1950
2003
summary ({
2004
+ ' csprng' : csprng_backend,
1951
2005
' https' : https_backend,
1952
2006
' sha1' : sha1_backend,
1953
2007
' sha1_unsafe' : sha1_unsafe_backend,
0 commit comments