mirror of
https://github.com/neovim/neovim.git
synced 2026-09-03 21:00:34 +00:00
build(deps): vendor lpeg
Problem: LPeg is hosted on a single unreliable external hoster, forcing is to mirror it in neovim/deps, which adds maintenance friction. Also, we have already vendored the Lua `re.lua` module. Solution: Vendor all of LPeg v1.1.0; as development is not very active anymore, this should not add much overhead (and allow us to simplify in particular the Zig build scripts). Note: LPeg defines a `luaL_newlib` macro for Lua 5.1, which conflicts with LuaJIT's extension. This requires inlining the macro defined in `lptypes.h` and used in `lptree.c`; see README.md for the patch.
This commit is contained in:
committed by
Christian Clason
parent
752f4b944b
commit
6c96ec8c45
@@ -8,7 +8,6 @@ pub fn build_nlua0(
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
use_luajit: bool,
|
||||
ziglua: *std.Build.Dependency,
|
||||
lpeg: ?*std.Build.Dependency,
|
||||
libluv: ?*std.Build.Step.Compile,
|
||||
system_integration_options: build.SystemIntegrationOptions,
|
||||
) !*std.Build.Step.Compile {
|
||||
@@ -60,7 +59,7 @@ pub fn build_nlua0(
|
||||
|
||||
mod.addIncludePath(b.path("src"));
|
||||
mod.addIncludePath(b.path("src/includes_fixmelater"));
|
||||
try add_lua_modules(b, target.result, mod, lpeg, use_luajit, true, system_integration_options);
|
||||
try add_lua_modules(mod, use_luajit, true);
|
||||
}
|
||||
|
||||
// for debugging the nlua0 environment
|
||||
@@ -83,13 +82,9 @@ pub fn build_nlua0(
|
||||
}
|
||||
|
||||
pub fn add_lua_modules(
|
||||
b: *std.Build,
|
||||
target: std.Target,
|
||||
mod: *std.Build.Module,
|
||||
lpeg_dep: ?*std.Build.Dependency,
|
||||
use_luajit: bool,
|
||||
is_nlua0: bool,
|
||||
system_integration_options: build.SystemIntegrationOptions,
|
||||
) !void {
|
||||
const flags = [_][]const u8{
|
||||
// Standard version used in Lua Makefile
|
||||
@@ -97,9 +92,6 @@ pub fn add_lua_modules(
|
||||
if (is_nlua0) "-DNVIM_NLUA0" else "",
|
||||
};
|
||||
|
||||
if (lpeg_dep) |lpeg| {
|
||||
mod.addIncludePath(lpeg.path(""));
|
||||
}
|
||||
mod.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
"src/mpack/lmpack.c",
|
||||
@@ -110,25 +102,17 @@ pub fn add_lua_modules(
|
||||
},
|
||||
.flags = &flags,
|
||||
});
|
||||
if (system_integration_options.lpeg) {
|
||||
if (try findLpeg(b, target)) |lpeg_lib| {
|
||||
mod.addLibraryPath(.{ .cwd_relative = std.fs.path.dirname(lpeg_lib).? });
|
||||
mod.addObjectFile(.{ .cwd_relative = lpeg_lib });
|
||||
}
|
||||
} else if (lpeg_dep) |lpeg| {
|
||||
mod.addCSourceFiles(.{
|
||||
.root = .{ .dependency = .{ .dependency = lpeg, .sub_path = "" } },
|
||||
.files = &.{
|
||||
"lpcap.c",
|
||||
"lpcode.c",
|
||||
"lpcset.c",
|
||||
"lpprint.c",
|
||||
"lptree.c",
|
||||
"lpvm.c",
|
||||
},
|
||||
.flags = &flags,
|
||||
});
|
||||
}
|
||||
mod.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
"src/lpeg/lpcap.c",
|
||||
"src/lpeg/lpcode.c",
|
||||
"src/lpeg/lpcset.c",
|
||||
"src/lpeg/lpprint.c",
|
||||
"src/lpeg/lptree.c",
|
||||
"src/lpeg/lpvm.c",
|
||||
},
|
||||
.flags = &flags,
|
||||
});
|
||||
|
||||
if (!use_luajit) {
|
||||
mod.addCSourceFiles(.{
|
||||
@@ -184,36 +168,3 @@ pub fn build_libluv(
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
||||
fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 {
|
||||
const filenames = [_][]const u8{
|
||||
"lpeg_a",
|
||||
"lpeg",
|
||||
"liblpeg_a",
|
||||
"lpeg.so",
|
||||
b.fmt("lpeg{s}", .{target.dynamicLibSuffix()}),
|
||||
};
|
||||
var code: u8 = 0;
|
||||
const dirs_stdout = std.mem.trimEnd(u8, try b.runAllowFail(&[_][]const u8{
|
||||
"pkg-config",
|
||||
"--variable=pc_system_libdirs",
|
||||
"--keep-system-cflags",
|
||||
"pkg-config",
|
||||
}, &code, .ignore), "\r\n");
|
||||
var paths: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 0);
|
||||
var path_it = std.mem.tokenizeAny(u8, dirs_stdout, " ,");
|
||||
while (path_it.next()) |dir| {
|
||||
try paths.append(b.allocator, dir);
|
||||
try paths.append(b.allocator, b.fmt("{s}/lua/5.1", .{dir}));
|
||||
}
|
||||
const io = b.graph.io;
|
||||
for (paths.items) |path| {
|
||||
var dir = std.Io.Dir.openDirAbsolute(io, path, .{}) catch continue;
|
||||
defer dir.close(io);
|
||||
for (filenames) |filename| {
|
||||
dir.access(io, filename, .{}) catch continue;
|
||||
return b.fmt("{s}/{s}", .{ path, filename });
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user