Repositories / ocaml-git.git
ocaml-git.git
Clone (read-only): git clone http://git.guha-anderson.com/git/ocaml-git.git
@@ -1,6 +1,8 @@ .gradle/ .build/ build/ +vendor/libgit2-build/ +vendor/libgit2-install/ *.kexe *.klib .kotlin/
@@ -0,0 +1,3 @@ +[submodule "vendor/libgit2"] + path = vendor/libgit2 + url = https://github.com/libgit2/libgit2.git
@@ -1,6 +1,5 @@ (lang dune 3.22) (name ocaml-git) -(generate_opam_files true) (package (name ocaml-git) @@ -8,4 +7,5 @@ (depends (ocaml (>= 5.4)) dune + (conf-cmake :build) alcotest))
@@ -1,13 +1,15 @@ -# This file is generated by dune, edit dune-project instead opam-version: "2.0" synopsis: "Small OCaml Git library" depends: [ "ocaml" {>= "5.4"} "dune" {>= "3.22"} + "conf-cmake" {build} "alcotest" "odoc" {with-doc} ] build: [ + ["sh" "-exc" "if test -f .gitmodules; then git submodule update --init --recursive; fi"] + ["sh" "-exc" "LIBGIT2_BUILD_JOBS=%{jobs}% ./scripts/build-vendored-libgit2.sh"] ["dune" "subst"] {dev} [ "dune"
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +LIBGIT2_SRC="${ROOT}/vendor/libgit2" +BUILD_DIR="${ROOT}/vendor/libgit2-build" +INSTALL_DIR="${ROOT}/vendor/libgit2-install" + +if [[ ! -f "${LIBGIT2_SRC}/CMakeLists.txt" ]]; then + echo "Missing ${LIBGIT2_SRC}. Initialize submodules: git submodule update --init --recursive" >&2 + exit 1 +fi + +JOBS="${LIBGIT2_BUILD_JOBS:-}" +if [[ -z "${JOBS}" && -n "${OPAMJOBS:-}" ]]; then + JOBS="${OPAMJOBS}" +fi +if [[ -z "${JOBS}" ]]; then + JOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)" +fi + +MARKER="${BUILD_DIR}/.ocaml_git_root" +if [[ -f "${BUILD_DIR}/CMakeCache.txt" ]]; then + if [[ ! -f "${MARKER}" ]] || [[ "$(<"${MARKER}")" != "${ROOT}" ]]; then + rm -rf "${BUILD_DIR}" + fi +fi + +cmake -S "${LIBGIT2_SRC}" -B "${BUILD_DIR}" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTS=OFF \ + -DBUILD_CLI=OFF \ + -DBUILD_EXAMPLES=OFF \ + -DUSE_HTTPS=OFF \ + -DUSE_SSH=OFF \ + -DUSE_GSSAPI=OFF \ + -DUSE_NTLMCLIENT=OFF \ + -DUSE_BUNDLED_ZLIB=ON \ + -DUSE_HTTP_PARSER=builtin \ + -DREGEX_BACKEND=builtin \ + -DUSE_ICONV=OFF \ + -DUSE_SHA1=CollisionDetection \ + -DUSE_SHA256=Builtin + +cmake --build "${BUILD_DIR}" --parallel "${JOBS}" +rm -rf "${INSTALL_DIR}" +cmake --install "${BUILD_DIR}" +printf '%s\n' "${ROOT}" > "${MARKER}"
@@ -1,34 +1,32 @@ #!/usr/bin/env sh set -eu -if ! command -v pkg-config >/dev/null 2>&1; then - echo "pkg-config is required to generate libgit2 static link flags" >&2 - exit 1 +if test "$#" -gt 0; then + root="$1" +else + root="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)" fi -flags="$(pkg-config --libs --static libgit2)" - -printf '(' -for flag in $flags; do - case "$flag" in - -lgit2) flag="-l:libgit2.a" ;; - -lhttp_parser) flag="-l:libhttp_parser.a" ;; - -lssh2) flag="-l:libssh2.a" ;; - -lssl) flag="-l:libssl.a" ;; - -lcrypto) flag="-l:libcrypto.a" ;; - -lpcre2-8) flag="-l:libpcre2-8.a" ;; - -lz) flag="-l:libz.a" ;; +if ! test -d "$root/vendor/libgit2-install/lib"; then + case "$(pwd)" in + */_build/*) + workspace_root="${PWD%%/_build/*}" + if test -d "$workspace_root/vendor/libgit2-install/lib"; then + root="$workspace_root" + fi + ;; esac - printf ' "%s"' "$flag" -done +fi -# Debian/Ubuntu's libgit2.pc omits GSSAPI from Libs.private even though the -# static archive references it when HTTP negotiate auth support is enabled. -# Static Kerberos/GSSAPI archives are not installed by default, and this system -# also lacks the unversioned linker symlink, so pass the versioned .so path. -if test -r /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2; then - printf ' "/usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2"' -else - printf ' "-lgssapi_krb5"' +printf '(' +printf ' "-L%s/vendor/libgit2-install/lib"' "$root" +if test -n "${OPAM_SWITCH_PREFIX:-}"; then + printf ' "-L%s/lib/ocaml-git"' "$OPAM_SWITCH_PREFIX" +elif command -v opam >/dev/null 2>&1; then + libdir="$(opam var lib 2>/dev/null || true)" + if test -n "$libdir"; then + printf ' "-L%s/ocaml-git"' "$libdir" + fi fi +printf ' "-Wl,--start-group" "-l:libgit2.a" "-Wl,--end-group" "-lrt" "-pthread"' printf ' )\n'
@@ -12,7 +12,14 @@ (no_dynlink) (foreign_stubs (language c) - (names ocaml_git_stubs)) + (names ocaml_git_stubs) + (include_dirs %{project_root}/vendor/libgit2-install/include)) (c_library_flags (:include libgit2_static_link_flags.sexp)) (libraries unix)) + +(install + (package ocaml-git) + (section lib) + (files + (../vendor/libgit2-install/lib/libgit2.a as libgit2.a)))
@@ -0,0 +1 @@ +Subproject commit a418d9d4ab87bae16b87d8f37143a4687ae0e4b2