Skip to content

Commit bbcf893

Browse files
committed
refactor!: replace libgit2 submodule with lde-build usage
This simplifies the build script with the introduction of lde-build and allows for cloning the repo without any need for recursing submodules.
1 parent 01dfa23 commit bbcf893

4 files changed

Lines changed: 22 additions & 30 deletions

File tree

‎.gitmodules‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎build.lua‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
1-
local outDir = os.getenv("LDE_OUTPUT_DIR")
2-
local sep = string.sub(package.config, 1, 1)
1+
local build = require("lde-build")
2+
33
local isWindows = jit.os == "Windows"
44
local isMac = jit.os == "OSX"
5-
local isAndroid = os.getenv("ANDROID_ROOT") ~= nil
6-
local scriptDir = debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])")
7-
local src = scriptDir .. "vendor" .. sep .. "libgit2"
85
local libName = isWindows and "git2.dll" or (isMac and "libgit2.dylib" or "libgit2.so")
9-
local outLib = outDir .. sep .. libName
106

11-
if io.open(outLib, "rb") then return end
7+
local url = "https://github.com/libgit2/libgit2/archive/refs/tags/v1.8.5.tar.gz"
8+
local tarball = "libgit2-1.8.5.tar.gz"
129

13-
local function exec(cmd)
14-
local ret = os.execute(cmd)
15-
assert(ret == 0 or ret == true, "command failed: " .. cmd)
16-
end
10+
local content = build:fetch(url)
11+
build:write(tarball, content)
12+
build:extract(tarball, ".")
13+
build:move("libgit2-1.8.5", "libgit2")
1714

18-
local build = src .. sep .. "build"
15+
local srcDir = build.outDir .. "/libgit2"
16+
local buildDir = srcDir .. "/build"
1917

2018
---@format disable-next
2119
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"
2220

23-
local https, cmakeExtra
21+
local https
2422
if isWindows then
2523
https = "WinHTTP"
26-
cmakeExtra = ""
2724
elseif isMac then
2825
https = "SecureTransport"
29-
cmakeExtra = ""
3026
else
3127
https = "OpenSSL"
32-
cmakeExtra = ""
3328
end
3429

35-
exec('cmake -S "' .. src .. '" -B "' .. build .. '" -DBUILD_SHARED_LIBS=ON -DUSE_HTTPS=' .. https .. ' ' .. gitMin .. (cmakeExtra ~= "" and (' ' .. cmakeExtra) or ""))
36-
exec('cmake --build "' .. build .. '" --config Release' .. (isWindows and "" or " -j$(nproc)"))
30+
build:sh('cmake -S "' ..
31+
srcDir .. '" -B "' .. buildDir .. '" -DBUILD_SHARED_LIBS=ON -DUSE_HTTPS=' .. https .. ' ' .. gitMin)
32+
build:sh('cmake --build "' .. buildDir .. '" --config Release' .. (isWindows and "" or " -j$(nproc)"))
3733

3834
if isWindows then
39-
exec('copy "' .. build .. '\\Release\\git2.dll" "' .. outLib .. '"')
35+
build:copy("libgit2/build/Release/git2.dll", libName)
4036
elseif isMac then
41-
exec('cp "' .. build .. '/libgit2.dylib" "' .. outLib .. '"')
42-
exec('strip -x "' .. outLib .. '"')
37+
build:copy("libgit2/build/libgit2.dylib", libName)
38+
build:sh('strip -x "' .. build.outDir .. '/' .. libName .. '"')
4339
else
44-
exec('cp "' .. build .. '/libgit2.so" "' .. outLib .. '"')
45-
exec('strip --strip-unneeded --remove-section=.eh_frame --remove-section=.eh_frame_hdr "' .. outLib .. '"')
40+
build:copy("libgit2/build/libgit2.so", libName)
41+
build:sh('strip --strip-unneeded --remove-section=.eh_frame --remove-section=.eh_frame_hdr "' ..
42+
build.outDir .. '/' .. libName .. '"')
4643
end

‎lde.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"name": "git2-sys",
33
"version": "0.1.0",
44
"devDependencies": {
5-
"lde-test": {
6-
"git": "https://github.com/lde-org/lde"
7-
}
5+
"lde-test": { "git": "https://github.com/lde-org/lde" },
6+
"lde-build": { "git": "https://github.com/lde-org/lde" }
87
}
98
}

‎vendor/libgit2‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)