Repository navigation
Expand file tree
/
Copy pathbuild.lua
More file actions
68 lines (57 loc) · 3.45 KB
/
Copy pathbuild.lua
File metadata and controls
68 lines (57 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- build.lua — libgit2 for lde.
--
-- Every non-Windows target links the static mbedTLS built by the optional
-- mbedtls-sys dependency. curl-sys links the same archives, so the final lde
-- image carries one mbedTLS copy. Windows keeps libgit2's WinHTTP backend.
local build = require("lde-build")
local isWindows = jit.os == "Windows"
local isMac = jit.os == "OSX"
local libName = isWindows and "git2.dll" or (isMac and "libgit2.dylib" or "libgit2.so")
local commit = "1888a166e43420b2a5f93f104f2a99ec049b073c"
local url = "https://github.com/libgit2/libgit2/archive/" .. commit .. ".tar.gz"
local tarball = "libgit2-" .. commit .. ".tar.gz"
local content = build:fetch(url)
build:write(tarball, content)
build:extract(tarball, ".")
build:move("libgit2-" .. commit, "libgit2")
local srcDir = build.outDir .. "/libgit2"
local buildDir = srcDir .. "/build"
---@format disable-next
local gitMin = "-DBUILD_TESTS=OFF -DBUILD_CLI=OFF -DUSE_SSH=OFF -DUSE_GSSAPI=OFF -DUSE_NTLMCLIENT=OFF -DREGEX_BACKEND=builtin -DUSE_HTTP_PARSER=builtin -DUSE_BUNDLED_ZLIB=ON -DCMAKE_C_FLAGS=-g0"
if isWindows then
build:sh('cmake -S "' .. srcDir .. '" -B "' .. buildDir .. '" -GNinja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DUSE_HTTPS=WinHTTP ' .. gitMin)
build:sh('cmake --build "' .. buildDir .. '" --config Release')
-- The pinned libgit2 names its shared library libgit2.dll. Multi-config
-- generators (Ninja Multi-Config, Visual Studio) emit it under
-- build/Release/; single-config ones (MinGW Makefiles) under build/.
local dll = build:exists("libgit2/build/Release/libgit2.dll")
and "libgit2/build/Release/libgit2.dll"
or "libgit2/build/libgit2.dll"
build:copy(dll, libName)
else
-- Built once by mbedtls-sys, the same archives curl-sys links.
local dep = build:dependency("mbedtls-sys")
local lib = dep .. "/lib/"
local mbedArgs = ' -DMBEDTLS_INCLUDE_DIR="' .. dep .. '/include"'
.. ' -DMBEDTLS_LIBRARY="' .. lib .. 'libmbedtls.a" -DMBEDX509_LIBRARY="' .. lib .. 'libmbedx509.a"'
.. ' -DMBEDCRYPTO_LIBRARY="' .. lib .. 'libmbedcrypto.a"'
-- Without CERT_LOCATION, libgit2's mbedTLS backend asks the `openssl` executable for a
-- default store and fails the configure when there is none (Termux, Alpine). The real
-- store is chosen at runtime (GIT_OPT_SET_SSL_CERT_LOCATIONS in src/init.lua), and baking a
-- build machine's path is wrong anyway, so point it at an empty placeholder: libgit2 skips a
-- default that does not parse or no longer exists.
build:write("no-default-ca.pem", "")
mbedArgs = mbedArgs .. ' -DCERT_LOCATION="' .. build.outDir .. '/no-default-ca.pem"'
build:sh('cmake -S "' .. srcDir .. '" -B "' .. buildDir .. '" -GNinja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DUSE_HTTPS=mbedtls' .. mbedArgs .. ' ' .. gitMin)
build:sh('cmake --build "' .. buildDir .. '" --config Release -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)')
if isMac then
build:copy("libgit2/build/libgit2.dylib", libName)
build:sh('strip -x -o "' .. build.outDir .. '/' .. libName .. '.stripped" "' .. build.outDir .. '/' .. libName .. '"')
build:move(libName .. '.stripped', libName)
else
build:copy("libgit2/build/libgit2.so", libName)
local stripEhFrame = (build.target or ""):find("musl", 1, true) and "" or " --remove-section=.eh_frame --remove-section=.eh_frame_hdr"
build:sh('strip --strip-unneeded' .. stripEhFrame .. ' -o "' .. build.outDir .. '/' .. libName .. '.stripped" "' .. build.outDir .. '/' .. libName .. '"')
build:move(libName .. '.stripped', libName)
end
end