From 5ec0c1ca07f9b8a8bea71bb46e2d92fe3189c600 Mon Sep 17 00:00:00 2001 From: Chinmay Dalal Date: Sun, 11 Jan 2026 22:33:44 -0500 Subject: [PATCH] feat(build.zig): install parsers in install step Problem: The install step does not install parsers Solution: Make the install step depend on installing parsers --- build.zig | 64 +++++++++++++++++++++++++++++++++------------------ build.zig.zon | 6 ----- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/build.zig b/build.zig index 4e3a4c12de..a7e31dd373 100644 --- a/build.zig +++ b/build.zig @@ -623,25 +623,31 @@ pub fn build(b: *std.Build) !void { xxd_exe.linkLibC(); test_deps.dependOn(&b.addInstallArtifact(xxd_exe, .{}).step); - if (b.lazyDependency("treesitter_c", .{ .target = target, .optimize = optimize })) |parser| { - test_deps.dependOn(add_ts_parser(b, "c", parser.path("."), false, target, optimize)); - } - if (b.lazyDependency("treesitter_markdown", .{ .target = target, .optimize = optimize })) |parser| { - test_deps.dependOn(add_ts_parser(b, "markdown", parser.path("tree-sitter-markdown/"), true, target, optimize)); - test_deps.dependOn(add_ts_parser(b, "markdown_inline", parser.path("tree-sitter-markdown-inline/"), true, target, optimize)); - } - if (b.lazyDependency("treesitter_vim", .{ .target = target, .optimize = optimize })) |parser| { - test_deps.dependOn(add_ts_parser(b, "vim", parser.path("."), true, target, optimize)); - } - if (b.lazyDependency("treesitter_vimdoc", .{ .target = target, .optimize = optimize })) |parser| { - test_deps.dependOn(add_ts_parser(b, "vimdoc", parser.path("."), false, target, optimize)); - } - if (b.lazyDependency("treesitter_lua", .{ .target = target, .optimize = optimize })) |parser| { - test_deps.dependOn(add_ts_parser(b, "lua", parser.path("."), true, target, optimize)); - } - if (b.lazyDependency("treesitter_query", .{ .target = target, .optimize = optimize })) |parser| { - test_deps.dependOn(add_ts_parser(b, "query", parser.path("."), false, target, optimize)); - } + const parser_c = b.dependency("treesitter_c", .{ .target = target, .optimize = optimize }); + test_deps.dependOn(add_ts_parser(b, "c", parser_c.path("."), false, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "c", parser_c.path("."), false, target, optimize, .install)); + + const parser_markdown = b.dependency("treesitter_markdown", .{ .target = target, .optimize = optimize }); + test_deps.dependOn(add_ts_parser(b, "markdown", parser_markdown.path("tree-sitter-markdown/"), true, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "markdown", parser_markdown.path("tree-sitter-markdown/"), true, target, optimize, .install)); + test_deps.dependOn(add_ts_parser(b, "markdown_inline", parser_markdown.path("tree-sitter-markdown-inline/"), true, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "markdown_inline", parser_markdown.path("tree-sitter-markdown-inline/"), true, target, optimize, .install)); + + const parser_vim = b.dependency("treesitter_vim", .{ .target = target, .optimize = optimize }); + test_deps.dependOn(add_ts_parser(b, "vim", parser_vim.path("."), true, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "vim", parser_vim.path("."), true, target, optimize, .install)); + + const parser_vimdoc = b.dependency("treesitter_vimdoc", .{ .target = target, .optimize = optimize }); + test_deps.dependOn(add_ts_parser(b, "vimdoc", parser_vimdoc.path("."), false, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "vimdoc", parser_vimdoc.path("."), false, target, optimize, .install)); + + const parser_lua = b.dependency("treesitter_lua", .{ .target = target, .optimize = optimize }); + test_deps.dependOn(add_ts_parser(b, "lua", parser_lua.path("."), true, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "lua", parser_lua.path("."), true, target, optimize, .install)); + + const parser_query = b.dependency("treesitter_query", .{ .target = target, .optimize = optimize }); + test_deps.dependOn(add_ts_parser(b, "query", parser_query.path("."), false, target, optimize, .test_)); + install.dependOn(add_ts_parser(b, "query", parser_query.path("."), false, target, optimize, .install)); var unit_headers: ?[]const LazyPath = null; if (support_unittests) { @@ -702,6 +708,7 @@ pub fn add_ts_parser( scanner: bool, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, + path: enum { test_, install }, ) *std.Build.Step { const parser = b.addLibrary(.{ .name = name, @@ -716,10 +723,21 @@ pub fn add_ts_parser( parser.addIncludePath(parser_dir.path(b, "src")); parser.linkLibC(); - const parser_install = b.addInstallArtifact(parser, .{ - .dest_sub_path = b.fmt("parser/{s}.so", .{name}), - }); - return &parser_install.step; + switch (path) { + .install => { + const parser_install = b.addInstallArtifact(parser, .{ + .dest_dir = .{ .override = .{ .custom = "share/nvim/runtime/parser" } }, + .dest_sub_path = b.fmt("{s}.so", .{name}), + }); + return &parser_install.step; + }, + .test_ => { + const parser_install = b.addInstallArtifact(parser, .{ + .dest_sub_path = b.fmt("parser/{s}.so", .{name}), + }); + return &parser_install.step; + }, + } } pub fn lua_version_info(b: *std.Build) []u8 { diff --git a/build.zig.zon b/build.zig.zon index 8c3ede40d1..66dbbf37b8 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -48,32 +48,26 @@ .treesitter_c = .{ .url = "git+https://github.com/tree-sitter/tree-sitter-c?ref=v0.24.1#7fa1be1b694b6e763686793d97da01f36a0e5c12", .hash = "N-V-__8AANxPSABzw3WBTSH_YkwaGAfrK6PBqAMqQedkDDim", - .lazy = true, }, .treesitter_markdown = .{ .url = "git+https://github.com/tree-sitter-grammars/tree-sitter-markdown?ref=v0.5.1#2dfd57f547f06ca5631a80f601e129d73fc8e9f0", .hash = "N-V-__8AABcZUwBZelO8MiLRwuLD1Wk34qHHbXtS4UW3Khys", - .lazy = true, }, .treesitter_lua = .{ .url = "git+https://github.com/tree-sitter-grammars/tree-sitter-lua?ref=v0.4.1#816840c592ab973500ae9750763c707b447e7fef", .hash = "N-V-__8AAHCmCAAf-5sa_C1N5Ts8B7V-vTKqUEMJZVnNkq_y", - .lazy = true, }, .treesitter_vim = .{ .url = "git+https://github.com/tree-sitter-grammars/tree-sitter-vim?ref=v0.7.0#3dd4747082d1b717b8978211c06ef7b6cd16125b", .hash = "N-V-__8AAMArVAB4uo2wg2XRs8HBviQ4Pq366cC_iRolX4Vc", - .lazy = true, }, .treesitter_vimdoc = .{ .url = "git+https://github.com/neovim/tree-sitter-vimdoc?ref=v4.1.0#f061895a0eff1d5b90e4fb60d21d87be3267031a", .hash = "N-V-__8AAI7VCgBqRcQ-vIxB8DJJFhmLG42p6rfwCWIdypSJ", - .lazy = true, }, .treesitter_query = .{ .url = "git+https://github.com/tree-sitter-grammars/tree-sitter-query?ref=v0.8.0#a225e21d81201be77da58de614e2b7851735677a", .hash = "N-V-__8AAMR5AwAzZ5_8S2p2COTEf5usBeeT4ORzh-lBGkWy", - .lazy = true, }, }, .paths = .{