Merge branch 'ps/build-meson-fixes-0130'

Assorted fixes and improvements to the build procedure based on
meson.

* ps/build-meson-fixes-0130:
  gitlab-ci: restrict maximum number of link jobs on Windows
  meson: consistently use custom program paths to resolve programs
  meson: fix overwritten `git` variable
  meson: prevent finding sed(1) in a loop
  meson: improve handling of `sane_tool_path` option
  meson: improve PATH handling
  meson: drop separate version library
  meson: stop linking libcurl into all executables
  meson: introduce `libgit_curl` dependency
  meson: simplify use of the common-main library
  meson: inline the static 'git' library
  meson: fix OpenSSL fallback when not explicitly required
  meson: fix exec path with enabled runtime prefix
This commit is contained in:
Junio C Hamano
2025-03-03 08:53:01 -08:00
8 changed files with 89 additions and 98 deletions

View File

@ -164,7 +164,7 @@ build:msvc-meson:
extends: .msvc-meson extends: .msvc-meson
stage: build stage: build
script: script:
- meson setup build -Dperl=disabled - meson setup build -Dperl=disabled -Dbackend_max_links=1
- meson compile -C build - meson compile -C build
artifacts: artifacts:
paths: paths:

View File

@ -41,7 +41,7 @@ custom_target(
foreach howto : howto_sources foreach howto : howto_sources
howto_stripped = custom_target( howto_stripped = custom_target(
command: [ command: [
find_program('sed'), sed,
'-e', '-e',
'1,/^$/d', '1,/^$/d',
'@INPUT@', '@INPUT@',

View File

@ -207,9 +207,9 @@ manpages = {
docs_backend = get_option('docs_backend') docs_backend = get_option('docs_backend')
if docs_backend == 'auto' if docs_backend == 'auto'
if find_program('asciidoc', required: false).found() if find_program('asciidoc', dirs: program_path, required: false).found()
docs_backend = 'asciidoc' docs_backend = 'asciidoc'
elif find_program('asciidoctor', required: false).found() elif find_program('asciidoctor', dirs: program_path, required: false).found()
docs_backend = 'asciidoctor' docs_backend = 'asciidoctor'
else else
error('Neither asciidoc nor asciidoctor were found.') error('Neither asciidoc nor asciidoctor were found.')
@ -217,7 +217,7 @@ if docs_backend == 'auto'
endif endif
if docs_backend == 'asciidoc' if docs_backend == 'asciidoc'
asciidoc = find_program('asciidoc', required: true) asciidoc = find_program('asciidoc', dirs: program_path)
asciidoc_html = 'xhtml11' asciidoc_html = 'xhtml11'
asciidoc_docbook = 'docbook' asciidoc_docbook = 'docbook'
xmlto_extra = [ ] xmlto_extra = [ ]
@ -246,7 +246,7 @@ if docs_backend == 'asciidoc'
asciidoc_conf, asciidoc_conf,
] ]
elif docs_backend == 'asciidoctor' elif docs_backend == 'asciidoctor'
asciidoctor = find_program('asciidoctor', required: true) asciidoctor = find_program('asciidoctor', dirs: program_path)
asciidoc_html = 'xhtml5' asciidoc_html = 'xhtml5'
asciidoc_docbook = 'docbook5' asciidoc_docbook = 'docbook5'
xmlto_extra = [ xmlto_extra = [
@ -284,8 +284,7 @@ elif docs_backend == 'asciidoctor'
] ]
endif endif
git = find_program('git', required: false) xmlto = find_program('xmlto', dirs: program_path)
xmlto = find_program('xmlto')
cmd_lists = [ cmd_lists = [
'cmds-ancillaryinterrogators.adoc', 'cmds-ancillaryinterrogators.adoc',
@ -406,7 +405,7 @@ if get_option('docs').contains('html')
pointing_to: 'git.html', pointing_to: 'git.html',
) )
xsltproc = find_program('xsltproc') xsltproc = find_program('xsltproc', dirs: program_path)
user_manual_xml = custom_target( user_manual_xml = custom_target(
command: asciidoc_common_options + [ command: asciidoc_common_options + [

View File

@ -191,30 +191,29 @@ project('git', 'c',
fs = import('fs') fs = import('fs')
program_path = [] program_path = []
# Git for Windows provides all the tools we need to build Git. if get_option('sane_tool_path').length() != 0
if host_machine.system() == 'windows' program_path = get_option('sane_tool_path')
program_path += [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ] elif host_machine.system() == 'windows'
# Git for Windows provides all the tools we need to build Git.
program_path = [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ]
endif endif
cygpath = find_program('cygpath', dirs: program_path, required: false) cygpath = find_program('cygpath', dirs: program_path, required: false)
diff = find_program('diff', dirs: program_path) diff = find_program('diff', dirs: program_path)
git = find_program('git', dirs: program_path, required: false)
sed = find_program('sed', dirs: program_path)
shell = find_program('sh', dirs: program_path) shell = find_program('sh', dirs: program_path)
tar = find_program('tar', dirs: program_path) tar = find_program('tar', dirs: program_path)
script_environment = environment() # Sanity-check that programs required for the build exist.
foreach tool : ['cat', 'cut', 'grep', 'sed', 'sort', 'tr', 'uname'] foreach tool : ['cat', 'cut', 'grep', 'sort', 'tr', 'uname']
program = find_program(tool, dirs: program_path) find_program(tool, dirs: program_path)
script_environment.prepend('PATH', fs.parent(program.full_path()))
endforeach endforeach
git = find_program('git', dirs: program_path, required: false) script_environment = environment()
if git.found() foreach path : program_path
script_environment.prepend('PATH', fs.parent(git.full_path())) script_environment.prepend('PATH', path)
endif endforeach
if get_option('sane_tool_path') != ''
script_environment.prepend('PATH', get_option('sane_tool_path'))
endif
# The environment used by GIT-VERSION-GEN. Note that we explicitly override # The environment used by GIT-VERSION-GEN. Note that we explicitly override
# environment variables that might be set by the user. This is by design so # environment variables that might be set by the user. This is by design so
@ -479,6 +478,7 @@ libgit_sources = [
'userdiff.c', 'userdiff.c',
'utf8.c', 'utf8.c',
'varint.c', 'varint.c',
'version.c',
'versioncmp.c', 'versioncmp.c',
'walker.c', 'walker.c',
'wildmatch.c', 'wildmatch.c',
@ -678,8 +678,9 @@ else
build_options_config.set('WITH_BREAKING_CHANGES', '') build_options_config.set('WITH_BREAKING_CHANGES', '')
endif endif
if get_option('sane_tool_path') != '' if get_option('sane_tool_path').length() != 0
build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + get_option('sane_tool_path') + '"|') sane_tool_path = (host_machine.system() == 'windows' ? ';' : ':').join(get_option('sane_tool_path'))
build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + sane_tool_path + '"|')
else else
build_options_config.set_quoted('BROKEN_PATH_FIX', '/^\# @BROKEN_PATH_FIX@$/d') build_options_config.set_quoted('BROKEN_PATH_FIX', '/^\# @BROKEN_PATH_FIX@$/d')
endif endif
@ -699,7 +700,6 @@ libgit_c_args = [
'-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"', '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
'-DETC_GITCONFIG="' + get_option('gitconfig') + '"', '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
'-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"', '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
'-DGIT_EXEC_PATH="' + get_option('prefix') / get_option('libexecdir') / 'git-core"',
'-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"', '-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"',
'-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"', '-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"',
'-DGIT_INFO_PATH="' + get_option('infodir') + '"', '-DGIT_INFO_PATH="' + get_option('infodir') + '"',
@ -963,7 +963,9 @@ if curl.found()
use_curl_for_imap_send = true use_curl_for_imap_send = true
endif endif
libgit_dependencies += curl # Most executables don't have to link against libcurl, but we still need its
# include directories so that we can resolve LIBCURL_VERSION in "help.c".
libgit_dependencies += curl.partial_dependency(includes: true)
libgit_c_args += '-DCURL_DISABLE_TYPECHECK' libgit_c_args += '-DCURL_DISABLE_TYPECHECK'
build_options_config.set('NO_CURL', '') build_options_config.set('NO_CURL', '')
else else
@ -1388,7 +1390,11 @@ if https_backend == 'auto' and security_framework.found()
endif endif
openssl_required = 'openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend] openssl_required = 'openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
openssl = dependency('openssl', required: openssl_required, default_options: ['default_library=static']) openssl = dependency('openssl',
required: openssl_required,
allow_fallback: openssl_required or https_backend == 'auto',
default_options: ['default_library=static'],
)
if https_backend == 'auto' and openssl.found() if https_backend == 'auto' and openssl.found()
https_backend = 'openssl' https_backend = 'openssl'
endif endif
@ -1402,6 +1408,7 @@ elif https_backend == 'openssl'
else else
# We either couldn't find any dependencies with 'auto' or the user requested # We either couldn't find any dependencies with 'auto' or the user requested
# 'none'. Both cases are benign. # 'none'. Both cases are benign.
https_backend = 'none'
endif endif
if https_backend != 'openssl' if https_backend != 'openssl'
@ -1501,6 +1508,7 @@ endif
if get_option('runtime_prefix') if get_option('runtime_prefix')
libgit_c_args += '-DRUNTIME_PREFIX' libgit_c_args += '-DRUNTIME_PREFIX'
build_options_config.set('RUNTIME_PREFIX', 'true') build_options_config.set('RUNTIME_PREFIX', 'true')
git_exec_path = get_option('libexecdir') / 'git-core'
if compiler.has_header('mach-o/dyld.h') if compiler.has_header('mach-o/dyld.h')
libgit_c_args += '-DHAVE_NS_GET_EXECUTABLE_PATH' libgit_c_args += '-DHAVE_NS_GET_EXECUTABLE_PATH'
@ -1537,7 +1545,9 @@ if get_option('runtime_prefix')
endif endif
else else
build_options_config.set('RUNTIME_PREFIX', 'false') build_options_config.set('RUNTIME_PREFIX', 'false')
git_exec_path = get_option('prefix') / get_option('libexecdir') / 'git-core'
endif endif
libgit_c_args += '-DGIT_EXEC_PATH="' + git_exec_path + '"'
git_version_file = custom_target( git_version_file = custom_target(
command: [ command: [
@ -1568,32 +1578,18 @@ version_def_h = custom_target(
depends: [git_version_file], depends: [git_version_file],
env: version_gen_environment, env: version_gen_environment,
) )
libgit_sources += version_def_h
# Build a separate library for "version.c" so that we do not have to rebuild
# everything when the current Git commit changes.
libgit_version_library = static_library('git-version',
sources: [
'version.c',
version_def_h,
],
c_args: libgit_c_args + [
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
],
dependencies: libgit_dependencies,
include_directories: libgit_include_directories,
)
libgit_library = static_library('git',
sources: libgit_sources,
c_args: libgit_c_args,
link_with: libgit_version_library,
dependencies: libgit_dependencies,
include_directories: libgit_include_directories,
)
libgit = declare_dependency( libgit = declare_dependency(
link_with: static_library('git',
sources: libgit_sources,
c_args: libgit_c_args + [
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
],
dependencies: libgit_dependencies,
include_directories: libgit_include_directories,
),
compile_args: libgit_c_args, compile_args: libgit_c_args,
link_with: libgit_library,
dependencies: libgit_dependencies, dependencies: libgit_dependencies,
include_directories: libgit_include_directories, include_directories: libgit_include_directories,
) )
@ -1634,88 +1630,89 @@ if host_machine.system() == 'windows'
error('Unsupported compiler ' + compiler.get_id()) error('Unsupported compiler ' + compiler.get_id())
endif endif
endif endif
common_main_library = static_library('common-main',
sources: common_main_sources, libgit_commonmain = declare_dependency(
c_args: libgit_c_args, link_with: static_library('common-main',
dependencies: libgit_dependencies, sources: common_main_sources,
include_directories: libgit_include_directories, dependencies: [ libgit ],
) ),
common_main = declare_dependency(
link_with: common_main_library,
link_args: common_main_link_args, link_args: common_main_link_args,
dependencies: [ libgit ],
) )
bin_wrappers = [ ] bin_wrappers = [ ]
test_dependencies = [ ] test_dependencies = [ ]
git = executable('git', git_builtin = executable('git',
sources: builtin_sources + 'git.c', sources: builtin_sources + 'git.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
bin_wrappers += git bin_wrappers += git_builtin
test_dependencies += executable('git-daemon', test_dependencies += executable('git-daemon',
sources: 'daemon.c', sources: 'daemon.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
test_dependencies += executable('git-sh-i18n--envsubst', test_dependencies += executable('git-sh-i18n--envsubst',
sources: 'sh-i18n--envsubst.c', sources: 'sh-i18n--envsubst.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
bin_wrappers += executable('git-shell', bin_wrappers += executable('git-shell',
sources: 'shell.c', sources: 'shell.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
test_dependencies += executable('git-http-backend', test_dependencies += executable('git-http-backend',
sources: 'http-backend.c', sources: 'http-backend.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
bin_wrappers += executable('scalar', bin_wrappers += executable('scalar',
sources: 'scalar.c', sources: 'scalar.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
if get_option('curl').enabled() if get_option('curl').enabled()
curl_sources = [ libgit_curl = declare_dependency(
'http.c', sources: [
'http-walker.c', 'http.c',
] 'http-walker.c',
],
dependencies: [libgit_commonmain, curl],
)
git_remote_http = executable('git-remote-http', test_dependencies += executable('git-remote-http',
sources: curl_sources + 'remote-curl.c', sources: 'remote-curl.c',
dependencies: [libgit, common_main], dependencies: [libgit_curl],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
test_dependencies += git_remote_http
test_dependencies += executable('git-http-fetch', test_dependencies += executable('git-http-fetch',
sources: curl_sources + 'http-fetch.c', sources: 'http-fetch.c',
dependencies: [libgit, common_main], dependencies: [libgit_curl],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
if expat.found() if expat.found()
test_dependencies += executable('git-http-push', test_dependencies += executable('git-http-push',
sources: curl_sources + 'http-push.c', sources: 'http-push.c',
dependencies: [libgit, common_main], dependencies: [libgit_curl],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
@ -1723,8 +1720,8 @@ if get_option('curl').enabled()
foreach alias : [ 'git-remote-https', 'git-remote-ftp', 'git-remote-ftps' ] foreach alias : [ 'git-remote-https', 'git-remote-ftp', 'git-remote-ftps' ]
test_dependencies += executable(alias, test_dependencies += executable(alias,
objects: git_remote_http.extract_all_objects(recursive: false), sources: 'remote-curl.c',
dependencies: [libgit, common_main], dependencies: [libgit_curl],
) )
install_symlink(alias + executable_suffix, install_symlink(alias + executable_suffix,
@ -1734,22 +1731,17 @@ if get_option('curl').enabled()
endforeach endforeach
endif endif
imap_send_sources = ['imap-send.c']
if use_curl_for_imap_send
imap_send_sources += curl_sources
endif
test_dependencies += executable('git-imap-send', test_dependencies += executable('git-imap-send',
sources: imap_send_sources, sources: 'imap-send.c',
dependencies: [libgit, common_main], dependencies: [ use_curl_for_imap_send ? libgit_curl : libgit_commonmain ],
install: true, install: true,
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )
foreach alias : [ 'git-receive-pack', 'git-upload-archive', 'git-upload-pack' ] foreach alias : [ 'git-receive-pack', 'git-upload-archive', 'git-upload-pack' ]
bin_wrappers += executable(alias, bin_wrappers += executable(alias,
objects: git.extract_all_objects(recursive: false), objects: git_builtin.extract_all_objects(recursive: false),
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
) )
install_symlink(alias + executable_suffix, install_symlink(alias + executable_suffix,

View File

@ -13,8 +13,8 @@ option('perl_cpan_fallback', type: 'boolean', value: true,
description: 'Install bundled copies of CPAN modules that serve as a fallback in case the modules are not available on the system.') description: 'Install bundled copies of CPAN modules that serve as a fallback in case the modules are not available on the system.')
option('runtime_prefix', type: 'boolean', value: false, option('runtime_prefix', type: 'boolean', value: false,
description: 'Resolve ancillary tooling and support files relative to the location of the runtime binary instead of hard-coding them into the binary.') description: 'Resolve ancillary tooling and support files relative to the location of the runtime binary instead of hard-coding them into the binary.')
option('sane_tool_path', type: 'string', value: '', option('sane_tool_path', type: 'array', value: [],
description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.') description: 'An array of paths to pick up tools from in case the normal tools are broken or lacking.')
# Build information compiled into Git and other parts like documentation. # Build information compiled into Git and other parts like documentation.
option('build_date', type: 'string', value: '', option('build_date', type: 'string', value: '',

View File

@ -15,6 +15,6 @@ foreach fuzz_program : fuzz_programs
'dummy-cmd-main.c', 'dummy-cmd-main.c',
fuzz_program, fuzz_program,
], ],
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
) )
endforeach endforeach

View File

@ -80,14 +80,14 @@ test_tool_sources = [
test_tool = executable('test-tool', test_tool = executable('test-tool',
sources: test_tool_sources, sources: test_tool_sources,
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
) )
bin_wrappers += test_tool bin_wrappers += test_tool
test_dependencies += test_tool test_dependencies += test_tool
test_fake_ssh = executable('test-fake-ssh', test_fake_ssh = executable('test-fake-ssh',
sources: 'test-fake-ssh.c', sources: 'test-fake-ssh.c',
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
) )
bin_wrappers += test_fake_ssh bin_wrappers += test_fake_ssh
test_dependencies += test_fake_ssh test_dependencies += test_fake_ssh

View File

@ -43,7 +43,7 @@ clar_sources += custom_target(
clar_unit_tests = executable('unit-tests', clar_unit_tests = executable('unit-tests',
sources: clar_sources + clar_test_suites, sources: clar_sources + clar_test_suites,
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
) )
test('unit-tests', clar_unit_tests) test('unit-tests', clar_unit_tests)
@ -72,7 +72,7 @@ foreach unit_test_program : unit_test_programs
'unit-tests/lib-reftable.c', 'unit-tests/lib-reftable.c',
unit_test_program, unit_test_program,
], ],
dependencies: [libgit, common_main], dependencies: [libgit_commonmain],
) )
test(unit_test_name, unit_test, test(unit_test_name, unit_test,
workdir: meson.current_source_dir(), workdir: meson.current_source_dir(),