From 58288748e2dc44444704132b7ba647695053e8e8 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Tue, 6 Oct 2026 15:21:56 -0700 Subject: [PATCH] build: add Bazel definitions Build Git and its C and shell helpers from a source archive, using the consuming workspace's dependencies and toolchain configuration. Adapt the registry's platform configuration for GNU Windows, PCRE2, native zlib-ng, iconv, and relocatable runtime paths. Reuse Git's source generators and retain the registry license and attribution. --- BUILD.bazel | 289 ++++++++++++++++++++++++++++++++ contrib/bazel/BUILD.bazel | 1 + contrib/bazel/LICENSE.registry | 202 ++++++++++++++++++++++ contrib/bazel/README.md | 17 ++ contrib/bazel/config.bzl | 161 ++++++++++++++++++ contrib/bazel/script-options.sh | 8 + 6 files changed, 678 insertions(+) create mode 100644 BUILD.bazel create mode 100644 contrib/bazel/BUILD.bazel create mode 100644 contrib/bazel/LICENSE.registry create mode 100644 contrib/bazel/README.md create mode 100644 contrib/bazel/config.bzl create mode 100644 contrib/bazel/script-options.sh diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000000000..5a35753dac997d --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,289 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") +load("//contrib/bazel:config.bzl", "GIT_COPTS", "git_binary") + +package(default_visibility = ["//visibility:public"]) + +# Exclude executable entry points and sources selected separately below. +_CORE_SRCS = glob([ + "*.c", + "compiler-tricks/*.c", + "ewah/*.c", + "negotiator/*.c", + "odb/*.c", + "refs/*.c", + "reftable/*.c", + "trace2/*.c", + "xdiff/*.c", +], exclude = [ + "common-main.c", + "daemon.c", + "git.c", + "http-backend.c", + "http-fetch.c", + "http-push.c", + "http-walker.c", + "http.c", + "imap-send.c", + "remote-curl.c", + "scalar.c", + "sh-i18n--envsubst.c", + "sha1dc_git.c", + "shell.c", + "unix-socket.c", + "unix-stream-server.c", +]) + [ + "compat/nonblock.c", + "compat/obstack.c", + "compat/open.c", + "compat/terminal.c", +] + +_BUILTIN_SRCS = glob(["builtin/*.c"]) +_SHELL_SCRIPTS = [ + "git-difftool--helper.sh", + "git-filter-branch.sh", + "git-merge-octopus.sh", + "git-merge-one-file.sh", + "git-merge-resolve.sh", + "git-mergetool.sh", + "git-quiltimport.sh", + "git-request-pull.sh", + "git-submodule.sh", + "git-web--browse.sh", + "git-sh-i18n.sh", + "git-sh-setup.sh", + "git-mergetool--lib.sh", +] + +# Use upstream generators and derive the source root from declared inputs. +# This also works when this package is in an external repository. +[ + sh_binary(name = "generate_" + kind, srcs = ["tools/generate-" + kind + ".sh"]) + for kind in ["cmdlist", "configlist", "hooklist"] +] + +genrule( + name = "command_list", + srcs = ["command-list.txt", "Documentation/scalar.adoc"] + glob(["Documentation/git*.adoc"]), + outs = ["command-list.h"], + cmd = '$(location :generate_cmdlist) "$$(dirname "$(location command-list.txt)")" "$@"', + tools = [":generate_cmdlist"], +) + +genrule( + name = "config_list", + srcs = glob(["Documentation/*config.adoc", "Documentation/config/*.adoc"]), + outs = ["config-list.h"], + cmd = '$(location :generate_configlist) "$$(dirname "$$(dirname "$(location Documentation/git-config.adoc)")")" "$@"', + tools = [":generate_configlist"], +) + +genrule( + name = "hook_list", + srcs = ["Documentation/githooks.adoc"], + outs = ["hook-list.h"], + cmd = '$(location :generate_hooklist) "$$(dirname "$$(dirname "$(location Documentation/githooks.adoc)")")" "$@"', + tools = [":generate_hooklist"], +) + +# Supply every version field explicitly so an external build cannot discover +# the consuming repository's identity. GIT-VERSION-GEN remains the authority +# for the development version and template substitutions. +[ + genrule( + name = name, + srcs = ["GIT-VERSION-GEN", template], + outs = [out], + cmd = """ + export GIT_VERSION="$$(sed -n 's/^DEF_VER=v//p' $(location GIT-VERSION-GEN))" + export GIT_BUILT_FROM_COMMIT=unknown GIT_DATE=1970-01-01 + export GIT_USER_AGENT="git/$$GIT_VERSION" + $(location :generate_version) "$$(dirname $(location GIT-VERSION-GEN))" "$(location %s)" "$@" + """ % template, + tools = [":generate_version"], + ) + for name, template, out in [ + ("version_def", "version-def.h.in", "version-def.h"), + ("git_version_file", "GIT-VERSION-FILE.in", "GIT-VERSION-FILE"), + ("windows_resource_file", "git.rc.in", "git.rc"), + ] +] + +sh_binary(name = "generate_version", srcs = ["GIT-VERSION-GEN"]) +sh_binary(name = "generate_script", srcs = ["tools/generate-script.sh"]) + +[ + genrule( + name = script[:-3].replace("-", "_"), + srcs = [script, "//contrib/bazel:script-options.sh"], + outs = [script[:-3]], + cmd = "$(location :generate_script) $(location %s) $@ $(location //contrib/bazel:script-options.sh)" % script, + tools = [":generate_script"], + ) + for script in _SHELL_SCRIPTS +] + +cc_library( + name = "git_headers", + hdrs = glob([ + "*.h", + "compat/**/*.h", + "ewah/*.h", + "negotiator/*.h", + "odb/*.h", + "refs/*.h", + "reftable/*.h", + "sha1dc/*.h", + "sha256/**/*.h", + "trace2/*.h", + "xdiff/*.h", + ]) + [":command_list", ":config_list", ":hook_list", ":version_def"], + includes = ["."] + select({ + "@platforms//os:windows": ["compat", "compat/poll", "compat/regex", "compat/win32"], + "//conditions:default": [], + }), + deps = [ + "@pcre2", + "@zlib-ng//:zlib_ng_native", + ] + select({ + "@platforms//os:windows": ["@win_iconv//:win_iconv"], + "//conditions:default": ["@openssl//:ssl"], + }), +) + +cc_library( + name = "windows_regex", + srcs = ["compat/regex/regex.c"], + textual_hdrs = glob(["compat/regex/*.c"]), + copts = GIT_COPTS + ["-DGAWK", "-DNO_MBSUPPORT"], + deps = [":git_headers"], + target_compatible_with = ["@platforms//os:windows"], + tags = ["manual"], +) + +cc_library( + name = "libgit", + srcs = _CORE_SRCS + [ + "compat/fopen.c", + "compat/qsort_s.c", + "compat/strlcpy.c", + "compat/simple-ipc/ipc-shared.c", + "sha1dc_git.c", + "sha1dc/sha1.c", + "sha1dc/ubc_check.c", + "sha256/block/sha256.c", + "unix-socket.c", + "unix-stream-server.c", + ] + select({ + "@platforms//os:linux": [ + "compat/linux/procinfo.c", + "compat/simple-ipc/ipc-unix-socket.c", + "compat/fsmonitor/fsm-health-linux.c", + "compat/fsmonitor/fsm-ipc-unix.c", + "compat/fsmonitor/fsm-listen-linux.c", + "compat/fsmonitor/fsm-path-utils-linux.c", + "compat/fsmonitor/fsm-settings-unix.c", + ], + "@platforms//os:macos": [ + "compat/darwin/procinfo.c", + "compat/memmem.c", + "compat/precompose_utf8.c", + "compat/regcomp_enhanced.c", + "compat/simple-ipc/ipc-unix-socket.c", + "compat/fsmonitor/fsm-health-darwin.c", + "compat/fsmonitor/fsm-ipc-unix.c", + "compat/fsmonitor/fsm-listen-darwin.c", + "compat/fsmonitor/fsm-path-utils-darwin.c", + "compat/fsmonitor/fsm-settings-unix.c", + ], + "@platforms//os:windows": [ + "compat/basename.c", + "compat/memmem.c", + "compat/mingw.c", + "compat/poll/poll.c", + "compat/pread.c", + "compat/setenv.c", + "compat/strcasestr.c", + "compat/strtoimax.c", + "compat/strtoumax.c", + "compat/win32/dirent.c", + "compat/win32/flush.c", + "compat/win32/path-utils.c", + "compat/win32/pthread.c", + "compat/win32/syslog.c", + "compat/win32/trace2_win32_process_info.c", + "compat/win32mmap.c", + "compat/winansi.c", + "compat/writev.c", + "compat/simple-ipc/ipc-win32.c", + "compat/fsmonitor/fsm-health-win32.c", + "compat/fsmonitor/fsm-ipc-win32.c", + "compat/fsmonitor/fsm-listen-win32.c", + "compat/fsmonitor/fsm-path-utils-win32.c", + "compat/fsmonitor/fsm-settings-win32.c", + ], + }), + copts = GIT_COPTS, + deps = [":git_headers", "@curl"] + select({ + "@platforms//os:windows": [":windows_regex"], + "//conditions:default": [], + }), +) + +cc_library( + name = "builtins", + srcs = _BUILTIN_SRCS, + copts = GIT_COPTS, + deps = [":libgit"], +) + +cc_library( + name = "libgit_http", + srcs = ["http.c", "http-walker.c"], + copts = GIT_COPTS, + deps = [":libgit", "@curl"], +) + +genrule( + name = "windows_resource_object", + srcs = [":windows_resource_file", "compat/win32/git.manifest", "GIT-VERSION-GEN"], + outs = ["git-resource.o"], + cmd = """ + sed 's/RT_MANIFEST/24/' $(location :windows_resource_file) > "$(@D)/git-windres.rc" + $(location @llvm//tools:llvm-windres) --input="$(@D)/git-windres.rc" --output="$@" \ + --output-format=coff --include-dir="$$(dirname $(location GIT-VERSION-GEN))" \ + --no-preprocess """ + select({ + "@platforms//cpu:x86_64": " --target=pe-x86-64", + "@platforms//cpu:aarch64": " --target=aarch64-w64-mingw32", + }), + tools = ["@llvm//tools:llvm-windres"], + target_compatible_with = ["@platforms//os:windows"], + tags = ["manual"], +) + +cc_library( + name = "windows_resources", + srcs = [":windows_resource_object"], + alwayslink = True, + target_compatible_with = ["@platforms//os:windows"], + tags = ["manual"], +) + +git_binary(name = "git", srcs = ["git.c"], deps = [":builtins"]) +git_binary(name = "scalar", srcs = ["scalar.c"]) +git_binary(name = "git-shell", srcs = ["shell.c"]) +git_binary(name = "git-daemon", srcs = ["daemon.c"]) +git_binary(name = "git-http-backend", srcs = ["http-backend.c"]) +git_binary(name = "git-http-fetch", srcs = ["http-fetch.c"], deps = [":libgit_http"]) +git_binary(name = "git-http-push", srcs = ["http-push.c"], deps = [":libgit_http", "@libexpat"]) +git_binary(name = "git-imap-send", srcs = ["imap-send.c"], deps = [":libgit_http"]) +git_binary(name = "git-remote-http", srcs = ["remote-curl.c"], deps = [":libgit_http"]) +git_binary(name = "git-sh-i18n--envsubst", srcs = ["sh-i18n--envsubst.c"]) + +filegroup( + name = "templates", + srcs = glob(["templates/hooks/*.sample"]) + ["templates/description", "templates/info/exclude"], +) + +filegroup(name = "mergetools", srcs = glob(["mergetools/*"])) diff --git a/contrib/bazel/BUILD.bazel b/contrib/bazel/BUILD.bazel new file mode 100644 index 00000000000000..f024e5b6b3addb --- /dev/null +++ b/contrib/bazel/BUILD.bazel @@ -0,0 +1 @@ +exports_files(["script-options.sh"]) diff --git a/contrib/bazel/LICENSE.registry b/contrib/bazel/LICENSE.registry new file mode 100644 index 00000000000000..d645695673349e --- /dev/null +++ b/contrib/bazel/LICENSE.registry @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/contrib/bazel/README.md b/contrib/bazel/README.md new file mode 100644 index 00000000000000..55f3f5b771dd6a --- /dev/null +++ b/contrib/bazel/README.md @@ -0,0 +1,17 @@ +# Bazel + +These targets are consumed from a source archive using `http_archive`. +Pin the source revision and apply local patches in the consuming workspace. +Build `@git//:git` and the required helper targets; `templates` and `mergetools` +provide runtime data. Installation and helper aliases belong to the consumer. + +The consumer supplies `rules_cc`, `rules_shell`, `platforms`, `curl`, `libexpat`, +`openssl`, `pcre2`, and `zlib-ng` (the `zlib_ng_native` target). Windows also +requires `win_iconv` and `llvm` for its resource compiler, plus Git Bash. +Use Clang/LLD on Linux and Windows (GNU ABI), and the Apple toolchain on macOS. +The compiled exec path is `libexec/git-core`; version generation uses Git's +`DEF_VER` and reports an unknown commit. + +Platform configuration is adapted in part from the Bazel Central Registry's +Git 2.55.0 overlay at eba513313039158442b2a7dc3f3d1b2880b86675. +`LICENSE.registry` retains its Apache 2.0 license. diff --git a/contrib/bazel/config.bzl b/contrib/bazel/config.bzl new file mode 100644 index 00000000000000..25185961cef1fe --- /dev/null +++ b/contrib/bazel/config.bzl @@ -0,0 +1,161 @@ +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") + +# Platform configuration follows config.mak.uname and the Makefile. +# Adapted in part from the registry Git overlay; see LICENSE.registry. + +_GIT_BASE_COPTS = [ + "-Wall", + "-DUSE_CURL_FOR_IMAP_SEND", + "-DSUPPORTS_SIMPLE_IPC", + "-DSHA1_DC", + "-DSHA1DC_NO_STANDARD_INCLUDES", + "-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0", + '-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\\"git-compat-util.h\\"', + '-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\\"git-compat-util.h\\"', + "-DSHA256_BLK", + '-DSHELL_PATH=\\"/bin/sh\\"', + '-DGIT_HTML_PATH=\\"share/doc/git-doc\\"', + '-DGIT_MAN_PATH=\\"share/man\\"', + '-DGIT_INFO_PATH=\\"share/info\\"', + '-DGIT_LOCALE_PATH=\\"share/locale\\"', + '-DBINDIR=\\"bin\\"', + '-DFALLBACK_RUNTIME_PREFIX=\\"\\"', + '-DDEFAULT_GIT_TEMPLATE_DIR=\\"share/git-core/templates\\"', + '-DPAGER_ENV=\\"LESS=FRX\\\\040LV=-c\\"', + "-DNO_GETTEXT", + "-DHAVE_ZLIB_NG", + "-DUSE_LIBPCRE2", +] + +_GIT_CPU_DEFINES = select({ + "@platforms//cpu:aarch64": ['-DGIT_HOST_CPU=\\"aarch64\\"'], + "@platforms//cpu:x86_64": ['-DGIT_HOST_CPU=\\"x86_64\\"'], + "//conditions:default": ['-DGIT_HOST_CPU=\\"unknown\\"'], +}) + +_GIT_MACOS_ICONV_COPTS = [ + # v2.53.0: Work around broken system iconv on newer macOS versions. + "-DICONV_RESTART_RESET", +] + +_GIT_MACOS_ICONV_LINKOPTS = [ + "-liconv", +] + +_GIT_OS_DEFINES = select({ + "@platforms//os:linux": [ + "-DHAVE_ALLOCA_H", + "-DHAVE_PATHS_H", + "-DHAVE_DEV_TTY", + "-DHAVE_CLOCK_GETTIME", + "-DHAVE_CLOCK_MONOTONIC", + "-DHAVE_SYNC_FILE_RANGE", + "-DHAVE_SYSINFO", + "-DHAVE_LINUX_MAGIC_H", + "-DHAVE_PLATFORM_PROCINFO", + "-DHAVE_GETDELIM", + "-DHAVE_GETRANDOM", + "-DFREAD_READS_DIRECTORIES", + "-DNO_STRLCPY", + "-DRUNTIME_PREFIX", + '-DPROCFS_EXECUTABLE_PATH=\\"/proc/self/exe\\"', + "-DHAVE_FSMONITOR_DAEMON_BACKEND", + "-DHAVE_FSMONITOR_OS_SETTINGS", + ], + "@platforms//os:macos": [ + "-DHAVE_PATHS_H", + "-DHAVE_DEV_TTY", + "-DHAVE_PLATFORM_PROCINFO", + "-DHAVE_GETDELIM", + "-DFREAD_READS_DIRECTORIES", + "-DNO_MEMMEM", + "-DUSE_ST_TIMESPEC", + "-DPRECOMPOSE_UNICODE", + "-DPROTECT_HFS_DEFAULT=1", + "-DHAVE_BSD_SYSCTL", + "-DHAVE_NS_GET_EXECUTABLE_PATH", + "-DRUNTIME_PREFIX", + "-DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS", + "-DHAVE_ARC4RANDOM", + # fsmonitor + "-DHAVE_FSMONITOR_DAEMON_BACKEND", + "-DHAVE_FSMONITOR_OS_SETTINGS", + ] + _GIT_MACOS_ICONV_COPTS, + "@platforms//os:windows": [ + # fsmonitor + "-DHAVE_FSMONITOR_DAEMON_BACKEND", + "-DHAVE_FSMONITOR_OS_SETTINGS", + "-DNO_OPENSSL", + "-DPCRE2_STATIC", + "-DHAVE_ALLOCA_H", + "-DHAVE_WPGMPTR", + "-DRUNTIME_PREFIX", + "-DNO_PREAD", + "-DNO_WRITEV", + "-DNO_LIBGEN_H", + "-DNO_POLL", + "-DNO_POLL_H", + "-DNO_SYS_POLL_H", + "-DNO_SYMLINK_HEAD", + "-DNO_SETENV", + "-DNO_STRCASESTR", + "-DNO_STRLCPY", + "-DNO_MEMMEM", + "-DNO_STRTOUMAX", + "-DNO_MKDTEMP", + "-DNO_ST_BLOCKS_IN_STRUCT_STAT", + "-DUSE_WIN32_IPC", + "-DUSE_WIN32_MMAP", + "-DMMAP_PREVENTS_DELETE", + "-DUNRELIABLE_FSTAT", + "-DOBJECT_CREATION_MODE=1", + "-DNO_POSIX_GOODIES", + "-DHAVE_PLATFORM_PROCINFO", + "-DHAVE_RTLGENRANDOM", + "-DNOGDI", + "-DWIN32", + "-DNATIVE_CRLF", + "-DDETECT_MSYS_TTY", + "-D__USE_MINGW_ANSI_STDIO=0", + '-DSTRIP_EXTENSION=\\".exe\\"', + ], + "//conditions:default": [], +}) + +_GIT_RUNTIME_PATH_DEFINES = select({ + "@platforms//os:windows": [ + '-DGIT_EXEC_PATH=\\"libexec/git-core\\"', + '-DETC_GITCONFIG=\\"etc/gitconfig\\"', + '-DETC_GITATTRIBUTES=\\"etc/gitattributes\\"', + ], + "//conditions:default": [ + '-DGIT_EXEC_PATH=\\"libexec/git-core\\"', + '-DETC_GITCONFIG=\\"/etc/gitconfig\\"', + '-DETC_GITATTRIBUTES=\\"/etc/gitattributes\\"', + ], +}) + +GIT_COPTS = _GIT_BASE_COPTS + _GIT_CPU_DEFINES + _GIT_OS_DEFINES + _GIT_RUNTIME_PATH_DEFINES + +GIT_LINKOPTS = select({ + "@platforms//os:linux": ["-lpthread", "-ldl", "-lm", "-lrt", "-lutil"], + "@platforms//os:macos": [ + "-lpthread", + "-framework", + "CoreServices", + ] + _GIT_MACOS_ICONV_LINKOPTS, + "@platforms//os:windows": ["-municode", "-lws2_32", "-lntdll"], + "//conditions:default": [], +}) + +def git_binary(name, srcs, deps = []): + cc_binary( + name = name, + srcs = ["common-main.c"] + srcs, + copts = GIT_COPTS, + linkopts = GIT_LINKOPTS, + deps = [":libgit"] + deps + select({ + "@platforms//os:windows": [":windows_resources"], + "//conditions:default": [], + }), + ) diff --git a/contrib/bazel/script-options.sh b/contrib/bazel/script-options.sh new file mode 100644 index 00000000000000..87eabbed63fe02 --- /dev/null +++ b/contrib/bazel/script-options.sh @@ -0,0 +1,8 @@ +SHELL_PATH=/bin/sh +DIFF=diff +LOCALEDIR=share/locale +USE_GETTEXT_SCHEME=fallthrough +GITWEBDIR=share/gitweb +PERL_PATH=/usr/bin/perl +PAGER_ENV='LESS=FRX LV=-c' +BROKEN_PATH_FIX=