Compare commits

...

4 Commits

Author SHA1 Message Date
bfredl bb3e03bb6c
Merge f39f1b9dd5 into c18d7941ef 2024-05-09 12:08:54 -04:00
dundargoc c18d7941ef build: allow sccache as compiler cache
Also enable caching for dependencies.

Closes https://github.com/neovim/neovim/issues/28670
2024-05-09 16:39:45 +02:00
bfredl f39f1b9dd5 workaround: to be upstreamed 2024-05-05 10:44:30 +02:00
bfredl 30027f4987 ADVENTURES IN WONDERLAND: build.zig
currently, this works:

zig build nlua0 -- file.lua args
with things like "print(vim.inspect({2,2}))"

and:

zig build wip
ls zig-out/include/

TODO: zig fetch doesn't like  https://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.2.tar.gz
HTTPS/TLS issue
2024-05-05 10:24:58 +02:00
30 changed files with 1244 additions and 35 deletions

53
BRANCH_TODO.md Normal file
View File

@ -0,0 +1,53 @@
Dependencies:
- [x] libuv
- [-] lua
- [ ] luajit
- [x] MSGPACK_URL https://github.com/msgpack/msgpack-c/archive/c-6.0.1.tar.gz
- [x] UNIBILIUM_URL https://github.com/neovim/unibilium/archive/d72c3598e7ac5d1ebf86ee268b8b4ed95c0fa628.tar.gz
- [ ] LIBVTERM_URL https://github.com/neovim/libvterm/archive/v0.3.3.tar.gz
- [-] luv
- [-] lpeg
- [x] compat53 (c api part only - but likely enough)
- [x] TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.22.5.tar.gz
non-glibc:
- [ ] GETTEXT_URL https://github.com/neovim/deps/raw/b9bf36eb31f27e8136d907da38fa23518927737e/opt/gettext-0.20.1.tar.gz
- [ ] LIBICONV_URL https://github.com/neovim/deps/raw/b9bf36eb31f27e8136d907da38fa23518927737e/opt/libiconv-1.17.tar.gz
Runtime dependencies:
- [ ] treesitter parsers
- [ ] cat/tee/xxd.exe
- [ ] WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.1.1/win32yank-x64.zip
Generators (nvim binary):
- [x] gen_api_dispatch.lua
- [x] gen_api_ui_events.lua
- [x] gen_char_blob.lua (partial - LUAC_PRG not supported)
- [x] gen_declarations.lua (partial - some generators generate input for this!)
- [x] gen_eval.lua
- [x] gen_events.lua
- [x] gen_ex_cmds.lua
- [x] gen_options_enum.lua
- [x] gen_options.lua
- [x] gen_unicode_tables.lua
Configuration:
- [x] nvim_version.lua
- [x] versiondef.h
- [ ] src/versiondef.h is a copy where $<CONFIG> has been changed to ${CONFIG}. upstream support for $<foo> ???
- [ ] versiondef_git.h
- [ ] config.h
- [ ] pathdef.h
Generators (Runtime and documentation):
- [ ] gen_vimvim.lua
- [ ] gen_eval_files.lua
- [ ] gen_vimdoc.lua*
- [ ] gen_filetype.lua
- [ ] gen_help_html.lua
- [ ] gen_lsp.lua

View File

@ -50,11 +50,6 @@ file(GLOB DOCFILES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/runtime/doc/*.txt)
set_directory_properties(PROPERTIES
EP_PREFIX "${DEPS_BUILD_DIR}")
find_program(CCACHE_PRG ccache)
if(CCACHE_PRG)
set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CCACHE_PRG})
endif()
if(NOT CI_BUILD)
set(CMAKE_INSTALL_MESSAGE NEVER)
endif()

577
build.zig Normal file
View File

@ -0,0 +1,577 @@
const std = @import("std");
const LazyPath = std.Build.LazyPath;
const version = struct {
const major = 0;
const minor = 10;
const patch = 0;
const prerelease = "-dev";
const api_level = 12;
const api_level_compat = 0;
const api_prerelease = 0;
};
// TODO: upstreeeeaam
pub fn lazyArtifact(d: *std.Build.Dependency, name: []const u8) ?*std.Build.Step.Compile {
var found: ?*std.Build.Step.Compile = null;
for (d.builder.install_tls.step.dependencies.items) |dep_step| {
const inst = dep_step.cast(std.Build.Step.InstallArtifact) orelse continue;
if (std.mem.eql(u8, inst.artifact.name, name)) {
if (found != null) std.debug.panic("artifact name '{s}' is ambiguous", .{name});
found = inst.artifact;
}
}
return found;
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// puc lua 5.1 is not ReleaseSafe "safe"
const optimize_lua = if (optimize == .Debug) .ReleaseSmall else optimize;
const use_luajit = false;
const ziglua = b.dependency("ziglua", .{
.target = target,
.optimize = optimize_lua,
.lang = if (use_luajit) .luajit else .lua51,
.shared = false,
});
const lpeg = b.dependency("lpeg", .{});
// const lua = ziglua.artifact("lua");
const lua = lazyArtifact(ziglua, "lua") orelse return;
const libuv_dep = b.dependency("libuv", .{ .target = target, .optimize = optimize });
const libuv = libuv_dep.artifact("uv");
const libluv = try build_libluv(b, target, optimize, lua, libuv);
const msgpack_c = b.dependency("msgpack_c", .{ .target = target, .optimize = optimize });
const unibilium = b.dependency("unibilium", .{ .target = target, .optimize = optimize });
const treesitter = b.dependency("treesitter", .{ .target = target, .optimize = optimize });
const vterm = b.dependency("vterm", .{ .target = target, .optimize = optimize });
const nlua0 = build_nlua0(b, target, optimize, use_luajit, ziglua, lpeg);
// usual caveat emptor: might need to force a rebuild if the only change is
// addition of new .c files, as those are not seen by any hash
const subdirs = [_][]const u8{
"", // src/nvim itself
"os/",
"api/",
"api/private/",
"msgpack_rpc/",
"tui/",
"event/",
"eval/",
"lua/",
"viml/",
"viml/parser/",
};
// source names _relative_ src/nvim/, not including other src/ subdircs
var nvim_sources = try std.ArrayList(struct { name: []u8, api_export: bool }).initCapacity(b.allocator, 100);
// both source headers and the {module}.h.generated.h files
var api_headers = try std.ArrayList(std.Build.LazyPath).initCapacity(b.allocator, 10);
const windows_only = [_][]const u8{ "pty_process_win.c", "pty_conpty_win.c", "os_win_console.c" };
const is_windows = (target.result.os.tag == .windows);
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 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| {
if (entry.name.len < 3) continue;
if (entry.name[0] < 'a' or entry.name[0] > 'z') continue;
if (os_check) {
if (!is_windows) {
for (windows_only) |name| {
if (std.mem.eql(u8, name, entry.name)) {
continue :entries;
}
}
}
}
if (std.mem.eql(u8, ".c", entry.name[entry.name.len - 2 ..])) {
try nvim_sources.append(.{ .name = b.fmt("{s}{s}", .{ s, entry.name }), .api_export = api_export });
}
if (api_export) {
if (std.mem.eql(u8, ".h", entry.name[entry.name.len - 2 ..]) and !std.mem.eql(u8, "ui_events.in.h", entry.name)) {
try api_headers.append(b.path(b.fmt("src/nvim/{s}{s}", .{ s, entry.name })));
}
}
}
}
const gen_config = b.addWriteFiles();
const gen_headers = b.addWriteFiles();
const version_lua = gen_config.add("nvim_version.lua", lua_version_info(b));
const versiondef_step = b.addConfigHeader(.{ .style = .{ .cmake = b.path("src/versiondef.h.in") } }, .{
.NVIM_VERSION_MAJOR = version.major,
.NVIM_VERSION_MINOR = version.minor,
.NVIM_VERSION_PATCH = version.patch,
.NVIM_VERSION_PRERELEASE = version.prerelease,
.VERSION_STRING = "TODO", // TODO
.CONFIG = b.fmt("build.zig -Doptimize={s}", .{@tagName(optimize)}), // TODO: include optimize name
});
_ = gen_config.addCopyFile(versiondef_step.getOutput(), "auto/versiondef.h"); // run_preprocessor() workaronnd
// TODO: actually run git :p
const medium = b.fmt("v{}.{}.{}{s}+zig", .{ version.major, version.minor, version.patch, version.prerelease });
const versiondef_git = gen_config.add("auto/versiondef_git.h", b.fmt(
\\#define NVIM_VERSION_MEDIUM "{s}"
\\#define NVIM_VERSION_BUILD "baaaar"
\\
, .{medium}));
// TODO(zig): using getEmittedIncludeTree() is ugly af. we want run_preprocessor()
// to use the std.build.Module include_path thing
const include_path = &.{
b.path("src/"),
b.path("src/includes_fixmelater/"),
gen_config.getDirectory(),
lua.getEmittedIncludeTree(),
libuv.getEmittedIncludeTree(),
libluv.getEmittedIncludeTree(),
msgpack_c.artifact("msgpack_c").getEmittedIncludeTree(),
unibilium.artifact("unibilium").getEmittedIncludeTree(),
treesitter.artifact("tree-sitter").getEmittedIncludeTree(),
vterm.artifact("vterm").getEmittedIncludeTree(),
};
for (nvim_sources.items) |s| {
const api_export = if (s.api_export) &api_headers else null;
const input_file = b.path(b.fmt("src/nvim/{s}", .{s.name}));
_ = try generate_header_for(b, s.name, input_file, api_export, nlua0, include_path, target, gen_headers);
}
{
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_ex_cmds.lua"));
_ = gen_header(b, gen_step, "ex_cmds_enum.generated.h", gen_headers);
_ = gen_header(b, gen_step, "ex_cmds_defs.generated.h", gen_headers);
gen_step.addFileArg(b.path("src/nvim/ex_cmds.lua"));
}
{
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_options.lua"));
_ = gen_header(b, gen_step, "options.generated.h", gen_headers);
gen_step.addFileArg(b.path("src/nvim/options.lua"));
}
{
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_options_enum.lua"));
_ = gen_header(b, gen_step, "options_enum.generated.h", gen_headers);
_ = gen_header(b, gen_step, "options_map.generated.h", gen_headers);
gen_step.addFileArg(b.path("src/nvim/options.lua"));
}
{
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_events.lua"));
_ = gen_header(b, gen_step, "auevents_enum.generated.h", gen_headers);
_ = gen_header(b, gen_step, "auevents_name_map.generated.h", gen_headers);
gen_step.addFileArg(b.path("src/nvim/auevents.lua"));
}
{
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_unicode_tables.lua"));
gen_step.addDirectoryArg(b.path("src/unicode"));
_ = gen_header(b, gen_step, "unicode_tables.generated.h", gen_headers);
}
{
// TODO: LUAC_PRG is missing. tricky with cross-compiling..
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_char_blob.lua"));
gen_step.addArg("-c");
_ = gen_header(b, gen_step, "lua/vim_module.generated.h", gen_headers);
// NB: vim._init_packages and vim.inspect must be be first and second ones
// respectively, otherwise --luamod-dev won't work properly.
const names = [_][]const u8{
"_init_packages",
"inspect",
"_editor",
"filetype",
"fs",
"F",
"keymap",
"loader",
"_defaults",
"_options",
"shared",
};
for (names) |n| {
gen_step.addFileArg(b.path(b.fmt("runtime/lua/vim/{s}.lua", .{n})));
gen_step.addArg(b.fmt("vim.{s}", .{n}));
}
}
const ui_metadata = ui_step: {
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_api_ui_events.lua"));
gen_step.addFileArg(b.path("src/nvim/api/ui_events.in.h"));
_ = try gen_header_with_header(b, gen_step, "ui_events_call.generated.h", nlua0, include_path, target, gen_headers);
_ = try gen_header_with_header(b, gen_step, "ui_events_remote.generated.h", nlua0, include_path, target, gen_headers);
const ui_metadata = gen_step.addOutputFileArg("ui_metadata.mpack");
_ = try gen_header_with_header(b, gen_step, "ui_events_client.generated.h", nlua0, include_path, target, gen_headers);
gen_step.addFileArg(b.path("src/nvim/generators/c_grammar.lua"));
break :ui_step ui_metadata;
};
const funcs_metadata = api_step: {
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_api_dispatch.lua"));
_ = try gen_header_with_header(b, gen_step, "api/private/dispatch_wrappers.generated.h", nlua0, include_path, target, gen_headers);
_ = gen_header(b, gen_step, "api/private/api_metadata.generated.h", gen_headers);
const funcs_metadata = gen_step.addOutputFileArg("funcs_metadata.mpack");
_ = gen_header(b, gen_step, "lua_api_c_bindings.generated.h", gen_headers);
_ = gen_header(b, gen_step, "keysets_defs.generated.h", gen_headers);
gen_step.addFileArg(ui_metadata);
gen_step.addFileArg(versiondef_git);
gen_step.addFileArg(version_lua);
gen_step.addFileArg(b.path("src/nvim/generators/c_grammar.lua"));
gen_step.addFileArg(b.path("src/nvim/generators/dump_bin_array.lua"));
gen_step.addFileArg(b.path("src/nvim/api/dispatch_deprecated.lua"));
// now follows all .h files with exported functions
for (api_headers.items) |h| {
gen_step.addFileArg(h);
}
break :api_step funcs_metadata;
};
const funcs_data = eval_step: {
const gen_step = b.addRunArtifact(nlua0);
gen_step.addFileArg(b.path("src/nvim/generators/gen_eval.lua"));
_ = gen_header(b, gen_step, "funcs.generated.h", gen_headers);
gen_step.addFileArg(funcs_metadata);
const funcs_data = gen_step.addOutputFileArg("funcs_data.mpack");
gen_step.addFileArg(b.path("src/nvim/eval.lua"));
break :eval_step funcs_data;
};
_ = funcs_data;
const test_gen_step = b.step("wip", "rearrange the power of it all");
test_gen_step.dependOn(&b.addInstallDirectory(.{ .source_dir = gen_config.getDirectory(), .install_dir = .prefix, .install_subdir = "config/" }).step);
test_gen_step.dependOn(&b.addInstallDirectory(.{ .source_dir = gen_headers.getDirectory(), .install_dir = .prefix, .install_subdir = "headers/" }).step);
const nvim_exe = b.addExecutable(.{
.name = "nvim",
.target = target,
.optimize = optimize,
});
nvim_exe.linkLibrary(lua);
nvim_exe.linkLibrary(libuv);
nvim_exe.linkLibrary(libluv);
nvim_exe.linkLibrary(msgpack_c.artifact("msgpack_c"));
nvim_exe.linkLibrary(unibilium.artifact("unibilium"));
nvim_exe.linkLibrary(treesitter.artifact("tree-sitter"));
nvim_exe.linkLibrary(vterm.artifact("vterm"));
nvim_exe.addIncludePath(b.path("src"));
nvim_exe.addIncludePath(b.path("src/includes_fixmelater"));
nvim_exe.addIncludePath(gen_config.getDirectory());
nvim_exe.addIncludePath(gen_headers.getDirectory());
add_lua_modules(&nvim_exe.root_module, lpeg, use_luajit);
const src_paths = try b.allocator.alloc([]u8, nvim_sources.items.len);
for (nvim_sources.items, 0..) |s, i| {
src_paths[i] = b.fmt("src/nvim/{s}", .{s.name});
}
const flags = [_][]const u8{
"-std=gnu99",
"-DINCLUDE_GENERATED_DECLARATIONS",
"-D_GNU_SOURCE",
if (use_luajit) "" else "-DNVIM_VENDOR_BIT",
};
nvim_exe.addCSourceFiles(.{ .files = src_paths, .flags = &flags });
nvim_exe.addCSourceFiles(.{
.files = &.{ "src/termkey/termkey.c", "src/termkey/driver-csi.c", "src/termkey/driver-ti.c" },
.flags = &.{"-DHAVE_UNIBILIUM"},
});
nvim_exe.addCSourceFiles(.{ .files = &.{
"src/xdiff/xdiffi.c",
"src/xdiff/xemit.c",
"src/xdiff/xhistogram.c",
"src/xdiff/xpatience.c",
"src/xdiff/xprepare.c",
"src/xdiff/xutils.c",
"src/cjson/lua_cjson.c",
"src/cjson/fpconv.c",
"src/cjson/strbuf.c",
}, .flags = &flags });
const nvim_exe_step = b.step("nvim_bin", "only the binary (not a fully working install!)");
nvim_exe_step.dependOn(&b.addInstallArtifact(nvim_exe, .{}).step);
}
pub fn lua_version_info(b: *std.Build) []u8 {
const v = version;
return b.fmt(
\\return {{
\\ {{"major", {}}},
\\ {{"minor", {}}},
\\ {{"patch", {}}},
\\ {{"prerelease", {}}},
\\ {{"api_level", {}}},
\\ {{"api_compatible", {}}},
\\ {{"api_prerelease", {}}},
\\}}
, .{ v.major, v.minor, v.patch, v.prerelease.len > 0, v.api_level, v.api_level_compat, v.api_prerelease });
}
pub fn gen_header(
b: *std.Build,
gen_step: *std.Build.Step.Run,
name: []const u8,
gen_headers: *std.Build.Step.WriteFile,
) std.Build.LazyPath {
_ = b;
const header = gen_step.addOutputFileArg(name);
_ = gen_headers.addCopyFile(header, name);
return header;
}
pub fn gen_header_with_header(
b: *std.Build,
gen_step: *std.Build.Step.Run,
name: []const u8,
nlua0: *std.Build.Step.Compile,
include_path: []const LazyPath,
target: ?std.Build.ResolvedTarget,
gen_headers: *std.Build.Step.WriteFile,
) !std.Build.LazyPath {
if (name.len < 12 or !std.mem.eql(u8, ".generated.h", name[name.len - 12 ..])) return error.InvalidBaseName;
const h = gen_header(b, gen_step, name, gen_headers);
_ = try generate_header_for(b, b.fmt("{s}.h", .{name[0 .. name.len - 12]}), h, null, nlua0, include_path, target, gen_headers);
return h;
}
pub const PreprocessorOptions = struct {
include_dirs: []const LazyPath = &.{},
c_macros: []const []const u8 = &.{},
target: ?std.Build.ResolvedTarget = null,
};
// TODO: this should be suggested to upstream
pub fn run_preprocessor(
b: *std.Build,
src: LazyPath,
output_name: []const u8,
options: PreprocessorOptions,
) !LazyPath {
const run_step = std.Build.Step.Run.create(b, b.fmt("preprocess to get {s}", .{output_name}));
run_step.addArgs(&.{ b.graph.zig_exe, "cc", "-E" });
run_step.addFileArg(src);
run_step.addArg("-o");
const output = run_step.addOutputFileArg(output_name);
// TODO: include path logic for addCSourceFiles and TranslateC is _very_ different
for (options.include_dirs) |include_dir| {
run_step.addArg("-I");
run_step.addDirectoryArg(include_dir);
}
for (options.c_macros) |c_macro| {
run_step.addArg(b.fmt("-D{s}", .{c_macro}));
run_step.addArg(c_macro);
}
if (options.target) |t| {
if (!t.query.isNative()) {
run_step.addArgs(&.{
"-target", try t.query.zigTriple(b.allocator),
});
}
}
run_step.addArgs(&.{ "-MMD", "-MF" });
_ = run_step.addDepFileOutputArg(b.fmt("{s}.d", .{output_name}));
return output;
}
pub fn generate_header_for(
b: *std.Build,
name: []const u8,
input_file: std.Build.LazyPath,
api_export: ?*std.ArrayList(LazyPath),
nlua0: *std.Build.Step.Compile,
include_path: []const LazyPath,
target: ?std.Build.ResolvedTarget,
gen_headers: *std.Build.Step.WriteFile,
) !*std.Build.Step.Run {
if (name.len < 2 or !(std.mem.eql(u8, ".c", name[name.len - 2 ..]) or std.mem.eql(u8, ".h", name[name.len - 2 ..]))) return error.InvalidBaseName;
const basename = name[0 .. name.len - 2];
const i_file = try run_preprocessor(b, input_file, b.fmt("{s}.i", .{basename}), .{
.include_dirs = include_path,
.c_macros = &.{ "HAVE_UNIBILIUM", "_GNU_SOURCE" },
.target = target,
});
const run_step = b.addRunArtifact(nlua0);
run_step.addFileArg(b.path("src/nvim/generators/gen_declarations.lua"));
run_step.addFileArg(input_file);
_ = gen_header(b, run_step, b.fmt("{s}.c.generated.h", .{basename}), gen_headers);
const h_file = gen_header(b, run_step, b.fmt("{s}.h.generated.h", .{basename}), gen_headers);
if (api_export) |api_files| {
try api_files.append(h_file);
}
run_step.addFileArg(i_file);
return run_step;
}
pub fn build_nlua0(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
use_luajit: bool,
ziglua: *std.Build.Dependency,
lpeg: *std.Build.Dependency,
) *std.Build.Step.Compile {
const options = b.addOptions();
options.addOption(bool, "use_luajit", use_luajit);
const nlua0_exe = b.addExecutable(.{
.name = "nlua0",
.root_source_file = .{ .path = "src/nlua0.zig" },
.target = target,
.optimize = optimize,
});
const nlua0_mod = &nlua0_exe.root_module;
const exe_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/nlua0.zig" },
.target = target,
.optimize = optimize,
});
// TODO: need mod.addLibraryPathFromDependency(ziglua)
// nlua0_mod.include_dirs.append(nlua0_mod.owner.allocator, .{ .other_step = ziglua_mod }) catch @panic("OOM");
const embedded_data = b.addModule("embedded_data", .{
.root_source_file = .{ .path = "runtime/embedded_data.zig" },
});
for ([2]*std.Build.Module{ nlua0_mod, &exe_unit_tests.root_module }) |mod| {
mod.addImport("ziglua", ziglua.module("ziglua"));
mod.addImport("embedded_data", embedded_data);
// addImport already links by itself. but we need headers as well..
mod.linkLibrary(ziglua.artifact("lua"));
mod.addOptions("options", options);
mod.addIncludePath(b.path("src"));
mod.addIncludePath(b.path("src/includes_fixmelater"));
add_lua_modules(mod, lpeg, use_luajit);
}
// 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, lpeg: *std.Build.Dependency, use_luajit: bool) void {
const flags = [_][]const u8{
// Standard version used in Lua Makefile
"-std=gnu99",
};
mod.addIncludePath(lpeg.path(""));
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(.{
.root = .{ .dependency = .{ .dependency = lpeg, .sub_path = "" } },
.files = &.{
"lpcap.c",
"lpcode.c",
"lpcset.c",
"lpprint.c",
"lptree.c",
"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,
) !*std.Build.Step.Compile {
const upstream = b.dependency("libluv", .{});
const compat53 = b.dependency("lua_compat53", .{});
const lib = b.addStaticLibrary(.{
.name = "luv",
.target = target,
.optimize = optimize,
});
lib.linkLibrary(lua);
lib.linkLibrary(libuv);
lib.addIncludePath(upstream.path("src"));
lib.addIncludePath(compat53.path("c-api"));
lib.installHeader(upstream.path("src/luv.h"), "luv/luv.h");
lib.addCSourceFiles(.{ .root = upstream.path("src/"), .files = &.{
"luv.c",
} });
lib.addCSourceFiles(.{ .root = compat53.path("c-api"), .files = &.{
"compat-5.3.c",
} });
return lib;
}

51
build.zig.zon Normal file
View File

@ -0,0 +1,51 @@
.{
.name = "neovim",
.version = "0.0.0",
// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.12.0",
// lpeg fetching from https://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.2.tar.gz doesn't work, bundlevendor for now
.dependencies = .{
.ziglua = .{
.url = "https://github.com/natecraddock/ziglua/archive/486f51d3acc61d805783f5f07aee34c75ab59a25.tar.gz",
.hash = "12208603e0f51fa6ce7201d8e851c5979b6b78887434623ac87a0f2a5a3dd3e75130",
},
.lpeg = .{
.url = "https://github.com/neovim/deps/raw/d495ee6f79e7962a53ad79670cb92488abe0b9b4/opt/lpeg-1.1.0.tar.gz",
.hash = "122084badadeb91106dd06b2055119a944c340563536caefd8e22d4064182f7cd6e6",
},
.libluv = .{
.url = "https://github.com/luvit/luv/releases/download/1.48.0-2/luv-1.48.0-2.tar.gz",
.hash = "122050b45fc1b2d1e72d30d3e4f446735ab95bbb88658bc1de736e5dc71c3e3cd767",
},
.lua_compat53 = .{
.url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.13.tar.gz",
.hash = "1220e75685f00c242fbf6c1c60e98dd1b24ba99e38277970a10636e44ed08cf2af8a",
},
.treesitter = .{
.url = "https://github.com/bfredl/tree-sitter/archive/1174f67cc6a9661fdd59f847d690ee874d8eaa66.tar.gz",
.hash = "1220cec07c0fd62e3832c13eb1744c4c94f8b9915d86de960ce849f48875fa61dec9",
},
.libuv = .{ .path = "./deps/libuv" },
.msgpack_c = .{ .path = "./deps/msgpack_c/" },
.unibilium = .{ .path = "./deps/unibilium/" },
.vterm = .{ .path = "./deps/vterm/" },
},
.paths = .{
// This makes *all* files, recursively, included in this package. It is generally
// better to explicitly list the files and directories instead, to insure that
// fetching from tarballs, file system paths, and version control all result
// in the same contents hash.
"",
// For example...
//"build.zig",
//"build.zig.zon",
//"src",
//"LICENSE",
//"README.md",
},
}

View File

@ -12,6 +12,6 @@
#endif
#define NVIM_VERSION_CFLAGS "${VERSION_STRING}"
#define NVIM_VERSION_BUILD_TYPE "$<CONFIG>"
#define NVIM_VERSION_BUILD_TYPE "${CONFIG}"
#endif // AUTO_VERSIONDEF_H

View File

@ -23,6 +23,12 @@ if(POLICY CMP0092)
list(APPEND DEPS_CMAKE_ARGS -D CMAKE_POLICY_DEFAULT_CMP0092=NEW)
endif()
find_program(CACHE_PRG NAMES ccache sccache)
if(CACHE_PRG)
set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CACHE_PRG})
list(APPEND DEPS_CMAKE_CACHE_ARGS -DCMAKE_C_COMPILER_LAUNCHER:STRING=${CMAKE_C_COMPILER_LAUNCHER})
endif()
# MAKE_PRG
if(UNIX)
find_program(MAKE_PRG NAMES gmake make)
@ -58,7 +64,8 @@ function(get_externalproject_options name DEPS_IGNORE_SHA)
set(EXTERNALPROJECT_OPTIONS
DOWNLOAD_NO_PROGRESS TRUE
EXTERNALPROJECT_OPTIONS URL ${${name_allcaps}_URL})
EXTERNALPROJECT_OPTIONS URL ${${name_allcaps}_URL}
CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})
if(NOT ${DEPS_IGNORE_SHA})
list(APPEND EXTERNALPROJECT_OPTIONS URL_HASH SHA256=${${name_allcaps}_SHA256})

124
deps/libuv/build.zig vendored Normal file
View File

@ -0,0 +1,124 @@
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("libuv", .{});
const lib = b.addStaticLibrary(.{
.name = "uv",
.target = target,
.optimize = optimize,
});
lib.addIncludePath(upstream.path("include"));
lib.addIncludePath(upstream.path("src"));
lib.installHeadersDirectory(upstream.path("include"), ".", .{});
if (target.result.os.tag == .windows) {
lib.linkSystemLibrary("psapi");
lib.linkSystemLibrary("user32");
lib.linkSystemLibrary("advapi32");
lib.linkSystemLibrary("iphlpapi");
lib.linkSystemLibrary("userenv");
lib.linkSystemLibrary("ws2_32");
}
if (target.result.os.tag == .linux) {
lib.linkSystemLibrary("pthread");
}
lib.linkLibC();
if (target.result.os.tag != .windows) {
lib.root_module.addCMacro("FILE_OFFSET_BITS", "64");
lib.root_module.addCMacro("_LARGEFILE_SOURCE", "");
}
if (target.result.os.tag == .linux) {
lib.root_module.addCMacro("_GNU_SOURCE", "");
lib.root_module.addCMacro("_POSIX_C_SOURCE", "200112");
}
if (target.result.isDarwin()) {
lib.root_module.addCMacro("_DARWIN_UNLIMITED_SELECT", "1");
lib.root_module.addCMacro("_DARWIN_USE_64_BIT_INODE", "1");
}
const root = upstream.path("");
// C files common to all platforms
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/fs-poll.c",
"src/idna.c",
"src/inet.c",
"src/random.c",
"src/strscpy.c",
"src/strtok.c",
"src/threadpool.c",
"src/timer.c",
"src/uv-common.c",
"src/uv-data-getter-setters.c",
"src/version.c",
} });
if (target.result.os.tag != .windows) {
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/unix/async.c",
"src/unix/core.c",
"src/unix/dl.c",
"src/unix/fs.c",
"src/unix/getaddrinfo.c",
"src/unix/getnameinfo.c",
"src/unix/loop-watcher.c",
"src/unix/loop.c",
"src/unix/pipe.c",
"src/unix/poll.c",
"src/unix/process.c",
"src/unix/random-devurandom.c",
"src/unix/signal.c",
"src/unix/stream.c",
"src/unix/tcp.c",
"src/unix/thread.c",
"src/unix/tty.c",
"src/unix/udp.c",
} });
}
if (target.result.os.tag == .linux or target.result.isDarwin()) {
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/unix/proctitle.c",
} });
}
if (target.result.os.tag == .linux) {
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/unix/linux.c",
"src/unix/procfs-exepath.c",
"src/unix/random-getrandom.c",
"src/unix/random-sysctl-linux.c",
} });
}
if (target.result.isBSD()) {
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/unix/bsd-ifaddrs.c",
"src/unix/kqueue.c",
} });
}
if (target.result.isDarwin() or target.result.os.tag == .openbsd) {
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/unix/random-getentropy.c",
} });
}
if (target.result.isDarwin()) {
lib.addCSourceFiles(.{ .root = root, .files = &.{
"src/unix/darwin-proctitle.c",
"src/unix/darwin.c",
"src/unix/fsevents.c",
} });
}
b.installArtifact(lib);
}

12
deps/libuv/build.zig.zon vendored Normal file
View File

@ -0,0 +1,12 @@
.{
.name = "libuv",
.version = "1.48.0",
.paths = .{""},
.dependencies = .{
.libuv = .{
.url = "https://github.com/libuv/libuv/archive/v1.48.0.tar.gz",
.hash = "1220c2e1269cfee3735a7331f1fa4c13aa3e4f355fca5b402be3ea72a464c76f1324",
},
},
}

47
deps/msgpack_c/build.zig vendored Normal file
View File

@ -0,0 +1,47 @@
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("msgpack_c", .{});
const lib = b.addStaticLibrary(.{
.name = "msgpack_c",
.target = target,
.optimize = optimize,
});
// via getEmittedIncludeTree to merge in configs properly
// lib.addIncludePath(upstream.path("include"));
lib.addIncludePath(upstream.path("src"));
// TODO: actually detect BIG-lyness of `target`
const sysdep = b.addConfigHeader(.{
.style = .{ .cmake = upstream.path("cmake/sysdep.h.in") },
.include_path = "msgpack/sysdep.h",
}, .{ .MSGPACK_ENDIAN_BIG_BYTE = "0", .MSGPACK_ENDIAN_LITTLE_BYTE = "1" });
lib.addConfigHeader(sysdep);
const pack_template = b.addConfigHeader(.{
.style = .{ .cmake = upstream.path("cmake/pack_template.h.in") },
.include_path = "msgpack/pack_template.h",
}, .{ .MSGPACK_ENDIAN_BIG_BYTE = "0", .MSGPACK_ENDIAN_LITTLE_BYTE = "1" });
lib.addConfigHeader(pack_template);
lib.installHeadersDirectory(upstream.path("include"), ".", .{});
lib.installConfigHeader(sysdep);
lib.installConfigHeader(pack_template);
lib.addIncludePath(lib.getEmittedIncludeTree());
lib.linkLibC();
lib.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
"src/objectc.c",
"src/unpack.c",
"src/version.c",
"src/vrefbuffer.c",
"src/zone.c",
} });
b.installArtifact(lib);
}

12
deps/msgpack_c/build.zig.zon vendored Normal file
View File

@ -0,0 +1,12 @@
.{
.name = "msgpack_c",
.version = "6.0.1",
.paths = .{""},
.dependencies = .{
.msgpack_c = .{
.url = "https://github.com/msgpack/msgpack-c/archive/c-6.0.1.tar.gz",
.hash = "1220781494e79f4d4351608b6442f9f7814df38dea9e96858dadbb54a65e564134c3",
},
},
}

27
deps/unibilium/build.zig vendored Normal file
View File

@ -0,0 +1,27 @@
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("unibilium", .{});
const lib = b.addStaticLibrary(.{
.name = "unibilium",
.target = target,
.optimize = optimize,
});
lib.addIncludePath(upstream.path(""));
lib.installHeader(upstream.path("unibilium.h"), "unibilium.h");
lib.linkLibC();
lib.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
"unibilium.c",
"uninames.c",
"uniutil.c",
}, .flags = &.{"-DTERMINFO_DIRS=\"/etc/terminfo:/usr/share/terminfo\""} });
b.installArtifact(lib);
}

12
deps/unibilium/build.zig.zon vendored Normal file
View File

@ -0,0 +1,12 @@
.{
.name = "unibilium",
.version = "0.0.1",
.paths = .{""},
.dependencies = .{
.unibilium = .{
.url = "https://github.com/neovim/unibilium/archive/d72c3598e7ac5d1ebf86ee268b8b4ed95c0fa628.tar.gz",
.hash = "1220eb029114911f764a2266a8595829343b726d8aa81105a728920fdcba4b482a7d",
},
},
}

36
deps/vterm/build.zig vendored Normal file
View File

@ -0,0 +1,36 @@
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("vterm", .{});
const lib = b.addStaticLibrary(.{
.name = "vterm",
.target = target,
.optimize = optimize,
});
lib.addIncludePath(upstream.path("src/"));
lib.addIncludePath(upstream.path("include/"));
// local additions: DECdrawing.inc and uk.inc (u w8t m8)
lib.addIncludePath(b.path("include/"));
lib.installHeadersDirectory(upstream.path("include"), ".", .{});
lib.linkLibC();
lib.addCSourceFiles(.{ .root = upstream.path("src"), .files = &.{
"encoding.c",
"keyboard.c",
"mouse.c",
"parser.c",
"pen.c",
"screen.c",
"state.c",
"unicode.c",
"vterm.c",
} });
b.installArtifact(lib);
}

12
deps/vterm/build.zig.zon vendored Normal file
View File

@ -0,0 +1,12 @@
.{
.name = "vterm",
.version = "0.3.3",
.paths = .{""},
.dependencies = .{
.vterm = .{
.url = "https://github.com/neovim/libvterm/archive/v0.3.3.tar.gz",
.hash = "1220184ae54d2331deb1be5d905978205c2731714e4b0ae8587e72c4ce02da317195",
},
},
}

View File

@ -0,0 +1,36 @@
static const struct StaticTableEncoding encoding_DECdrawing = {
{ .decode = &decode_table },
{
[0x60] = 0x25C6,
[0x61] = 0x2592,
[0x62] = 0x2409,
[0x63] = 0x240C,
[0x64] = 0x240D,
[0x65] = 0x240A,
[0x66] = 0x00B0,
[0x67] = 0x00B1,
[0x68] = 0x2424,
[0x69] = 0x240B,
[0x6a] = 0x2518,
[0x6b] = 0x2510,
[0x6c] = 0x250C,
[0x6d] = 0x2514,
[0x6e] = 0x253C,
[0x6f] = 0x23BA,
[0x70] = 0x23BB,
[0x71] = 0x2500,
[0x72] = 0x23BC,
[0x73] = 0x23BD,
[0x74] = 0x251C,
[0x75] = 0x2524,
[0x76] = 0x2534,
[0x77] = 0x252C,
[0x78] = 0x2502,
[0x79] = 0x2A7D,
[0x7a] = 0x2A7E,
[0x7b] = 0x03C0,
[0x7c] = 0x2260,
[0x7d] = 0x00A3,
[0x7e] = 0x00B7,
}
};

6
deps/vterm/include/encoding/uk.inc vendored Normal file
View File

@ -0,0 +1,6 @@
static const struct StaticTableEncoding encoding_uk = {
{ .decode = &decode_table },
{
[0x23] = 0x00a3,
}
};

View File

@ -0,0 +1,2 @@
pub const inspect_module = @embedFile("./lua/vim/inspect.lua");
pub const shared_module = @embedFile("./lua/vim/shared.lua");

View File

@ -0,0 +1,55 @@
#pragma once
#define SIZEOF_INT 4
#define SIZEOF_INTMAX_T 8
#define SIZEOF_LONG 8
#define SIZEOF_SIZE_T 8
#if 8 == 8
#define ARCH_64
#elif 8 == 4
#define ARCH_32
#endif
#define PROJECT_NAME "nvim"
/* #undef HAVE__NSGETENVIRON */
#define HAVE_FD_CLOEXEC
#define HAVE_FSEEKO
#define HAVE_LANGINFO_H
#define HAVE_NL_LANGINFO_CODESET
#define HAVE_NL_MSG_CAT_CNTR
#define HAVE_PWD_FUNCS
#define HAVE_READLINK
#define HAVE_STRNLEN
#define HAVE_STRCASECMP
#define HAVE_STRINGS_H
#define HAVE_STRNCASECMP
#define HAVE_STRPTIME
#define HAVE_XATTR
// #define HAVE_SYS_SDT_H
#define HAVE_SYS_UTSNAME_H
/* #undef HAVE_SYS_WAIT_H */
#define HAVE_TERMIOS_H
#define HAVE_WORKING_LIBINTL
#define UNIX
/* #undef CASE_INSENSITIVE_FILENAME */
/* #undef USE_FNAME_CASE */
#define HAVE_SYS_UIO_H
#ifdef HAVE_SYS_UIO_H
#define HAVE_READV
# ifndef HAVE_READV
# undef HAVE_SYS_UIO_H
# endif
#endif
#define HAVE_DIRFD_AND_FLOCK
#define HAVE_FORKPTY
#define HAVE_BE64TOH
/* #undef ORDER_BIG_ENDIAN */
#define ENDIAN_INCLUDE_FILE <endian.h>
#define HAVE_EXECINFO_BACKTRACE
#define HAVE_BUILTIN_ADD_OVERFLOW
#define HAVE_WIMPLICIT_FALLTHROUGH_FLAG
/* #undef HAVE_BITSCANFORWARD64 */

View File

@ -0,0 +1,3 @@
char *default_vim_dir = "/usr/local/share/nvim";
char *default_vimruntime_dir = "";
char *default_lib_dir = "/usr/local/lib/nvim";

113
src/nlua0.zig Normal file
View File

@ -0,0 +1,113 @@
const std = @import("std");
const ziglua = @import("ziglua");
const options = @import("options");
const embedded_data = @import("embedded_data");
const hashy = @embedFile("nvim/generators/hashy.lua");
const Lua = ziglua.Lua;
extern "c" fn luaopen_mpack(ptr: *anyopaque) c_int;
extern "c" fn luaopen_lpeg(ptr: *anyopaque) c_int;
extern "c" fn luaopen_bit(ptr: *anyopaque) c_int;
fn init() !*Lua {
// Initialize the Lua vm
var lua = try Lua.newStateLibc();
lua.openLibs();
// this sets _G.vim by itself, so we don't need to
try lua.loadBuffer(embedded_data.shared_module, "shared.lua");
lua.call(0, 1);
try lua.loadBuffer(embedded_data.inspect_module, "inspect.lua");
lua.call(0, 1);
lua.setField(-2, "inspect");
_ = try lua.getGlobal("package");
_ = lua.getField(-1, "preload");
try lua.loadBuffer(hashy, "hashy.lua"); // [package, preload, hashy]
lua.setField(-2, "generators.hashy");
lua.pop(2);
const retval = luaopen_mpack(lua);
if (retval != 1) return error.LoadError;
_ = lua.getField(-1, "NIL"); // [vim, mpack, NIL]
lua.setField(-3, "NIL"); // vim.NIL = mpack.NIL (wow BOB wow)
lua.setField(-2, "mpack");
const retval2 = luaopen_lpeg(lua);
if (retval2 != 1) return error.LoadError;
lua.setField(-3, "lpeg");
lua.pop(2);
if (!options.use_luajit) {
lua.pop(luaopen_bit(lua));
}
return lua;
}
pub fn main() !void {
const argv = std.os.argv;
const lua = try init();
defer lua.deinit();
if (argv.len < 2) {
std.debug.print("USAGE: nlua0 script.lua args...\n\n", .{});
try lua.doString("print(vim.inspect(vim.uv.os_uname()))");
return;
}
lua.createTable(@intCast(argv.len - 2), 1);
for (0.., argv[1..]) |i, arg| {
_ = lua.pushString(std.mem.span(arg));
lua.rawSetIndex(-2, @intCast(i));
}
lua.setGlobal("arg");
// Create an allocator
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// const allocator = gpa.allocator();
// defer _ = gpa.deinit();
//std.debug.print("All your {s} are belong to us.\n", .{argv[1]});
_ = try lua.getGlobal("debug");
_ = lua.getField(-1, "traceback");
try lua.loadFile(std.mem.span(argv[1]));
lua.protectedCall(0, 0, -2) catch |e| {
if (e == error.Runtime) {
const msg = try lua.toString(-1);
std.debug.print("{s}\n", .{msg});
}
return e;
};
}
fn do_ret1(lua: *Lua, str: [:0]const u8) !void {
try lua.loadString(str);
try lua.protectedCall(0, 1, 0);
}
test "simple test" {
const lua = try init();
defer lua.deinit();
try do_ret1(lua, "return vim.isarray({2,3})");
try std.testing.expectEqual(true, lua.toBoolean(-1));
lua.pop(1);
try do_ret1(lua, "return vim.isarray({a=2,b=3})");
try std.testing.expectEqual(false, lua.toBoolean(-1));
lua.pop(1);
try do_ret1(lua, "return vim.inspect(vim.mpack.decode('\\146\\42\\69'))");
try std.testing.expectEqualStrings("{ 42, 69 }", try lua.toString(-1));
lua.pop(1);
try do_ret1(lua, "return require'bit'.band(7,12)");
try std.testing.expectEqualStrings("4", try lua.toString(-1));
lua.pop(1);
}

View File

@ -571,14 +571,19 @@ add_custom_command(
${LUA_API_C_BINDINGS}
${GENERATED_KEYSETS_DEFS}
${UI_METADATA}
${NVIM_VERSION_GIT_H}
${NVIM_VERSION_GIT_H} ${NVIM_VERSION_LUA}
${GENERATOR_C_GRAMMAR}
${GENERATOR_DIR}/dump_bin_array.lua
${CMAKE_CURRENT_LIST_DIR}/api/dispatch_deprecated.lua
${API_HEADERS}
DEPENDS
${LUA_GEN_DEPS}
${API_HEADERS}
${MSGPACK_RPC_HEADERS}
${API_DISPATCH_GENERATOR}
${GENERATOR_C_GRAMMAR}
${GENERATOR_DIR}/dump_bin_array.lua
${UI_METADATA}
${NVIM_VERSION_LUA}
${NVIM_VERSION_GIT_H}
@ -630,6 +635,7 @@ add_custom_command(
${GENERATED_UI_EVENTS_REMOTE}
${UI_METADATA}
${GENERATED_UI_EVENTS_CLIENT}
${GENERATOR_C_GRAMMAR}
DEPENDS
${LUA_GEN_DEPS}
${API_UI_EVENTS_GENERATOR}
@ -656,29 +662,29 @@ list(APPEND NVIM_GENERATED_FOR_SOURCES
)
add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS}
COMMAND ${LUA_GEN} ${EX_CMDS_GENERATOR} ${GENERATED_INCLUDES_DIR} ${GENERATED_DIR}
COMMAND ${LUA_GEN} ${EX_CMDS_GENERATOR} ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS} ${CMAKE_CURRENT_LIST_DIR}/ex_cmds.lua
DEPENDS ${LUA_GEN_DEPS} ${EX_CMDS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/ex_cmds.lua
)
add_custom_command(OUTPUT ${GENERATED_FUNCS} ${FUNCS_DATA}
COMMAND ${LUA_GEN} ${FUNCS_GENERATOR} ${GENERATED_DIR} ${FUNCS_METADATA} ${FUNCS_DATA}
COMMAND ${LUA_GEN} ${FUNCS_GENERATOR} ${GENERATED_FUNCS} ${FUNCS_METADATA} ${FUNCS_DATA} ${CMAKE_CURRENT_LIST_DIR}/eval.lua
DEPENDS ${LUA_GEN_DEPS} ${FUNCS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/eval.lua ${FUNCS_METADATA}
)
list(APPEND NVIM_GENERATED_FOR_SOURCES
"${GENERATED_FUNCS}")
add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
COMMAND ${LUA_GEN} ${EVENTS_GENERATOR} ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
COMMAND ${LUA_GEN} ${EVENTS_GENERATOR} ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP} ${CMAKE_CURRENT_LIST_DIR}/auevents.lua
DEPENDS ${LUA_GEN_DEPS} ${EVENTS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/auevents.lua
)
add_custom_command(OUTPUT ${GENERATED_OPTIONS}
COMMAND ${LUA_GEN} ${OPTIONS_GENERATOR} ${GENERATED_OPTIONS}
COMMAND ${LUA_GEN} ${OPTIONS_GENERATOR} ${GENERATED_OPTIONS} ${CMAKE_CURRENT_LIST_DIR}/options.lua
DEPENDS ${LUA_GEN_DEPS} ${OPTIONS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/options.lua
)
add_custom_command(OUTPUT ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP}
COMMAND ${LUA_GEN} ${OPTIONS_ENUM_GENERATOR} ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP}
COMMAND ${LUA_GEN} ${OPTIONS_ENUM_GENERATOR} ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP} ${CMAKE_CURRENT_LIST_DIR}/options.lua
DEPENDS ${LUA_GEN_DEPS} ${OPTIONS_ENUM_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/options.lua
)

View File

@ -2,8 +2,6 @@ local mpack = vim.mpack
local hashy = require 'generators.hashy'
local pre_args = 7
assert(#arg >= pre_args)
-- output h file with generated dispatch functions (dispatch_wrappers.generated.h)
local dispatch_outputf = arg[1]
-- output h file with packed metadata (api_metadata.generated.h)
@ -14,6 +12,12 @@ local lua_c_bindings_outputf = arg[4] -- lua_api_c_bindings.generated.c
local keysets_outputf = arg[5] -- keysets_defs.generated.h
local ui_metadata_inputf = arg[6] -- ui events metadata
local git_version_inputf = arg[7] -- git version header
local nvim_version_inputf = arg[8] -- nvim version
local c_grammar_inputf = arg[9]
local dump_bin_array_inputf = arg[10]
local dispatch_deprecated_inputf = arg[11]
local pre_args = 11
assert(#arg >= pre_args)
local functions = {}
@ -24,7 +28,7 @@ local headers = {}
-- set of function names, used to detect duplicates
local function_names = {}
local c_grammar = require('generators.c_grammar')
local c_grammar = loadfile(c_grammar_inputf)()
local startswith = vim.startswith
@ -137,7 +141,7 @@ end
-- Export functions under older deprecated names.
-- These will be removed eventually.
local deprecated_aliases = require('api.dispatch_deprecated')
local deprecated_aliases = loadfile(dispatch_deprecated_inputf)()
for _, f in ipairs(shallowcopy(functions)) do
local ismethod = false
if startswith(f.name, 'nvim_') then
@ -229,7 +233,7 @@ for x in string.gmatch(ui_options_text, '"([a-z][a-z_]+)"') do
table.insert(ui_options, x)
end
local version = require 'nvim_version'
local version = loadfile(nvim_version_inputf)()
local git_version = io.open(git_version_inputf):read '*a'
local version_build = string.match(git_version, '#define NVIM_VERSION_BUILD "([^"]+)"') or vim.NIL
@ -286,7 +290,7 @@ for i, item in ipairs(types) do
end
local packed = table.concat(pieces)
local dump_bin_array = require('generators.dump_bin_array')
local dump_bin_array = loadfile(dump_bin_array_inputf)()
dump_bin_array(api_metadata_output, 'packed_api_metadata', packed)
api_metadata_output:close()

View File

@ -1,13 +1,14 @@
local mpack = vim.mpack
assert(#arg == 5)
assert(#arg == 6)
local input = io.open(arg[1], 'rb')
local call_output = io.open(arg[2], 'wb')
local remote_output = io.open(arg[3], 'wb')
local metadata_output = io.open(arg[4], 'wb')
local client_output = io.open(arg[5], 'wb')
local c_grammar_inputf = arg[6]
local c_grammar = require('generators.c_grammar')
local c_grammar = loadfile(c_grammar_inputf)()
local events = c_grammar.grammar:match(input:read('*all'))
local hashy = require 'generators.hashy'

View File

@ -1,10 +1,9 @@
local mpack = vim.mpack
local autodir = arg[1]
local funcsfname = arg[1]
local metadata_file = arg[2]
local funcs_file = arg[3]
local funcsfname = autodir .. '/funcs.generated.h'
local eval_file = arg[4]
--Will generate funcs.generated.h with definition of functions static const array.
@ -45,7 +44,7 @@ hashpipe:write([[
]])
local funcs = require('eval').funcs
local funcs = loadfile(eval_file)().funcs
for _, func in pairs(funcs) do
if func.float_func then
func.func = 'float_op_wrapper'

View File

@ -1,7 +1,8 @@
local fileio_enum_file = arg[1]
local names_file = arg[2]
local auevents_file = arg[3]
local auevents = require('auevents')
local auevents = loadfile(auevents_file)()
local events = auevents.events
local aliases = auevents.aliases

View File

@ -1,17 +1,15 @@
local includedir = arg[1]
local autodir = arg[2]
-- Will generate files ex_cmds_enum.generated.h with cmdidx_T enum
-- and ex_cmds_defs.generated.h with main Ex commands definitions.
local enumfname = includedir .. '/ex_cmds_enum.generated.h'
local defsfname = autodir .. '/ex_cmds_defs.generated.h'
local enumfname = arg[1] -- '/ex_cmds_enum.generated.h'
local defsfname = arg[2] -- '/ex_cmds_defs.generated.h'
local ex_cmds_name = arg[3] -- 'ex_cmds.lua'
local enumfile = io.open(enumfname, 'w')
local defsfile = io.open(defsfname, 'w')
local bit = require 'bit'
local ex_cmds = require('ex_cmds')
local ex_cmds = loadfile(ex_cmds_name)()
local defs = ex_cmds.cmds
local flags = ex_cmds.flags

View File

@ -1,4 +1,5 @@
local options_file = arg[1]
local options_input_file = arg[2]
local opt_fd = assert(io.open(options_file, 'w'))
@ -11,7 +12,7 @@ local w = function(s)
end
--- @module 'nvim.options'
local options = require('options')
local options = loadfile(options_input_file)()
local cstr = options.cstr

View File

@ -4,6 +4,8 @@
local options_enum_file = arg[1]
local options_map_file = arg[2]
local options_input_file = arg[3]
local options_enum_fd = assert(io.open(options_enum_file, 'w'))
local options_map_fd = assert(io.open(options_map_file, 'w'))
@ -27,7 +29,7 @@ local lowercase_to_titlecase = function(s)
end
--- @type vim.option_meta[]
local options = require('options').options
local options = loadfile(options_input_file)().options
-- Generate BV_ enum constants.
enum_w('/// "indir" values for buffer-local options.')

View File

@ -665,7 +665,7 @@ static inline void nlua_create_typed_table(lua_State *lstate, const size_t narr,
void nlua_push_String(lua_State *lstate, const String s, int flags)
FUNC_ATTR_NONNULL_ALL
{
lua_pushlstring(lstate, s.data, s.size);
lua_pushlstring(lstate, s.size ? s.data : "", s.size);
}
/// Convert given Integer to lua number

17
src/versiondef.h.in Normal file
View File

@ -0,0 +1,17 @@
#ifndef AUTO_VERSIONDEF_H
#define AUTO_VERSIONDEF_H
#define NVIM_VERSION_MAJOR @NVIM_VERSION_MAJOR@
#define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@
#define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@
#define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@"
#cmakedefine NVIM_VERSION_MEDIUM "@NVIM_VERSION_MEDIUM@"
#ifndef NVIM_VERSION_MEDIUM
# include "auto/versiondef_git.h"
#endif
#define NVIM_VERSION_CFLAGS "${VERSION_STRING}"
#define NVIM_VERSION_BUILD_TYPE "${CONFIG}"
#endif // AUTO_VERSIONDEF_H