mirror of
https://github.com/neovim/neovim.git
synced 2026-09-03 12:50:36 +00:00
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.
171 lines
4.9 KiB
Zig
171 lines
4.9 KiB
Zig
const std = @import("std");
|
|
const build = @import("../build.zig");
|
|
const LazyPath = std.Build.LazyPath;
|
|
|
|
pub fn build_nlua0(
|
|
b: *std.Build,
|
|
target: std.Build.ResolvedTarget,
|
|
optimize: std.builtin.OptimizeMode,
|
|
use_luajit: bool,
|
|
ziglua: *std.Build.Dependency,
|
|
libluv: ?*std.Build.Step.Compile,
|
|
system_integration_options: build.SystemIntegrationOptions,
|
|
) !*std.Build.Step.Compile {
|
|
const options = b.addOptions();
|
|
options.addOption(bool, "use_luajit", use_luajit);
|
|
|
|
const nlua0_exe = b.addExecutable(.{
|
|
.name = "nlua0",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/nlua0.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
.use_llvm = true,
|
|
});
|
|
const nlua0_mod = nlua0_exe.root_module;
|
|
|
|
const exe_unit_tests = b.addTest(.{
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/nlua0.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
|
|
const embedded_data = b.addModule("embedded_data", .{
|
|
.root_source_file = b.path("runtime/embedded_data.zig"),
|
|
});
|
|
|
|
for ([2]*std.Build.Module{ nlua0_mod, exe_unit_tests.root_module }) |mod| {
|
|
mod.addImport("ziglua", ziglua.module("zlua"));
|
|
mod.addImport("embedded_data", embedded_data);
|
|
// addImport already links by itself. but we need headers as well..
|
|
if (system_integration_options.lua) {
|
|
const system_lua_lib = if (use_luajit) "luajit" else "lua5.1";
|
|
mod.linkSystemLibrary(system_lua_lib, .{});
|
|
} else {
|
|
mod.linkLibrary(ziglua.artifact("lua"));
|
|
}
|
|
if (libluv) |luv| {
|
|
mod.linkLibrary(luv);
|
|
} else {
|
|
mod.linkSystemLibrary("luv", .{});
|
|
}
|
|
|
|
mod.addOptions("options", options);
|
|
|
|
mod.addIncludePath(b.path("src"));
|
|
mod.addIncludePath(b.path("src/includes_fixmelater"));
|
|
try add_lua_modules(mod, use_luajit, true);
|
|
}
|
|
|
|
// for debugging the nlua0 environment
|
|
// like this: `zig build nlua0 -- script.lua {args}`
|
|
const run_cmd = b.addRunArtifact(nlua0_exe);
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
const run_step = b.step("nlua0", "Run nlua0 build tool");
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
b.installArtifact(nlua0_exe); // DEBUG
|
|
|
|
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
|
|
|
const test_step = b.step("test_nlua0", "Run unit tests for nlua0");
|
|
test_step.dependOn(&run_exe_unit_tests.step);
|
|
|
|
return nlua0_exe;
|
|
}
|
|
|
|
pub fn add_lua_modules(
|
|
mod: *std.Build.Module,
|
|
use_luajit: bool,
|
|
is_nlua0: bool,
|
|
) !void {
|
|
const flags = [_][]const u8{
|
|
// Standard version used in Lua Makefile
|
|
"-std=gnu99",
|
|
if (is_nlua0) "-DNVIM_NLUA0" else "",
|
|
};
|
|
|
|
mod.addCSourceFiles(.{
|
|
.files = &.{
|
|
"src/mpack/lmpack.c",
|
|
"src/mpack/mpack_core.c",
|
|
"src/mpack/object.c",
|
|
"src/mpack/conv.c",
|
|
"src/mpack/rpc.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(.{
|
|
.files = &.{
|
|
"src/bit.c",
|
|
},
|
|
.flags = &flags,
|
|
});
|
|
}
|
|
}
|
|
|
|
pub fn build_libluv(
|
|
b: *std.Build,
|
|
target: std.Build.ResolvedTarget,
|
|
optimize: std.builtin.OptimizeMode,
|
|
lua: ?*std.Build.Step.Compile,
|
|
libuv: *std.Build.Step.Compile,
|
|
use_luajit: bool,
|
|
) !*std.Build.Step.Compile {
|
|
const upstream = b.lazyDependency("luv", .{});
|
|
const compat53 = b.lazyDependency("lua_compat53", .{});
|
|
var root_module = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
const lib = b.addLibrary(.{
|
|
.name = "luv",
|
|
.linkage = .static,
|
|
.root_module = root_module,
|
|
});
|
|
|
|
if (lua) |lua_lib| {
|
|
root_module.linkLibrary(lua_lib);
|
|
} else {
|
|
const system_lua_lib = if (use_luajit) "luajit" else "lua5.1";
|
|
root_module.linkSystemLibrary(system_lua_lib, .{});
|
|
}
|
|
root_module.linkLibrary(libuv);
|
|
|
|
if (upstream) |dep| {
|
|
root_module.addIncludePath(dep.path("src"));
|
|
lib.installHeader(dep.path("src/luv.h"), "luv/luv.h");
|
|
root_module.addCSourceFiles(.{ .root = dep.path("src/"), .files = &.{
|
|
"luv.c",
|
|
} });
|
|
}
|
|
if (compat53) |dep| {
|
|
root_module.addIncludePath(dep.path("c-api"));
|
|
root_module.addCSourceFiles(.{ .root = dep.path("c-api"), .files = &.{
|
|
"compat-5.3.c",
|
|
} });
|
|
}
|
|
|
|
return lib;
|
|
}
|