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' )
@@ -480,6 +495,13 @@ libgit_sources = [
480
495
' xdiff/xutils.c' ,
481
496
]
482
497
498
+ libgit_sources += custom_target (
499
+ input : ' command-list.txt' ,
500
+ output : ' command-list.h' ,
501
+ command : [shell, meson .current_source_dir() + ' /generate-cmdlist.sh' , meson .current_source_dir(), ' @OUTPUT@' ],
502
+ env : script_environment,
503
+ )
504
+
483
505
builtin_sources = [
484
506
' builtin/add.c' ,
485
507
' builtin/am.c' ,
@@ -607,14 +629,7 @@ builtin_sources = [
607
629
' builtin/write-tree.c' ,
608
630
]
609
631
610
- libgit_sources += custom_target (
611
- input : ' command-list.txt' ,
612
- output : ' command-list.h' ,
613
- command : [shell, meson .current_source_dir() + ' /generate-cmdlist.sh' , meson .current_source_dir(), ' @OUTPUT@' ],
614
- env : script_environment,
615
- )
616
-
617
- libgit_sources += custom_target (
632
+ builtin_sources += custom_target (
618
633
output : ' config-list.h' ,
619
634
command : [
620
635
shell,
@@ -625,7 +640,7 @@ libgit_sources += custom_target(
625
640
env : script_environment,
626
641
)
627
642
628
- libgit_sources += custom_target (
643
+ builtin_sources += custom_target (
629
644
input : ' Documentation/githooks.txt' ,
630
645
output : ' hook-list.h' ,
631
646
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' )
@@ -1899,6 +1927,10 @@ if get_option('tests')
1899
1927
subdir (' t' )
1900
1928
endif
1901
1929
1930
+ if get_option (' fuzzers' )
1931
+ subdir (' oss-fuzz' )
1932
+ endif
1933
+
1902
1934
subdir (' bin-wrappers' )
1903
1935
if get_option (' docs' ) != []
1904
1936
subdir (' Documentation' )
@@ -1932,6 +1964,27 @@ configure_file(
1932
1964
configuration : build_options_config,
1933
1965
)
1934
1966
1967
+ # Development environments can be used via `meson devenv -C <builddir>`. This
1968
+ # allows you to execute test scripts directly with the built Git version and
1969
+ # puts the built version of Git in your PATH.
1970
+ devenv = environment ()
1971
+ devenv.set(' GIT_BUILD_DIR' , meson .current_build_dir())
1972
+ devenv.prepend(' PATH' , meson .current_build_dir() / ' bin-wrappers' )
1973
+ meson .add_devenv(devenv)
1974
+
1975
+ # Generate the 'version' file in the distribution tarball. This is used via
1976
+ # `meson dist -C <builddir>` to populate the source archive with the Git
1977
+ # version that the archive is being generated from.
1978
+ meson .add_dist_script(
1979
+ shell,
1980
+ ' -c' ,
1981
+ ' "$1" "$2" "$3" --format="@GIT_VERSION@" "$MESON_DIST_ROOT/version"' ,
1982
+ ' GIT-VERSION-GEN' ,
1983
+ shell,
1984
+ meson .current_source_dir() / ' GIT-VERSION-GEN' ,
1985
+ meson .current_source_dir(),
1986
+ )
1987
+
1935
1988
summary ({
1936
1989
' curl' : curl.found(),
1937
1990
' expat' : expat.found(),
@@ -1945,6 +1998,7 @@ summary({
1945
1998
}, section : ' Auto-detected features' )
1946
1999
1947
2000
summary ({
2001
+ ' csprng' : csprng_backend,
1948
2002
' https' : https_backend,
1949
2003
' sha1' : sha1_backend,
1950
2004
' sha1_unsafe' : sha1_unsafe_backend,
0 commit comments