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.adoc' ,
631
646
output : ' hook-list.h' ,
632
647
command : [
@@ -1331,6 +1346,7 @@ if not meson.is_cross_build() and fs.exists('/dev/tty')
1331
1346
libgit_c_args += ' -DHAVE_DEV_TTY'
1332
1347
endif
1333
1348
1349
+ csprng_backend = get_option (' csprng_backend' )
1334
1350
https_backend = get_option (' https_backend' )
1335
1351
sha1_backend = get_option (' sha1_backend' )
1336
1352
sha1_unsafe_backend = get_option (' sha1_unsafe_backend' )
@@ -1342,7 +1358,7 @@ if https_backend == 'auto' and security_framework.found()
1342
1358
https_backend = ' CommonCrypto'
1343
1359
endif
1344
1360
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]
1346
1362
openssl = dependency (' openssl' , required : openssl_required, default_options : [' default_library=static' ])
1347
1363
if https_backend == ' auto' and openssl.found()
1348
1364
https_backend = ' openssl'
@@ -1427,18 +1443,30 @@ else
1427
1443
error (' Unhandled SHA256 backend ' + sha256_backend)
1428
1444
endif
1429
1445
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' )
1431
1449
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' )
1433
1452
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' )
1435
1455
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' )
1437
1458
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' )
1439
1461
libgit_c_args += ' -DHAVE_RTLGENRANDOM'
1440
- elif openssl.found()
1462
+ csprng_backend = ' rtlgenrandom'
1463
+ elif csprng_backend in [' auto' , ' openssl' ] and openssl.found()
1441
1464
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)
1442
1470
endif
1443
1471
1444
1472
if get_option (' runtime_prefix' )
@@ -1906,6 +1934,10 @@ if get_option('tests')
1906
1934
subdir (' t' )
1907
1935
endif
1908
1936
1937
+ if get_option (' fuzzers' )
1938
+ subdir (' oss-fuzz' )
1939
+ endif
1940
+
1909
1941
subdir (' bin-wrappers' )
1910
1942
if get_option (' docs' ) != []
1911
1943
subdir (' Documentation' )
@@ -1941,6 +1973,27 @@ configure_file(
1941
1973
configuration : build_options_config,
1942
1974
)
1943
1975
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
+
1944
1997
summary ({
1945
1998
' curl' : curl.found(),
1946
1999
' expat' : expat.found(),
@@ -1954,6 +2007,7 @@ summary({
1954
2007
}, section : ' Auto-detected features' )
1955
2008
1956
2009
summary ({
2010
+ ' csprng' : csprng_backend,
1957
2011
' https' : https_backend,
1958
2012
' sha1' : sha1_backend,
1959
2013
' sha1_unsafe' : sha1_unsafe_backend,
0 commit comments