Merge pull request #39076 from bfredl/zig0.16

IT IS HAPPENING: Zig 0.16
This commit is contained in:
bfredl
2026-04-21 20:09:57 +02:00
committed by GitHub
16 changed files with 160 additions and 166 deletions

View File

@@ -255,7 +255,7 @@ jobs:
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
with:
version: 0.15.2
version: 0.16.0
- run: sudo apt-get install -y inotify-tools
- run: zig build $OPTS test_nlua0
@@ -278,7 +278,7 @@ jobs:
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
with:
version: 0.15.2
version: 0.16.0
- run: zig build test_nlua0 -Dluajit=false
- run: zig build nvim_bin -Dluajit=false && ./zig-out/bin/nvim --version
@@ -295,7 +295,7 @@ jobs:
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
with:
version: 0.15.2
version: 0.16.0
- run: zig build test_nlua0
- run: zig build nvim_bin

1
.gitignore vendored
View File

@@ -15,6 +15,7 @@ compile_commands.json
# Build/deps dir
/.zig-cache/
/zig-out/
/zig-pkg/
/.deps/
/tmp/
/.clangd/

197
build.zig
View File

@@ -42,6 +42,7 @@ pub fn lazyArtifact(d: *std.Build.Dependency, name: []const u8) ?*std.Build.Step
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const io = b.graph.io;
const t = target.result;
const os_tag = t.os.tag;
@@ -66,7 +67,7 @@ pub fn build(b: *std.Build) !void {
const host_use_luajit = if (cross_compiling) false else use_luajit;
const E = enum { luajit, lua51 };
const system_integration_options = SystemIntegrationOptions{
const sys_opts = SystemIntegrationOptions{
.lpeg = b.systemIntegrationOption("lpeg", .{}),
.lua = b.systemIntegrationOption("lua", .{}),
.tree_sitter = b.systemIntegrationOption("tree-sitter", .{}),
@@ -80,20 +81,20 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize_lua,
.lang = if (use_luajit) E.luajit else E.lua51,
.shared = false,
.system_lua = system_integration_options.lua,
.system_lua = sys_opts.lua,
});
const ziglua_host = if (cross_compiling) b.dependency("zlua", .{
.target = target_host,
.optimize = .ReleaseSmall,
.lang = if (host_use_luajit) E.luajit else E.lua51,
.system_lua = system_integration_options.lua,
.system_lua = sys_opts.lua,
.shared = false,
}) else ziglua;
var lua: ?*Compile = null;
var libuv: ?*Compile = null;
var libluv: ?*Compile = null;
var libluv_host: ?*Compile = null;
if (!system_integration_options.lua) {
if (!sys_opts.lua) {
// this is currently not necessary, as ziglua currently doesn't use lazy dependencies
// to circumvent ziglua.artifact() failing in a bad way.
lua = lazyArtifact(ziglua, "lua") orelse return;
@@ -101,7 +102,7 @@ pub fn build(b: *std.Build) !void {
_ = lazyArtifact(ziglua_host, "lua") orelse return;
}
}
if (!system_integration_options.uv) {
if (!sys_opts.uv) {
// NOTE: libuv on Windows depends on Windows SDK when compiled with .Debug mode
// https://github.com/neovim/neovim/issues/36889
const optimize_uv = if (optimize == .Debug and target.result.os.tag == .windows) .ReleaseSafe else optimize;
@@ -127,38 +128,39 @@ pub fn build(b: *std.Build) !void {
}
}
const lpeg = if (system_integration_options.lpeg) null else b.lazyDependency("lpeg", .{});
const lpeg = if (sys_opts.lpeg) null else b.lazyDependency("lpeg", .{});
const iconv = if (is_windows or is_darwin) b.lazyDependency("libiconv", .{
.target = target,
.optimize = optimize,
}) else null;
const utf8proc = if (system_integration_options.utf8proc) null else b.lazyDependency("utf8proc", .{
const utf8proc = if (sys_opts.utf8proc) null else b.lazyDependency("utf8proc", .{
.target = target,
.optimize = optimize,
});
const unibilium = if (use_unibilium and !system_integration_options.unibilium) b.lazyDependency("unibilium", .{
const unibilium = if (use_unibilium and !sys_opts.unibilium) b.lazyDependency("unibilium", .{
.target = target,
.optimize = optimize,
}) else null;
// TODO(bfredl): fix upstream bugs with UBSAN
const optimize_ts = .ReleaseFast;
const treesitter = if (system_integration_options.tree_sitter) null else b.lazyDependency("treesitter", .{
const treesitter = if (sys_opts.tree_sitter) null else b.lazyDependency("treesitter", .{
.target = target,
.optimize = optimize_ts,
});
const nlua0 = try build_lua.build_nlua0(
b,
io,
target_host,
optimize_host,
host_use_luajit,
ziglua_host,
lpeg,
libluv_host,
system_integration_options,
sys_opts,
);
// usual caveat emptor: might need to force a rebuild if the only change is
@@ -201,12 +203,12 @@ pub fn build(b: *std.Build) !void {
const src_dir = b.build_root.handle;
for (subdirs) |s| {
var dir = try src_dir.openDir(b.fmt("src/nvim/{s}", .{s}), .{ .iterate = true });
defer dir.close();
var dir = try src_dir.openDir(io, b.fmt("src/nvim/{s}", .{s}), .{ .iterate = true });
defer dir.close(io);
var it = dir.iterateAssumeFirstIteration();
const api_export = std.mem.eql(u8, s, "api/");
const os_check = std.mem.eql(u8, s, "os/");
entries: while (try it.next()) |entry| {
entries: while (try it.next(io)) |entry| {
if (entry.name.len < 3) continue;
if (entry.name[0] < 'a' or entry.name[0] > 'z') continue;
if (os_check) {
@@ -257,7 +259,7 @@ pub fn build(b: *std.Build) !void {
.VERSION_STRING = "TODO", // TODO(bfredl): not sure what to put here. summary already in "config_str"
.CONFIG = config_str,
});
_ = gen_config.addCopyFile(versiondef_step.getOutput(), "auto/versiondef.h"); // run_preprocessor() workaronnd
_ = gen_config.addCopyFile(versiondef_step.getOutputFile(), "auto/versiondef.h"); // run_preprocessor() workaronnd
const ptrwidth = t.ptrBitWidth() / 8;
const sysconfig_step = b.addConfigHeader(.{
@@ -310,7 +312,7 @@ pub fn build(b: *std.Build) !void {
const system_install_path = b.option([]const u8, "install-path", "Install path (for packagers)");
const install_path = system_install_path orelse b.install_path;
const lib_dir = if (system_install_path) |path| b.fmt("{s}/lib", .{path}) else b.lib_dir;
_ = gen_config.addCopyFile(sysconfig_step.getOutput(), "auto/config.h"); // run_preprocessor() workaronnd
_ = gen_config.addCopyFile(sysconfig_step.getOutputFile(), "auto/config.h"); // run_preprocessor() workaronnd
_ = gen_config.add("auto/pathdef.h", b.fmt(
\\char *default_vim_dir = "{s}/share/nvim";
@@ -336,7 +338,7 @@ pub fn build(b: *std.Build) !void {
"-C", b.build_root.path orelse ".", // affects the --git-dir argument
"--git-dir", ".git", // affected by the -C argument
"describe", "--dirty", "--match", "v*.*.*", //
}, &code, .Ignore) catch {
}, &code, .ignore) catch {
break :v version_string;
};
const git_describe = std.mem.trim(u8, git_describe_untrimmed, " \n\r");
@@ -375,31 +377,31 @@ pub fn build(b: *std.Build) !void {
var unittest_include_path: std.ArrayList(LazyPath) = try .initCapacity(b.allocator, 2);
try unittest_include_path.append(b.allocator, b.path("src/"));
try unittest_include_path.append(b.allocator, gen_config.getDirectory());
if (system_integration_options.lua) {
if (sys_opts.lua) {
try appendSystemIncludePath(b, &unittest_include_path, lualib_name);
} else if (lua) |compile| {
try unittest_include_path.append(b.allocator, compile.getEmittedIncludeTree());
}
if (system_integration_options.uv) {
if (sys_opts.uv) {
try appendSystemIncludePath(b, &unittest_include_path, "libuv");
try appendSystemIncludePath(b, &unittest_include_path, "libluv");
} else {
if (libuv) |compile| try unittest_include_path.append(b.allocator, compile.getEmittedIncludeTree());
if (libluv) |compile| try unittest_include_path.append(b.allocator, compile.getEmittedIncludeTree());
}
if (system_integration_options.utf8proc) {
if (sys_opts.utf8proc) {
try appendSystemIncludePath(b, &unittest_include_path, "libutf8proc");
} else if (utf8proc) |dep| {
try unittest_include_path.append(b.allocator, dep.artifact("utf8proc").getEmittedIncludeTree());
}
if (use_unibilium) {
if (system_integration_options.unibilium) {
if (sys_opts.unibilium) {
try appendSystemIncludePath(b, &unittest_include_path, "unibilium");
} else if (unibilium) |dep| {
try unittest_include_path.append(b.allocator, dep.artifact("unibilium").getEmittedIncludeTree());
}
}
if (system_integration_options.tree_sitter) {
if (sys_opts.tree_sitter) {
try appendSystemIncludePath(b, &unittest_include_path, "tree-sitter");
} else if (treesitter) |dep| {
try unittest_include_path.append(b.allocator, dep.artifact("tree-sitter").getEmittedIncludeTree());
@@ -410,6 +412,7 @@ pub fn build(b: *std.Build) !void {
const gen_headers, const funcs_data = try gen.nvim_gen_sources(
b,
io,
nlua0,
&nvim_sources,
&nvim_headers,
@@ -419,7 +422,7 @@ pub fn build(b: *std.Build) !void {
);
const test_config_step = b.addWriteFiles();
_ = test_config_step.add("test/cmakeconfig/paths.lua", try test_config(b));
_ = test_config_step.add("test/cmakeconfig/paths.lua", try test_config(b, io));
const test_gen_step = b.step("gen_headers", "debug: output generated headers");
const config_install = b.addInstallDirectory(.{
@@ -434,68 +437,58 @@ pub fn build(b: *std.Build) !void {
.install_subdir = "headers/",
}).step);
const nvim_exe = b.addExecutable(.{
.name = "nvim",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
var nvim_mod = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
const nvim_exe = b.addExecutable(.{ .name = "nvim", .root_module = nvim_mod });
nvim_exe.rdynamic = true; // -E
if (system_integration_options.lua) {
if (sys_opts.lua) {
nvim_exe.root_module.linkSystemLibrary(lualib_name, .{});
} else if (lua) |compile| {
nvim_exe.root_module.linkLibrary(compile);
nvim_mod.linkLibrary(compile);
}
if (system_integration_options.uv) {
nvim_exe.root_module.linkSystemLibrary("libuv", .{});
nvim_exe.root_module.linkSystemLibrary("libluv", .{});
if (sys_opts.uv) {
nvim_mod.linkSystemLibrary("libuv", .{});
nvim_mod.linkSystemLibrary("libluv", .{});
} else {
if (libuv) |compile| nvim_exe.root_module.linkLibrary(compile);
if (libluv) |compile| nvim_exe.root_module.linkLibrary(compile);
if (libuv) |compile| nvim_mod.linkLibrary(compile);
if (libluv) |compile| nvim_mod.linkLibrary(compile);
}
if (iconv) |dep| nvim_exe.linkLibrary(dep.artifact("iconv"));
if (system_integration_options.utf8proc) {
nvim_exe.root_module.linkSystemLibrary("utf8proc", .{});
if (iconv) |dep| nvim_mod.linkLibrary(dep.artifact("iconv"));
if (sys_opts.utf8proc) {
nvim_mod.linkSystemLibrary("utf8proc", .{});
} else if (utf8proc) |dep| {
nvim_exe.root_module.linkLibrary(dep.artifact("utf8proc"));
nvim_mod.linkLibrary(dep.artifact("utf8proc"));
}
if (use_unibilium) {
if (system_integration_options.unibilium) {
nvim_exe.root_module.linkSystemLibrary("unibilium", .{});
if (sys_opts.unibilium) {
nvim_mod.linkSystemLibrary("unibilium", .{});
} else if (unibilium) |dep| {
nvim_exe.root_module.linkLibrary(dep.artifact("unibilium"));
nvim_mod.linkLibrary(dep.artifact("unibilium"));
}
}
if (system_integration_options.tree_sitter) {
nvim_exe.root_module.linkSystemLibrary("tree-sitter", .{});
if (sys_opts.tree_sitter) {
nvim_mod.linkSystemLibrary("tree-sitter", .{});
} else if (treesitter) |dep| {
nvim_exe.root_module.linkLibrary(dep.artifact("tree-sitter"));
nvim_mod.linkLibrary(dep.artifact("tree-sitter"));
}
if (is_windows) {
nvim_exe.linkSystemLibrary("netapi32");
nvim_mod.linkSystemLibrary("netapi32", .{});
}
nvim_exe.addIncludePath(b.path("src"));
nvim_exe.addIncludePath(gen_config.getDirectory());
nvim_exe.addIncludePath(gen_headers.getDirectory());
try build_lua.add_lua_modules(
b,
t,
nvim_exe.root_module,
lpeg,
use_luajit,
false,
system_integration_options,
);
nvim_mod.addIncludePath(b.path("src"));
nvim_mod.addIncludePath(gen_config.getDirectory());
nvim_mod.addIncludePath(gen_headers.getDirectory());
try build_lua.add_lua_modules(b, io, t, nvim_mod, lpeg, use_luajit, false, sys_opts);
var unit_test_sources = try std.ArrayList([]u8).initCapacity(b.allocator, 10);
if (support_unittests) {
var unit_test_fixtures = try src_dir.openDir("test/unit/fixtures/", .{ .iterate = true });
defer unit_test_fixtures.close();
var unit_test_fixtures = try src_dir.openDir(io, "test/unit/fixtures/", .{ .iterate = true });
defer unit_test_fixtures.close(io);
var it = unit_test_fixtures.iterateAssumeFirstIteration();
while (try it.next()) |entry| {
while (try it.next(io)) |entry| {
if (entry.name.len < 3) continue;
if (std.mem.eql(u8, ".c", entry.name[entry.name.len - 2 ..])) {
try unit_test_sources.append(b.allocator, b.fmt("test/unit/fixtures/{s}", .{entry.name}));
@@ -520,9 +513,9 @@ pub fn build(b: *std.Build) !void {
if (is_windows) "-DUTF8PROC_STATIC" else "",
if (use_unibilium) "-DHAVE_UNIBILIUM" else "",
};
nvim_exe.addCSourceFiles(.{ .files = src_paths, .flags = &flags });
nvim_mod.addCSourceFiles(.{ .files = src_paths, .flags = &flags });
nvim_exe.addCSourceFiles(.{ .files = &.{
nvim_mod.addCSourceFiles(.{ .files = &.{
"src/xdiff/xdiffi.c",
"src/xdiff/xemit.c",
"src/xdiff/xhistogram.c",
@@ -535,7 +528,7 @@ pub fn build(b: *std.Build) !void {
}, .flags = &flags });
if (is_windows) {
nvim_exe.addWin32ResourceFile(.{ .file = b.path("src/nvim/os/nvim.rc") });
nvim_mod.addWin32ResourceFile(.{ .file = b.path("src/nvim/os/nvim.rc") });
}
const nvim_exe_step = b.step("nvim_bin", "only the binary (not a fully working install!)");
@@ -588,29 +581,11 @@ pub fn build(b: *std.Build) !void {
});
test_deps.dependOn(test_fixture(b, "shell-test", false, false, null, target, optimize, &flags));
test_deps.dependOn(test_fixture(
b,
"tty-test",
true,
system_integration_options.uv,
libuv,
target,
optimize,
&flags,
));
test_deps.dependOn(test_fixture(b, "tty-test", true, sys_opts.uv, libuv, target, optimize, &flags));
test_deps.dependOn(test_fixture(b, "pwsh-test", false, false, null, target, optimize, &flags));
test_deps.dependOn(test_fixture(b, "printargs-test", false, false, null, target, optimize, &flags));
test_deps.dependOn(test_fixture(b, "printenv-test", false, false, null, target, optimize, &flags));
test_deps.dependOn(test_fixture(
b,
"streams-test",
true,
system_integration_options.uv,
libuv,
target,
optimize,
&flags,
));
test_deps.dependOn(test_fixture(b, "streams-test", true, sys_opts.uv, libuv, target, optimize, &flags));
// tee: vendored in src/tee/
const tee_exe = b.addExecutable(.{
@@ -618,10 +593,10 @@ pub fn build(b: *std.Build) !void {
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
tee_exe.addCSourceFile(.{ .file = b.path("src/tee/tee.c") });
tee_exe.linkLibC();
tee_exe.root_module.addCSourceFile(.{ .file = b.path("src/tee/tee.c") });
test_deps.dependOn(&b.addInstallArtifact(tee_exe, .{}).step);
// xxd - hex dump utility (vendored from Vim)
@@ -630,10 +605,10 @@ pub fn build(b: *std.Build) !void {
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
xxd_exe.addCSourceFile(.{ .file = b.path("src/xxd/xxd.c") });
xxd_exe.linkLibC();
xxd_exe.root_module.addCSourceFile(.{ .file = b.path("src/xxd/xxd.c") });
test_deps.dependOn(&b.addInstallArtifact(xxd_exe, .{}).step);
const parser_c = b.dependency("treesitter_c", .{ .target = target, .optimize = optimize_ts });
@@ -686,28 +661,26 @@ pub fn test_fixture(
optimize: std.builtin.OptimizeMode,
flags: []const []const u8,
) *std.Build.Step {
const fixture = b.addExecutable(.{
.name = name,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
var root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
const fixture = b.addExecutable(.{ .name = name, .root_module = root_module });
const source = if (std.mem.eql(u8, name, "pwsh-test")) "shell-test" else name;
if (std.mem.eql(u8, name, "printenv-test")) {
fixture.mingw_unicode_entry_point = true; // uses UNICODE on WINDOWS :scream:
}
fixture.addCSourceFile(.{
root_module.addCSourceFile(.{
.file = b.path(b.fmt("./test/functional/fixtures/{s}.c", .{source})),
.flags = flags,
});
fixture.linkLibC();
if (use_libuv) {
if (use_system_libuv) {
fixture.root_module.linkSystemLibrary("libuv", .{});
root_module.linkSystemLibrary("libuv", .{});
} else if (libuv) |uv| {
fixture.linkLibrary(uv);
root_module.linkLibrary(uv);
}
}
return &b.addInstallArtifact(fixture, .{}).step;
@@ -722,18 +695,19 @@ pub fn add_ts_parser(
optimize: std.builtin.OptimizeMode,
path: enum { test_, install },
) *std.Build.Step {
var root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
const parser = b.addLibrary(.{
.name = name,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
.linkage = .dynamic,
.root_module = root_module,
});
parser.addCSourceFile(.{ .file = parser_dir.path(b, "src/parser.c") });
if (scanner) parser.addCSourceFile(.{ .file = parser_dir.path(b, "src/scanner.c") });
parser.addIncludePath(parser_dir.path(b, "src"));
parser.linkLibC();
root_module.addCSourceFile(.{ .file = parser_dir.path(b, "src/parser.c") });
if (scanner) root_module.addCSourceFile(.{ .file = parser_dir.path(b, "src/scanner.c") });
root_module.addIncludePath(parser_dir.path(b, "src"));
switch (path) {
.install => {
@@ -784,9 +758,10 @@ fn replace_backslashes(b: *std.Build, input: []const u8) ![]const u8 {
input;
}
pub fn test_config(b: *std.Build) ![]u8 {
var buf: [std.fs.max_path_bytes]u8 = undefined;
const src_path = try b.build_root.handle.realpath(".", &buf);
pub fn test_config(b: *std.Build, io: std.Io) ![]u8 {
var buf: [std.fs.max_path_bytes]u8 = std.mem.zeroes([std.fs.max_path_bytes]u8);
_ = try b.build_root.handle.realPath(io, &buf);
const src_path = std.mem.span(@as([*:0]u8, @ptrCast(&buf)));
// we don't use test/cmakeconfig/paths.lua.in because it contains cmake specific logic
return b.fmt(
@@ -817,7 +792,7 @@ fn appendSystemIncludePath(
const stdout = try b.runAllowFail(
&[_][]const u8{ "pkg-config", system_name, "--cflags-only-I", "--keep-system-cflags" },
&code,
.Ignore,
.ignore,
);
if (code != 0) return std.Build.PkgConfigError.PkgConfigFailed;
var arg_it = std.mem.tokenizeAny(u8, stdout, " \r\n\t");

View File

@@ -2,12 +2,12 @@
.name = .neovim,
.fingerprint = 0x66eb090879307a38,
.version = "0.13.0",
.minimum_zig_version = "0.15.2",
.minimum_zig_version = "0.16.0",
.dependencies = .{
.zlua = .{
.url = "git+https://github.com/natecraddock/ziglua#a1cae53f6b841dd4fa108103f4bd0f515ca29cfb",
.hash = "zlua-0.1.0-hGRpCwxDBQD25I09a5dhcaNCEontuUsq2pgB34wjugHQ",
.url = "git+https://github.com/natecraddock/ziglua#c09d0cb9f8175c1c02fbeae51940cfab15f3e085",
.hash = "zlua-0.1.0-hGRpC1hWBQAhR6kPtfypQ1Awn09a9JWpIuErNKPCMwSq",
},
.lpeg = .{
.url = "https://github.com/neovim/deps/raw/d495ee6f79e7962a53ad79670cb92488abe0b9b4/opt/lpeg-1.1.0.tar.gz",
@@ -25,8 +25,8 @@
.lazy = true,
},
.treesitter = .{
.url = "git+https://github.com/tree-sitter/tree-sitter#64698af1ac6abb97f5a548cfbaf6e88bca2d8782",
.hash = "tree_sitter-0.27.0-Tw2sR3PCCwChW63BNQ5OXb1i17eT58LSeWSdweWuZ6lF",
.url = "git+https://github.com/tree-sitter/tree-sitter#aff9b9d92e628bdb159189b7066baa00e8f7535e",
.hash = "tree_sitter-0.27.0-Tw2sR0TDCwBUIKjCd2avkJKfxXvSNZmdynJqiXMUYgAv",
.lazy = true,
},
.libuv = .{

View File

@@ -43,8 +43,8 @@ TREESITTER_QUERY_URL https://github.com/tree-sitter-grammars/tree-sitter-query/a
TREESITTER_QUERY_SHA256 c2b23b9a54cffcc999ded4a5d3949daf338bebb7945dece229f832332e6e6a7d
TREESITTER_MARKDOWN_URL https://github.com/tree-sitter-grammars/tree-sitter-markdown/archive/v0.5.3.tar.gz
TREESITTER_MARKDOWN_SHA256 df845b1ab7c7c163ec57d7fa17170c92b04be199bddab02523636efec5224ab6
TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/64698af1ac6abb97f5a548cfbaf6e88bca2d8782.tar.gz
TREESITTER_SHA256 3ad608d1e30321615e2d6bb3907fbfe65c0c58cf74e8041813ca8a7d8dcf6714
TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/aff9b9d92e628bdb159189b7066baa00e8f7535e.tar.gz
TREESITTER_SHA256 9518f74b873ce1f521257130ddcb8008cbb1b2a5febe7f56271027147c43ee1c
WASMTIME_URL https://github.com/bytecodealliance/wasmtime/archive/v36.0.6.tar.gz
WASMTIME_SHA256 c4a3c596a07c02ba6adce503154a2095fd98037a1e50d56add9773f0269ec9b7

View File

@@ -14,13 +14,14 @@ pub fn build(b: *std.Build) !void {
});
if (b.lazyDependency("unibilium", .{})) |upstream| {
lib.addIncludePath(upstream.path(""));
var root_module = lib.root_module;
root_module.addIncludePath(upstream.path(""));
lib.installHeader(upstream.path("unibilium.h"), "unibilium.h");
lib.linkLibC();
root_module.link_libc = true;
lib.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
root_module.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
"unibilium.c",
"uninames.c",
"uniutil.c",

View File

@@ -1,5 +1,6 @@
.{
.name = "unibilium",
.name = .unibilium,
.fingerprint = 0x1d1baa4896ad720,
.version = "2.1.2",
.paths = .{""},

View File

@@ -14,12 +14,13 @@ pub fn build(b: *std.Build) !void {
});
if (b.lazyDependency("utf8proc", .{})) |upstream| {
lib.addIncludePath(upstream.path(""));
var root_module = lib.root_module;
root_module.addIncludePath(upstream.path(""));
lib.installHeader(upstream.path("utf8proc.h"), "utf8proc.h");
lib.linkLibC();
root_module.link_libc = true;
lib.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
root_module.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
"utf8proc.c",
}, .flags = &.{"-DUTF8PROC_STATIC"} });
}

View File

@@ -1,5 +1,6 @@
.{
.name = "utf8proc",
.name = .utf8proc,
.fingerprint = 0xdcddf08dbb8954c4,
.version = "2.10.0",
.paths = .{""},

View File

@@ -111,7 +111,7 @@ API
BUILD
todo
Building using "zig build" requires zig 0.16.x.
DEFAULTS

View File

@@ -30,9 +30,9 @@ local zig_mode = {
luajit = false,
uncrustify = false,
wasmtime = false,
libuv = false,
unibilium = 'nested',
utf8proc = 'nested',
libuv = 'nested',
}
local dependency_table = {} --- @type table<string, string>

View File

@@ -4,6 +4,7 @@ const LazyPath = std.Build.LazyPath;
pub fn build_nlua0(
b: *std.Build,
io: std.Io,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
use_luajit: bool,
@@ -59,7 +60,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(b, io, target.result, mod, lpeg, use_luajit, true, system_integration_options);
}
// for debugging the nlua0 environment
@@ -83,6 +84,7 @@ pub fn build_nlua0(
pub fn add_lua_modules(
b: *std.Build,
io: std.Io,
target: std.Target,
mod: *std.Build.Module,
lpeg_dep: ?*std.Build.Dependency,
@@ -110,7 +112,7 @@ pub fn add_lua_modules(
.flags = &flags,
});
if (system_integration_options.lpeg) {
if (try findLpeg(b, target)) |lpeg_lib| {
if (try findLpeg(b, io, target)) |lpeg_lib| {
mod.addLibraryPath(.{ .cwd_relative = std.fs.path.dirname(lpeg_lib).? });
mod.addObjectFile(.{ .cwd_relative = lpeg_lib });
}
@@ -149,33 +151,34 @@ pub fn build_libluv(
) !*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 = b.createModule(.{
.target = target,
.optimize = optimize,
}),
.root_module = root_module,
});
if (lua) |lua_lib| {
lib.root_module.linkLibrary(lua_lib);
root_module.linkLibrary(lua_lib);
} else {
const system_lua_lib = if (use_luajit) "luajit" else "lua5.1";
lib.root_module.linkSystemLibrary(system_lua_lib, .{});
root_module.linkSystemLibrary(system_lua_lib, .{});
}
lib.linkLibrary(libuv);
root_module.linkLibrary(libuv);
if (upstream) |dep| {
lib.addIncludePath(dep.path("src"));
root_module.addIncludePath(dep.path("src"));
lib.installHeader(dep.path("src/luv.h"), "luv/luv.h");
lib.addCSourceFiles(.{ .root = dep.path("src/"), .files = &.{
root_module.addCSourceFiles(.{ .root = dep.path("src/"), .files = &.{
"luv.c",
} });
}
if (compat53) |dep| {
lib.addIncludePath(dep.path("c-api"));
lib.addCSourceFiles(.{ .root = dep.path("c-api"), .files = &.{
root_module.addIncludePath(dep.path("c-api"));
root_module.addCSourceFiles(.{ .root = dep.path("c-api"), .files = &.{
"compat-5.3.c",
} });
}
@@ -183,7 +186,7 @@ pub fn build_libluv(
return lib;
}
fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 {
fn findLpeg(b: *std.Build, io: std.Io, target: std.Target) !?[]const u8 {
const filenames = [_][]const u8{
"lpeg_a",
"lpeg",
@@ -197,7 +200,7 @@ fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 {
"--variable=pc_system_libdirs",
"--keep-system-cflags",
"pkg-config",
}, &code, .Ignore), "\r\n");
}, &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| {
@@ -205,10 +208,10 @@ fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 {
try paths.append(b.allocator, b.fmt("{s}/lua/5.1", .{dir}));
}
for (paths.items) |path| {
var dir = std.fs.openDirAbsolute(path, .{}) catch continue;
defer dir.close();
var dir = std.Io.Dir.openDirAbsolute(io, path, .{}) catch continue;
defer dir.close(io);
for (filenames) |filename| {
dir.access(filename, .{}) catch continue;
dir.access(io, filename, .{}) catch continue;
return b.fmt("{s}/{s}", .{ path, filename });
}
}

View File

@@ -5,6 +5,7 @@ pub const SourceItem = struct { name: []u8, api_export: bool };
pub fn nvim_gen_sources(
b: *std.Build,
io: std.Io,
nlua0: *std.Build.Step.Compile,
nvim_sources: *std.ArrayList(SourceItem),
nvim_headers: *std.ArrayList([]u8),
@@ -85,15 +86,15 @@ pub fn nvim_gen_sources(
}
// Dynamically add all Lua _core/ modules (like CMakeLists.txt does)
if (b.build_root.handle.openDir("runtime/lua/vim/_core", .{ .iterate = true })) |core_dir_handle| {
if (b.build_root.handle.openDir(io, "runtime/lua/vim/_core", .{ .iterate = true })) |core_dir_handle| {
var core_dir = core_dir_handle;
defer core_dir.close();
defer core_dir.close(io);
var iter = core_dir.iterate();
var core_files = try std.ArrayList([]const u8).initCapacity(b.allocator, 0);
defer core_files.deinit(b.allocator);
while (try iter.next()) |entry| {
while (try iter.next(io)) |entry| {
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".lua")) {
const module_name = try b.allocator.dupe(u8, entry.name[0 .. entry.name.len - 4]);
try core_files.append(b.allocator, module_name);

View File

@@ -22,7 +22,7 @@ extern "c" fn luaopen_lpeg(ptr: *anyopaque) c_int;
extern "c" fn luaopen_bit(ptr: *anyopaque) c_int;
extern "c" fn luaopen_luv(ptr: *anyopaque) c_int;
fn init() !*Lua {
fn init_lua() !*Lua {
// Initialize the Lua vm
var lua = try Lua.init(std.heap.c_allocator);
lua.openLibs();
@@ -69,26 +69,34 @@ fn init() !*Lua {
return lua;
}
pub fn main() !void {
const argv = std.os.argv;
pub fn main(init: std.process.Init) !void {
const args = init.minimal.args;
const lua = try init();
const lua = try init_lua();
defer lua.deinit();
if (argv.len < 2) {
if (args.vector.len < 2) {
std.debug.print("USAGE: nlua0 script.lua args...\n\n", .{});
return;
}
lua.createTable(@intCast(argv.len - 2), 1);
for (0.., argv[1..]) |i, arg| {
_ = lua.pushString(std.mem.span(arg));
lua.createTable(@intCast(args.vector.len - 2), 1);
var iter = try init.minimal.args.iterateAllocator(init.arena.allocator());
_ = iter.skip();
var i: u32 = 0;
var firstarg: [:0]const u8 = undefined;
while (iter.next()) |val| : (i += 1) {
_ = lua.pushString(val);
if (i == 0) {
firstarg = try lua.toString(-1); // preserved on lua heap..
}
lua.rawSetIndex(-2, @intCast(i));
}
lua.setGlobal("arg");
_ = try lua.getGlobal("debug");
_ = lua.getField(-1, "traceback");
try lua.loadFile(std.mem.span(argv[1]));
try lua.loadFile(firstarg);
lua.protectedCall(.{ .msg_handler = -2 }) catch |e| {
if (e == error.LuaRuntime) {
const msg = try lua.toString(-1);
@@ -104,7 +112,7 @@ fn do_ret1(lua: *Lua, str: [:0]const u8) !void {
}
test "simple test" {
const lua = try init();
const lua = try init_lua();
defer lua.deinit();
try do_ret1(lua, "return vim.isarray({2,3})");

View File

@@ -5,6 +5,7 @@ local clear = n.clear
local eval = n.eval
local has_powershell = n.has_powershell
local matches = t.matches
local not_matches = t.not_matches
local api = n.api
local testprg = n.testprg
@@ -48,7 +49,7 @@ describe(':make', function()
local out = eval('execute("make")')
-- Error message is captured in the file and printed in the footer
matches(
'[\r\n]+.*[\r\n]+.*Unknown first argument%: foo%^%[%[0m[\r\n]+shell returned 3[\r\n]+%(1 of 1%)%: Unknown first argument%: foo',
'[\r\n]+.*[\r\n]+.*Unknown first argument%: foo.*[\r\n]+shell returned 3[\r\n]+%(1 of 1%)%: Unknown first argument%: foo',
out
)
end)
@@ -63,8 +64,9 @@ describe(':make', function()
local out = eval('execute("make")')
-- Ensure there are no "shell returned X" messages between
-- command and last line (indicating zero exit)
matches('.*ready [$]%s+%^%[%[0m', out)
matches('.*ready [$]%s+', out)
matches('\n.*%: ready [$]', out)
not_matches('shell returned', out)
end)
end)
end)

View File

@@ -33,8 +33,8 @@ pub fn testStep(b: *std.Build, kind: []const u8, nvim_bin: *std.Build.Step.Compi
try env.put("TMPDIR", b.fmt("{s}/Xtest_tmpdir", .{b.install_path}));
try env.put("NVIM_LOG_FILE", b.fmt("{s}/Xtest_nvimlog", .{b.install_path}));
env.remove("NVIM");
env.remove("XDG_DATA_DIRS");
_ = env.swapRemove("NVIM");
_ = env.swapRemove("XDG_DATA_DIRS");
return test_step;
}