From 55c7a189709c84f3bca6159f8342d9c2f5a05d53 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 03:06:50 +0100 Subject: [PATCH 01/18] make the ZLS executable build step depend on the ZLS module The build options are now split between `build_options` and `exe_options`. The latter only used in `main.zig` when creating the final executable. Tracy has also been moved into a separate module. --- build.zig | 219 +++++++++++++++++-------------- src/DocumentScope.zig | 2 +- src/DocumentStore.zig | 2 +- src/Server.zig | 2 +- src/analysis.zig | 2 +- src/configuration.zig | 2 +- src/diff.zig | 2 +- src/features/code_actions.zig | 2 +- src/features/completions.zig | 2 +- src/features/diagnostics.zig | 2 +- src/features/document_symbol.zig | 2 +- src/features/folding_range.zig | 2 +- src/features/goto.zig | 2 +- src/features/hover.zig | 2 +- src/features/inlay_hints.zig | 2 +- src/features/references.zig | 2 +- src/main.zig | 48 ++++--- src/stage2/AstGen.zig | 2 +- src/tracy.zig | 8 +- src/translate_c.zig | 2 +- src/zls.zig | 3 + 21 files changed, 170 insertions(+), 142 deletions(-) diff --git a/build.zig b/build.zig index 6c5a275d5d..cef888d493 100644 --- a/build.zig +++ b/build.zig @@ -38,6 +38,8 @@ pub fn build(b: *Build) !void { const single_threaded = b.option(bool, "single-threaded", "Build a single threaded Executable"); const pie = b.option(bool, "pie", "Build a Position Independent Executable"); const enable_tracy = b.option(bool, "enable_tracy", "Whether tracy should be enabled.") orelse false; + const enable_tracy_allocation = b.option(bool, "enable_tracy_allocation", "Enable using TracyAllocator to monitor allocations.") orelse enable_tracy; + const enable_tracy_callstack = b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse enable_tracy; const coverage = b.option(bool, "generate_coverage", "Generate coverage data with kcov") orelse false; const coverage_output_dir = b.option([]const u8, "coverage_output_dir", "Output directory for coverage data") orelse b.pathJoin(&.{ b.install_prefix, "kcov" }); const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); @@ -46,59 +48,20 @@ pub fn build(b: *Build) !void { const override_version_data_file_path = b.option([]const u8, "version_data_file_path", "Relative path to version data file (if none, will be named with timestamp)"); const use_llvm = b.option(bool, "use_llvm", "Use Zig's llvm code backend"); - const version_string = v: { - const version_string = b.fmt("{d}.{d}.{d}", .{ zls_version.major, zls_version.minor, zls_version.patch }); - const build_root_path = b.build_root.path orelse "."; - - var code: u8 = undefined; - const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{ - "git", "-C", build_root_path, "describe", "--match", "*.*.*", "--tags", - }, &code, .Ignore) catch break :v version_string; - - const git_describe = std.mem.trim(u8, git_describe_untrimmed, " \n\r"); - - switch (std.mem.count(u8, git_describe, "-")) { - 0 => { - // Tagged release version (e.g. 0.10.0). - std.debug.assert(std.mem.eql(u8, git_describe, version_string)); // tagged release must match version string - break :v version_string; - }, - 2 => { - // Untagged development build (e.g. 0.10.0-dev.216+34ce200). - var it = std.mem.splitScalar(u8, git_describe, '-'); - const tagged_ancestor = it.first(); - const commit_height = it.next().?; - const commit_id = it.next().?; - - const ancestor_ver = try std.SemanticVersion.parse(tagged_ancestor); - std.debug.assert(zls_version.order(ancestor_ver) == .gt); // zls version must be greater than its previous version - std.debug.assert(std.mem.startsWith(u8, commit_id, "g")); // commit hash is prefixed with a 'g' - - break :v b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] }); - }, - else => { - std.debug.print("Unexpected 'git describe' output: '{s}'\n", .{git_describe}); - std.process.exit(1); - }, - } - }; + const version_string = getVersion(b); + + const build_options = b.addOptions(); + const build_options_module = build_options.createModule(); + build_options.addOption([]const u8, "version_string", version_string); + build_options.addOption(std.SemanticVersion, "version", try std.SemanticVersion.parse(version_string)); + build_options.addOption([]const u8, "min_zig_string", min_zig_string); const exe_options = b.addOptions(); + const exe_options_module = exe_options.createModule(); exe_options.addOption(std.log.Level, "log_level", b.option(std.log.Level, "log_level", "The Log Level to be used.") orelse .info); - exe_options.addOption(bool, "enable_tracy", enable_tracy); - exe_options.addOption(bool, "enable_tracy_allocation", b.option(bool, "enable_tracy_allocation", "Enable using TracyAllocator to monitor allocations.") orelse enable_tracy); - exe_options.addOption(bool, "enable_tracy_callstack", b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse enable_tracy); exe_options.addOption(bool, "enable_failing_allocator", b.option(bool, "enable_failing_allocator", "Whether to use a randomly failing allocator.") orelse false); exe_options.addOption(u32, "enable_failing_allocator_likelihood", b.option(u32, "enable_failing_allocator_likelihood", "The chance that an allocation will fail is `1/likelihood`") orelse 256); exe_options.addOption(bool, "use_gpa", b.option(bool, "use_gpa", "Good for debugging") orelse (optimize == .Debug)); - exe_options.addOption([]const u8, "version_string", version_string); - exe_options.addOption(std.SemanticVersion, "version", try std.SemanticVersion.parse(version_string)); - exe_options.addOption([]const u8, "min_zig_string", min_zig_string); - - const build_options = b.addOptions(); - const build_options_module = build_options.createModule(); - build_options.addOption([]const u8, "version_string", version_string); - build_options.addOption(std.SemanticVersion, "version", try std.SemanticVersion.parse(version_string)); const global_cache_path = try b.cache_root.join(b.allocator, &.{"zls"}); b.cache_root.handle.makePath(global_cache_path) catch |err| { @@ -110,48 +73,15 @@ pub fn build(b: *Build) !void { test_options.addOption([]const u8, "zig_exe_path", b.graph.zig_exe); test_options.addOption([]const u8, "global_cache_path", global_cache_path); - const exe_options_module = exe_options.createModule(); const known_folders_module = b.dependency("known_folders", .{}).module("known-folders"); const diffz_module = b.dependency("diffz", .{}).module("diffz"); - - const exe = b.addExecutable(.{ - .name = "zls", - .root_source_file = .{ .path = "src/main.zig" }, + const tracy_module = getTracyModule(b, .{ .target = target, .optimize = optimize, - .single_threaded = single_threaded, + .enable = enable_tracy, + .enable_allocation = enable_tracy_allocation, + .enable_callstack = enable_tracy_callstack, }); - exe.use_llvm = use_llvm; - exe.use_lld = use_llvm; - exe.pie = pie; - b.installArtifact(exe); - - exe.root_module.addImport("build_options", exe_options_module); - exe.root_module.addImport("known-folders", known_folders_module); - exe.root_module.addImport("diffz", diffz_module); - - if (enable_tracy) { - const client_cpp = "src/tracy/public/TracyClient.cpp"; - - // On mingw, we need to opt into windows 7+ to get some features required by tracy. - const tracy_c_flags: []const []const u8 = if (target.result.isMinGW()) - &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } - else - &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; - - exe.addIncludePath(.{ .path = "src/tracy" }); - exe.addCSourceFile(.{ - .file = .{ .path = client_cpp }, - .flags = tracy_c_flags, - }); - exe.linkLibCpp(); - exe.linkLibC(); - - if (target.result.os.tag == .windows) { - exe.linkSystemLibrary("dbghelp"); - exe.linkSystemLibrary("ws2_32"); - } - } const gen_exe = b.addExecutable(.{ .name = "zls_gen", @@ -194,45 +124,60 @@ pub fn build(b: *Build) !void { else gen_version_data_cmd.addOutputFileArg(version_data_file_name); const version_data_module = b.addModule("version_data", .{ .root_source_file = version_data_path }); - exe.root_module.addImport("version_data", version_data_module); const zls_module = b.addModule("zls", .{ .root_source_file = .{ .path = "src/zls.zig" }, .imports = &.{ .{ .name = "known-folders", .module = known_folders_module }, .{ .name = "diffz", .module = diffz_module }, + .{ .name = "tracy", .module = tracy_module }, .{ .name = "build_options", .module = build_options_module }, .{ .name = "version_data", .module = version_data_module }, }, }); + const exe = b.addExecutable(.{ + .name = "zls", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + .single_threaded = single_threaded, + .use_llvm = use_llvm, + .use_lld = use_llvm, + }); + exe.pie = pie; + exe.root_module.addImport("exe_options", exe_options_module); + exe.root_module.addImport("tracy", tracy_module); + exe.root_module.addImport("known-folders", known_folders_module); + exe.root_module.addImport("zls", zls_module); + b.installArtifact(exe); + const test_step = b.step("test", "Run all the tests"); test_step.dependOn(b.getInstallStep()); - var tests = b.addTest(.{ + const tests = b.addTest(.{ .root_source_file = .{ .path = "tests/tests.zig" }, .target = target, .optimize = optimize, .filter = test_filter, .single_threaded = single_threaded, + .use_llvm = use_llvm, + .use_lld = use_llvm, }); - tests.use_llvm = use_llvm; - tests.use_lld = use_llvm; tests.root_module.addImport("zls", zls_module); - tests.root_module.addImport("build_options", build_options_module); tests.root_module.addImport("test_options", test_options_module); test_step.dependOn(&b.addRunArtifact(tests).step); - var src_tests = b.addTest(.{ + const src_tests = b.addTest(.{ .root_source_file = .{ .path = "src/zls.zig" }, .target = target, .optimize = optimize, .filter = test_filter, .single_threaded = single_threaded, + .use_llvm = use_llvm, + .use_lld = use_llvm, }); - src_tests.use_llvm = use_llvm; - src_tests.use_lld = use_llvm; src_tests.root_module.addImport("build_options", build_options_module); src_tests.root_module.addImport("test_options", test_options_module); test_step.dependOn(&b.addRunArtifact(src_tests).step); @@ -248,15 +193,15 @@ pub fn build(b: *Build) !void { .{ .bytes = b.dupe(coverage_output_dir) }, }; - var tests_run = b.addRunArtifact(tests); - var src_tests_run = b.addRunArtifact(src_tests); + const tests_run = b.addRunArtifact(tests); + const src_tests_run = b.addRunArtifact(src_tests); tests_run.has_side_effects = true; src_tests_run.has_side_effects = true; tests_run.argv.insertSlice(0, args) catch @panic("OOM"); src_tests_run.argv.insertSlice(0, args) catch @panic("OOM"); - var merge_step = std.Build.Step.Run.create(b, "merge kcov"); + const merge_step = std.Build.Step.Run.create(b, "merge kcov"); merge_step.has_side_effects = true; merge_step.addArgs(&.{ "kcov", @@ -270,3 +215,87 @@ pub fn build(b: *Build) !void { test_step.dependOn(&merge_step.step); } } + +fn getVersion(b: *Build) []const u8 { + const version_string = b.fmt("{d}.{d}.{d}", .{ zls_version.major, zls_version.minor, zls_version.patch }); + const build_root_path = b.build_root.path orelse "."; + + var code: u8 = undefined; + const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{ + "git", "-C", build_root_path, "describe", "--match", "*.*.*", "--tags", + }, &code, .Ignore) catch return version_string; + + const git_describe = std.mem.trim(u8, git_describe_untrimmed, " \n\r"); + + switch (std.mem.count(u8, git_describe, "-")) { + 0 => { + // Tagged release version (e.g. 0.10.0). + std.debug.assert(std.mem.eql(u8, git_describe, version_string)); // tagged release must match version string + return version_string; + }, + 2 => { + // Untagged development build (e.g. 0.10.0-dev.216+34ce200). + var it = std.mem.splitScalar(u8, git_describe, '-'); + const tagged_ancestor = it.first(); + const commit_height = it.next().?; + const commit_id = it.next().?; + + const ancestor_ver = std.SemanticVersion.parse(tagged_ancestor) catch unreachable; + std.debug.assert(zls_version.order(ancestor_ver) == .gt); // zls version must be greater than its previous version + std.debug.assert(std.mem.startsWith(u8, commit_id, "g")); // commit hash is prefixed with a 'g' + + return b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] }); + }, + else => { + std.debug.print("Unexpected 'git describe' output: '{s}'\n", .{git_describe}); + std.process.exit(1); + }, + } +} + +fn getTracyModule( + b: *Build, + options: struct { + target: Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + enable: bool, + enable_allocation: bool, + enable_callstack: bool, + }, +) *Build.Module { + const tracy_options = b.addOptions(); + tracy_options.addOption(bool, "enable", options.enable); + tracy_options.addOption(bool, "enable_allocation", options.enable and options.enable_allocation); + tracy_options.addOption(bool, "enable_callstack", options.enable and options.enable_callstack); + + const tracy_module = b.addModule("tracy", .{ + .root_source_file = .{ .path = "src/tracy.zig" }, + .target = options.target, + .optimize = options.optimize, + }); + tracy_module.addImport("options", tracy_options.createModule()); + if (!options.enable) return tracy_module; + tracy_module.link_libc = true; + tracy_module.link_libcpp = true; + + const client_cpp = "src/tracy/public/TracyClient.cpp"; + + // On mingw, we need to opt into windows 7+ to get some features required by tracy. + const tracy_c_flags: []const []const u8 = if (options.target.result.isMinGW()) + &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } + else + &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; + + tracy_module.addIncludePath(.{ .path = "src/tracy" }); + tracy_module.addCSourceFile(.{ + .file = .{ .path = client_cpp }, + .flags = tracy_c_flags, + }); + + if (options.target.result.os.tag == .windows) { + tracy_module.linkSystemLibrary("dbghelp", .{}); + tracy_module.linkSystemLibrary("ws2_32", .{}); + } + + return tracy_module; +} diff --git a/src/DocumentScope.zig b/src/DocumentScope.zig index 42e7e85a54..23f9b2cc0e 100644 --- a/src/DocumentScope.zig +++ b/src/DocumentScope.zig @@ -1,7 +1,7 @@ const std = @import("std"); const ast = @import("ast.zig"); const Ast = std.zig.Ast; -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const offsets = @import("offsets.zig"); const Analyser = @import("analysis.zig"); const Declaration = Analyser.Declaration; diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index fbff1a339f..deb6e53a5f 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -7,7 +7,7 @@ const log = std.log.scoped(.zls_store); const Ast = std.zig.Ast; const BuildAssociatedConfig = @import("BuildAssociatedConfig.zig"); const BuildConfig = @import("build_runner/BuildConfig.zig"); -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const Config = @import("Config.zig"); const ZigVersionWrapper = @import("ZigVersionWrapper.zig"); const translate_c = @import("translate_c.zig"); diff --git a/src/Server.zig b/src/Server.zig index 7d8def25ed..ae2b9ad0dd 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -11,7 +11,7 @@ const Analyser = @import("analysis.zig"); const ast = @import("ast.zig"); const offsets = @import("offsets.zig"); const Ast = std.zig.Ast; -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const diff = @import("diff.zig"); const ComptimeInterpreter = @import("ComptimeInterpreter.zig"); const InternPool = @import("analyser/analyser.zig").InternPool; diff --git a/src/analysis.zig b/src/analysis.zig index b64f52c8e4..912090a568 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -5,7 +5,7 @@ const offsets = @import("offsets.zig"); const URI = @import("uri.zig"); const log = std.log.scoped(.zls_analysis); const ast = @import("ast.zig"); -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const ComptimeInterpreter = @import("ComptimeInterpreter.zig"); const InternPool = ComptimeInterpreter.InternPool; const references = @import("features/references.zig"); diff --git a/src/configuration.zig b/src/configuration.zig index e83e10a893..ed651ce226 100644 --- a/src/configuration.zig +++ b/src/configuration.zig @@ -2,7 +2,7 @@ const std = @import("std"); const builtin = @import("builtin"); const ZigVersionWrapper = @import("ZigVersionWrapper.zig"); -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const known_folders = @import("known-folders"); const Config = @import("Config.zig"); diff --git a/src/diff.zig b/src/diff.zig index cbc8952879..7b3a095a4f 100644 --- a/src/diff.zig +++ b/src/diff.zig @@ -1,7 +1,7 @@ const std = @import("std"); const types = @import("lsp.zig"); const offsets = @import("offsets.zig"); -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const DiffMatchPatch = @import("diffz"); const dmp = DiffMatchPatch{ diff --git a/src/features/code_actions.zig b/src/features/code_actions.zig index 74723ec7e6..9b44b51b5b 100644 --- a/src/features/code_actions.zig +++ b/src/features/code_actions.zig @@ -6,7 +6,7 @@ const Analyser = @import("../analysis.zig"); const ast = @import("../ast.zig"); const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); pub const Builder = struct { arena: std.mem.Allocator, diff --git a/src/features/completions.zig b/src/features/completions.zig index 56e07b5d8f..c51357fa19 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -9,7 +9,7 @@ const types = @import("../lsp.zig"); const Analyser = @import("../analysis.zig"); const ast = @import("../ast.zig"); const offsets = @import("../offsets.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const URI = @import("../uri.zig"); const DocumentScope = @import("../DocumentScope.zig"); const analyser_completions = @import("../analyser/completions.zig"); diff --git a/src/features/diagnostics.zig b/src/features/diagnostics.zig index 34ff301dc3..2612f917b5 100644 --- a/src/features/diagnostics.zig +++ b/src/features/diagnostics.zig @@ -12,7 +12,7 @@ const ast = @import("../ast.zig"); const offsets = @import("../offsets.zig"); const URI = @import("../uri.zig"); const code_actions = @import("code_actions.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const Module = @import("../stage2/Module.zig"); const Zir = @import("../stage2/Zir.zig"); diff --git a/src/features/document_symbol.zig b/src/features/document_symbol.zig index 35a50f0c27..2e1d9bf9af 100644 --- a/src/features/document_symbol.zig +++ b/src/features/document_symbol.zig @@ -6,7 +6,7 @@ const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); const ast = @import("../ast.zig"); const analysis = @import("../analysis.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const Symbol = struct { name: []const u8, diff --git a/src/features/folding_range.zig b/src/features/folding_range.zig index cd02606a69..655aa4b8c8 100644 --- a/src/features/folding_range.zig +++ b/src/features/folding_range.zig @@ -4,7 +4,7 @@ const Ast = std.zig.Ast; const ast = @import("../ast.zig"); const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const FoldingRange = struct { loc: offsets.Loc, diff --git a/src/features/goto.zig b/src/features/goto.zig index 23d7134eb4..9849618055 100644 --- a/src/features/goto.zig +++ b/src/features/goto.zig @@ -7,7 +7,7 @@ const ast = @import("../ast.zig"); const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); const URI = @import("../uri.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const Analyser = @import("../analysis.zig"); const DocumentStore = @import("../DocumentStore.zig"); diff --git a/src/features/hover.zig b/src/features/hover.zig index 587e2ebf00..1f38d09c6e 100644 --- a/src/features/hover.zig +++ b/src/features/hover.zig @@ -6,7 +6,7 @@ const ast = @import("../ast.zig"); const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); const URI = @import("../uri.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const Analyser = @import("../analysis.zig"); const DocumentStore = @import("../DocumentStore.zig"); diff --git a/src/features/inlay_hints.zig b/src/features/inlay_hints.zig index efba03a96e..c6e27b1b21 100644 --- a/src/features/inlay_hints.zig +++ b/src/features/inlay_hints.zig @@ -7,7 +7,7 @@ const DocumentStore = @import("../DocumentStore.zig"); const Analyser = @import("../analysis.zig"); const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); const ast = @import("../ast.zig"); const Config = @import("../Config.zig"); diff --git a/src/features/references.zig b/src/features/references.zig index c167731725..2b10cef664 100644 --- a/src/features/references.zig +++ b/src/features/references.zig @@ -8,7 +8,7 @@ const Analyser = @import("../analysis.zig"); const types = @import("../lsp.zig"); const offsets = @import("../offsets.zig"); const ast = @import("../ast.zig"); -const tracy = @import("../tracy.zig"); +const tracy = @import("tracy"); fn labelReferences( allocator: std.mem.Allocator, diff --git a/src/main.zig b/src/main.zig index 7702bec35c..fbba797388 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,21 +1,17 @@ const std = @import("std"); const zig_builtin = @import("builtin"); -const build_options = @import("build_options"); -const tracy = @import("tracy.zig"); +const zls = @import("zls"); +const exe_options = @import("exe_options"); + +const tracy = @import("tracy"); const known_folders = @import("known-folders"); -const Config = @import("Config.zig"); -const configuration = @import("configuration.zig"); -const Server = @import("Server.zig"); -const Header = @import("Header.zig"); -const Transport = @import("Transport.zig"); -const debug = @import("debug.zig"); const binned_allocator = @import("binned_allocator.zig"); const logger = std.log.scoped(.zls_main); var actual_log_level: std.log.Level = switch (zig_builtin.mode) { .Debug => .debug, - else => @enumFromInt(@intFromEnum(build_options.log_level)), // temporary fix to build failing on release-safe due to a Zig bug + else => @enumFromInt(@intFromEnum(exe_options.log_level)), // temporary fix to build failing on release-safe due to a Zig bug }; fn logFn( @@ -45,7 +41,7 @@ pub const std_options = std.Options{ .logFn = logFn, }; -fn getRecordFile(config: Config) ?std.fs.File { +fn getRecordFile(config: zls.Config) ?std.fs.File { if (!config.record_session) return null; if (config.record_session_path) |record_path| { @@ -62,7 +58,7 @@ fn getRecordFile(config: Config) ?std.fs.File { } } -fn getReplayFile(config: Config) ?std.fs.File { +fn getReplayFile(config: zls.Config) ?std.fs.File { const replay_path = config.replay_session_path orelse config.record_session_path orelse return null; if (std.fs.openFileAbsolute(replay_path, .{})) |file| { @@ -78,8 +74,8 @@ fn getReplayFile(config: Config) ?std.fs.File { /// when replaying we read this message and replace the current config fn updateConfig( allocator: std.mem.Allocator, - transport: *Transport, - config: *configuration.ConfigWithPath, + transport: *zls.Transport, + config: *zls.configuration.ConfigWithPath, record_file: ?std.fs.File, replay_file: ?std.fs.File, ) !void { @@ -94,7 +90,7 @@ fn updateConfig( defer buffer.deinit(allocator); try std.json.stringify(cfg, .{}, buffer.writer(allocator)); - var header = Header{ .content_length = buffer.items.len }; + var header = zls.Header{ .content_length = buffer.items.len }; try header.write(file.writer()); try file.writeAll(buffer.items); } @@ -104,7 +100,7 @@ fn updateConfig( defer allocator.free(json_message); const new_config = try std.json.parseFromSlice( - Config, + zls.Config, allocator, json_message, .{ .allocate = .alloc_always }, @@ -232,11 +228,11 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult { return result; } if (specified.get(.version)) { - try stdout.writeAll(build_options.version_string ++ "\n"); + try stdout.writeAll(zls.build_options.version_string ++ "\n"); return result; } if (specified.get(.@"minimum-build-version")) { - try stdout.writeAll(build_options.min_zig_string ++ "\n"); + try stdout.writeAll(zls.build_options.min_zig_string ++ "\n"); return result; } if (specified.get(.@"compiler-version")) { @@ -255,7 +251,7 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult { std.debug.assert(result.config_path != null); } if (specified.get(.@"show-config-path")) { - var new_config = try configuration.getConfig(allocator, result.config_path); + var new_config = try zls.configuration.getConfig(allocator, result.config_path); defer new_config.deinit(allocator); if (new_config.config_path) |path| { @@ -286,13 +282,13 @@ const stack_frames = switch (zig_builtin.mode) { }; pub fn main() !void { - var allocator_state = if (build_options.use_gpa) + var allocator_state = if (exe_options.use_gpa) std.heap.GeneralPurposeAllocator(.{ .stack_trace_frames = stack_frames }){} else binned_allocator.BinnedAllocator(.{}){}; defer { - if (build_options.use_gpa) + if (exe_options.use_gpa) std.debug.assert(allocator_state.deinit() == .ok) else allocator_state.deinit(); @@ -301,8 +297,8 @@ pub fn main() !void { var tracy_state = if (tracy.enable_allocation) tracy.tracyAllocator(allocator_state.allocator()) else void{}; const inner_allocator: std.mem.Allocator = if (tracy.enable_allocation) tracy_state.allocator() else allocator_state.allocator(); - var failing_allocator_state = if (build_options.enable_failing_allocator) debug.FailingAllocator.init(inner_allocator, build_options.enable_failing_allocator_likelihood) else void{}; - const allocator: std.mem.Allocator = if (build_options.enable_failing_allocator) failing_allocator_state.allocator() else inner_allocator; + var failing_allocator_state = if (exe_options.enable_failing_allocator) zls.debug.FailingAllocator.init(inner_allocator, exe_options.enable_failing_allocator_likelihood) else void{}; + const allocator: std.mem.Allocator = if (exe_options.enable_failing_allocator) failing_allocator_state.allocator() else inner_allocator; const result = try parseArgs(allocator); defer allocator.free(result.zls_exe_path); @@ -312,9 +308,9 @@ pub fn main() !void { .exit => return, } - logger.info("Starting ZLS {s} @ '{s}'", .{ build_options.version_string, result.zls_exe_path }); + logger.info("Starting ZLS {s} @ '{s}'", .{ zls.build_options.version_string, result.zls_exe_path }); - var config = try configuration.getConfig(allocator, result.config_path); + var config = try zls.configuration.getConfig(allocator, result.config_path); defer config.deinit(allocator); if (result.replay_enabled and config.config.record_session_path == null) { @@ -332,7 +328,7 @@ pub fn main() !void { const replay_file = if (result.replay_enabled) getReplayFile(config.config) else null; defer if (replay_file) |file| file.close(); - var transport = Transport.init( + var transport = zls.Transport.init( if (replay_file) |file| file.reader() else std.io.getStdIn().reader(), std.io.getStdOut().writer(), ); @@ -341,7 +337,7 @@ pub fn main() !void { try updateConfig(allocator, &transport, &config, record_file, replay_file); - const server = try Server.create(allocator); + const server = try zls.Server.create(allocator); defer server.destroy(); try server.updateConfiguration2(config.config); server.recording_enabled = record_file != null; diff --git a/src/stage2/AstGen.zig b/src/stage2/AstGen.zig index 908358892a..850b81c5db 100644 --- a/src/stage2/AstGen.zig +++ b/src/stage2/AstGen.zig @@ -22,7 +22,7 @@ const isPrimitive = std.zig.primitives.isPrimitive; const Zir = @import("Zir.zig"); const refToIndex = Zir.refToIndex; const indexToRef = Zir.indexToRef; -const trace = @import("../tracy.zig").trace; +const trace = @import("tracy").trace; const BuiltinFn = @import("BuiltinFn.zig"); const AstRlAnnotate = @import("AstRlAnnotate.zig"); diff --git a/src/tracy.zig b/src/tracy.zig index ec9a7f3764..d7afd74775 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -25,11 +25,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const build_options = @import("build_options"); +const options = @import("options"); -pub const enable = if (builtin.is_test) false else build_options.enable_tracy; -pub const enable_allocation = enable and build_options.enable_tracy_allocation; -pub const enable_callstack = enable and build_options.enable_tracy_callstack; +pub const enable = if (builtin.is_test) false else options.enable; +pub const enable_allocation = enable and options.enable_allocation; +pub const enable_callstack = enable and options.enable_callstack; // TODO: make this configurable const callstack_depth = 10; diff --git a/src/translate_c.zig b/src/translate_c.zig index f4d658e83f..f6f7b12569 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -3,7 +3,7 @@ const zig_builtin = @import("builtin"); const builtin = @import("builtin"); const Config = @import("Config.zig"); const ast = @import("ast.zig"); -const tracy = @import("tracy.zig"); +const tracy = @import("tracy"); const Ast = std.zig.Ast; const URI = @import("uri.zig"); const ZCS = @import("ZigCompileServer.zig"); diff --git a/src/zls.zig b/src/zls.zig index 5c6e47f156..d07362ca3f 100644 --- a/src/zls.zig +++ b/src/zls.zig @@ -1,6 +1,8 @@ //! Used by tests as a package, can be used by tools such as //! zigbot9001 to take advantage of zls' tools +pub const build_options = @import("build_options"); + pub const ast = @import("ast.zig"); pub const Analyser = @import("analysis.zig"); pub const Header = @import("Header.zig"); @@ -9,6 +11,7 @@ pub const offsets = @import("offsets.zig"); pub const Config = @import("Config.zig"); pub const Server = @import("Server.zig"); pub const translate_c = @import("translate_c.zig"); +pub const Transport = @import("Transport.zig"); pub const types = @import("lsp.zig"); pub const URI = @import("uri.zig"); pub const DocumentStore = @import("DocumentStore.zig"); From 4218a4a6eac71e58036881736f8b522dfe1458f6 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 03:12:20 +0100 Subject: [PATCH 02/18] CI: update code checkout step `fetch-depth: 0` means that that all history for all branches and tags should be fetch which is completely unnecessary. --- .github/workflows/build_runner.yml | 6 +- .github/workflows/coverage.yml | 8 +- .github/workflows/fuzz.yml | 15 +- .github/workflows/main.yml | 305 ++++++++++++++--------------- 4 files changed, 160 insertions(+), 174 deletions(-) diff --git a/.github/workflows/build_runner.yml b/.github/workflows/build_runner.yml index 386e570401..2c989c1244 100644 --- a/.github/workflows/build_runner.yml +++ b/.github/workflows/build_runner.yml @@ -10,7 +10,7 @@ on: - ".github/workflows/build_runner.yml" - "src/build_runner/**" schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" workflow_dispatch: jobs: @@ -27,9 +27,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 + uses: actions/checkout@v4 - name: Grab zig uses: goto-bus-stop/setup-zig@v2 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 08b68e85f8..3c1b50b2a3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -6,10 +6,7 @@ jobs: coverage: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: true + - uses: actions/checkout@v4 - uses: goto-bus-stop/setup-zig@v2 with: @@ -30,7 +27,7 @@ jobs: run: | kcov --version zig build test -Dgenerate_coverage - + - name: Upload to Codecov uses: codecov/codecov-action@v3 with: @@ -38,4 +35,3 @@ jobs: directory: zig-out/kcov/kcov-merged fail_ci_if_error: true verbose: true - diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 165ef1b34f..7dcf61180c 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -55,25 +55,22 @@ jobs: - run: zig env - name: Checkout zig - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: zig repository: "ziglang/zig" - fetch-depth: 0 - name: Checkout zls (non-PR) if: github.event_name != 'pull_request_target' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: zls - fetch-depth: 0 - name: Checkout zls (PR) if: github.event_name == 'pull_request_target' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: zls - fetch-depth: 0 ref: "refs/pull/${{ github.event.number }}/merge" - name: Build zls @@ -83,11 +80,10 @@ jobs: zig build - name: Checkout sus - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: sus repository: "zigtools/sus" - fetch-depth: 0 - name: Build sus run: | @@ -117,6 +113,3 @@ jobs: space_region: nyc3 source: sus/saved_logs/ out_dir: ${{ github.event.pull_request.head.repo.full_name || github.repository }}/${{ github.head_ref || github.ref_name }}/${{ github.event.pull_request.head.sha || github.sha }} - - - \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70db94c965..c57a739d83 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,153 +1,152 @@ -name: CI - -on: - push: - paths: - - ".github/workflows/main.yml" - - "**.zig" - - "build.zig.zon" - pull_request: - paths: - - ".github/workflows/main.yml" - - "**.zig" - - "build.zig.zon" - schedule: - - cron: "0 0 * * *" - workflow_dispatch: - -jobs: - build: - if: github.repository_owner == 'zigtools' - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: goto-bus-stop/setup-zig@v2 - with: - version: master - - - name: Get Zig version - id: zig_version - run: echo "zig_version=$(zig version)" >> $GITHUB_OUTPUT - - - run: zig env - - - name: Run zig fmt - run: zig fmt --check . - - - name: Build - run: zig build - - - name: Get ZLS version and mimimum build version - id: zls_version - run: | - echo "zls_version=$(./zig-out/bin/zls --version)" >> $GITHUB_OUTPUT - echo "zls_minimum_build_version=$(./zig-out/bin/zls --minimum-build-version)" >> $GITHUB_OUTPUT - - - name: Run Tests - run: zig build test - - - name: Build artifacts - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - declare -a targets=("x86_64-windows" "x86_64-linux" "x86_64-macos" "x86-windows" "x86-linux" "aarch64-linux" "aarch64-macos" "wasm32-wasi") - mkdir -p "artifacts/${{ steps.zls_version.outputs.zls_version }}/" - - for target in "${targets[@]}"; do - mkdir -p artifacts/${{ steps.zls_version.outputs.zls_version }}/$target - - echo "Building target ${target}..." - if [ "${GITHUB_REF##*/}" == "master" ]; then - echo "Building safe" - zig build -Dtarget=${target} -Dcpu=baseline -Doptimize=ReleaseSafe --prefix artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/ - else - echo "Building debug as action is not running on master" - zig build -Dtarget=${target} -Dcpu=baseline --prefix artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/ - fi - - mv artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/bin/* artifacts/${{ steps.zls_version.outputs.zls_version }}/${target} - rmdir artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/bin - done - - wget https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json - - cp index.json artifacts/old-index.json - - jq --arg targets "${targets[*]}" '.latest = "${{ steps.zls_version.outputs.zls_version }}" | .versions["${{ steps.zls_version.outputs.zls_version }}"] = { - "date": now | todateiso8601, - "builtWithZigVersion": "${{ steps.zig_version.outputs.zig_version }}", - "zlsVersion": "${{ steps.zls_version.outputs.zls_version }}", - "zlsMinimumBuildVersion": "${{ steps.zls_version.outputs.zls_minimum_build_version }}", - "commit": "${{ github.sha }}", - "targets": ($targets / " "), - }' index.json > artifacts/index.json - - - name: Upload x86_64-windows artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86_64-windows - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-windows/ - - - name: Upload x86_64-linux artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86_64-linux - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-linux/ - - - name: Upload x86_64-macos artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86_64-macos - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-macos/ - - - name: Upload x86-windows artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86-windows - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86-windows/ - - - name: Upload x86-linux artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86-linux - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86-linux/ - - - name: Upload aarch64-linux artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-aarch64-linux - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/aarch64-linux/ - - - name: Upload aarch64-macos artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-aarch64-macos - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/aarch64-macos/ - - - name: Upload wasm32-wasi artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-wasm32-wasi - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/wasm32-wasi/ - - - uses: BetaHuhn/do-spaces-action@v2 - if: ${{ matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/master' }} - with: - access_key: ${{ secrets.DO_SPACES_ACCESS_KEY }} - secret_key: ${{ secrets.DO_SPACES_SECRET_KEY }} - space_name: zigtools-releases - space_region: nyc3 - source: artifacts/ - out_dir: zls/ +name: CI + +on: + push: + paths: + - ".github/workflows/main.yml" + - "**.zig" + - "build.zig.zon" + pull_request: + paths: + - ".github/workflows/main.yml" + - "**.zig" + - "build.zig.zon" + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + build: + if: github.repository_owner == 'zigtools' + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - uses: goto-bus-stop/setup-zig@v2 + with: + version: master + + - name: Get Zig version + id: zig_version + run: echo "zig_version=$(zig version)" >> $GITHUB_OUTPUT + + - run: zig env + + - name: Run zig fmt + run: zig fmt --check . + + - name: Build + run: zig build + + - name: Get ZLS version and mimimum build version + id: zls_version + run: | + echo "zls_version=$(./zig-out/bin/zls --version)" >> $GITHUB_OUTPUT + echo "zls_minimum_build_version=$(./zig-out/bin/zls --minimum-build-version)" >> $GITHUB_OUTPUT + + - name: Run Tests + run: zig build test + + - name: Build artifacts + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + declare -a targets=("x86_64-windows" "x86_64-linux" "x86_64-macos" "x86-windows" "x86-linux" "aarch64-linux" "aarch64-macos" "wasm32-wasi") + mkdir -p "artifacts/${{ steps.zls_version.outputs.zls_version }}/" + + for target in "${targets[@]}"; do + mkdir -p artifacts/${{ steps.zls_version.outputs.zls_version }}/$target + + echo "Building target ${target}..." + if [ "${GITHUB_REF##*/}" == "master" ]; then + echo "Building safe" + zig build -Dtarget=${target} -Dcpu=baseline -Doptimize=ReleaseSafe --prefix artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/ + else + echo "Building debug as action is not running on master" + zig build -Dtarget=${target} -Dcpu=baseline --prefix artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/ + fi + + mv artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/bin/* artifacts/${{ steps.zls_version.outputs.zls_version }}/${target} + rmdir artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/bin + done + + wget https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json + + cp index.json artifacts/old-index.json + + jq --arg targets "${targets[*]}" '.latest = "${{ steps.zls_version.outputs.zls_version }}" | .versions["${{ steps.zls_version.outputs.zls_version }}"] = { + "date": now | todateiso8601, + "builtWithZigVersion": "${{ steps.zig_version.outputs.zig_version }}", + "zlsVersion": "${{ steps.zls_version.outputs.zls_version }}", + "zlsMinimumBuildVersion": "${{ steps.zls_version.outputs.zls_minimum_build_version }}", + "commit": "${{ github.sha }}", + "targets": ($targets / " "), + }' index.json > artifacts/index.json + + - name: Upload x86_64-windows artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-x86_64-windows + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-windows/ + + - name: Upload x86_64-linux artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-x86_64-linux + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-linux/ + + - name: Upload x86_64-macos artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-x86_64-macos + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-macos/ + + - name: Upload x86-windows artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-x86-windows + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86-windows/ + + - name: Upload x86-linux artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-x86-linux + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86-linux/ + + - name: Upload aarch64-linux artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-aarch64-linux + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/aarch64-linux/ + + - name: Upload aarch64-macos artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-aarch64-macos + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/aarch64-macos/ + + - name: Upload wasm32-wasi artifact + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v3 + with: + name: zls-wasm32-wasi + path: artifacts/${{ steps.zls_version.outputs.zls_version }}/wasm32-wasi/ + + - uses: BetaHuhn/do-spaces-action@v2 + if: ${{ matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/master' }} + with: + access_key: ${{ secrets.DO_SPACES_ACCESS_KEY }} + secret_key: ${{ secrets.DO_SPACES_SECRET_KEY }} + space_name: zigtools-releases + space_region: nyc3 + source: artifacts/ + out_dir: zls/ From 86c3b2de1bcb49fb5427d438ac7fd039ce817440 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 04:28:31 +0100 Subject: [PATCH 03/18] CI: do not terminate all steps on failure --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c57a739d83..4843266a98 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,7 @@ jobs: build: if: github.repository_owner == 'zigtools' strategy: + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} From 59e1f1f3aab0c46abebe25867ab685d5b0b0643c Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 04:29:39 +0100 Subject: [PATCH 04/18] CI: remove unnecessary zig build steps zig build test depends on the install step --- .github/workflows/coverage.yml | 4 ---- .github/workflows/main.yml | 3 --- 2 files changed, 7 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3c1b50b2a3..9aa10d7c9c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -12,12 +12,8 @@ jobs: with: version: master - - run: zig version - run: zig env - - name: Build - run: zig build - - name: Install kcov run: | wget https://github.com/SimonKagstrom/kcov/releases/download/v42/kcov-amd64.tar.gz diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4843266a98..1db67c486f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,9 +39,6 @@ jobs: - name: Run zig fmt run: zig fmt --check . - - name: Build - run: zig build - - name: Get ZLS version and mimimum build version id: zls_version run: | From b654d89b1af8cade68a9ce4202f3b9065be17253 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 04:31:43 +0100 Subject: [PATCH 05/18] CI: remove release artifact upload to GitHub Releases can be extracted from `https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json` --- .github/workflows/main.yml | 56 -------------------------------------- 1 file changed, 56 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1db67c486f..7e3e5702ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -83,62 +83,6 @@ jobs: "targets": ($targets / " "), }' index.json > artifacts/index.json - - name: Upload x86_64-windows artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86_64-windows - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-windows/ - - - name: Upload x86_64-linux artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86_64-linux - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-linux/ - - - name: Upload x86_64-macos artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86_64-macos - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86_64-macos/ - - - name: Upload x86-windows artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86-windows - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86-windows/ - - - name: Upload x86-linux artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-x86-linux - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/x86-linux/ - - - name: Upload aarch64-linux artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-aarch64-linux - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/aarch64-linux/ - - - name: Upload aarch64-macos artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-aarch64-macos - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/aarch64-macos/ - - - name: Upload wasm32-wasi artifact - if: ${{ matrix.os == 'ubuntu-latest' }} - uses: actions/upload-artifact@v3 - with: - name: zls-wasm32-wasi - path: artifacts/${{ steps.zls_version.outputs.zls_version }}/wasm32-wasi/ - - uses: BetaHuhn/do-spaces-action@v2 if: ${{ matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/master' }} with: From e0d04b7e998b7f89623b1a5779c857255a4c31a3 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sun, 11 Feb 2024 05:05:15 +0100 Subject: [PATCH 06/18] CI: build release artifacts with Zig build system in new GitHub Action This means that artifacts will be build in parallel. It is also possible to move more of the CI script into the Zig build system but this should be a good starting point. --- .github/workflows/artifacts.yml | 60 ++++++++++++++++++++++++++++++ .github/workflows/main.yml | 65 +-------------------------------- build.zig | 39 ++++++++++++++++++++ 3 files changed, 100 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/artifacts.yml diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml new file mode 100644 index 0000000000..65bb30c820 --- /dev/null +++ b/.github/workflows/artifacts.yml @@ -0,0 +1,60 @@ +name: Deploy release artifacts + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + deploy: + if: github.repository_owner == 'zigtools' + runs-on: ubuntu-latest + needs: [build, check_build_runner] + steps: + - uses: actions/checkout@v4 + + - uses: goto-bus-stop/setup-zig@v2 + with: + version: master + + - run: zig env + + - name: Build artifacts + run: | + zig build release -Dcpu=baseline -Doptimize=ReleaseSafe --summary all + + zls_version=$(zig-out/x86_64-linux/zls --version) + mkdir -p "artifacts/$zls_version/" + cp -r zig-out/* "artifacts/$zls_version/" + + wget https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json + + cp index.json artifacts/old-index.json + + for file in zig-out/*; do + targets+=("${file#zig-out/}") + done + + jq \ + --arg targets "${targets[*]}" \ + --arg zig_version "$(zig version)" \ + --arg zls_version "$(zig-out/x86_64-linux/zls --version)" \ + --arg zls_minimum_build_version "$(zig-out/x86_64-linux/zls --minimum-build-version)" \ + '.latest = $zls_version | .versions[$zls_version] = { + "date": now | todateiso8601, + "builtWithZigVersion": $zig_version, + "zlsVersion": $zls_version, + "zlsMinimumBuildVersion": $zls_minimum_build_version, + "commit": "${{ github.sha }}", + "targets": ($targets / " "), + }' index.json > artifacts/index.json + + - uses: BetaHuhn/do-spaces-action@v2 + with: + access_key: ${{ secrets.DO_SPACES_ACCESS_KEY }} + secret_key: ${{ secrets.DO_SPACES_SECRET_KEY }} + space_name: zigtools-releases + space_region: nyc3 + source: artifacts/ + out_dir: zls/ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e3e5702ec..20b4842c12 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,16 +1,8 @@ name: CI on: - push: - paths: - - ".github/workflows/main.yml" - - "**.zig" - - "build.zig.zon" pull_request: - paths: - - ".github/workflows/main.yml" - - "**.zig" - - "build.zig.zon" + push: schedule: - cron: "0 0 * * *" workflow_dispatch: @@ -30,65 +22,10 @@ jobs: with: version: master - - name: Get Zig version - id: zig_version - run: echo "zig_version=$(zig version)" >> $GITHUB_OUTPUT - - run: zig env - name: Run zig fmt run: zig fmt --check . - - name: Get ZLS version and mimimum build version - id: zls_version - run: | - echo "zls_version=$(./zig-out/bin/zls --version)" >> $GITHUB_OUTPUT - echo "zls_minimum_build_version=$(./zig-out/bin/zls --minimum-build-version)" >> $GITHUB_OUTPUT - - name: Run Tests run: zig build test - - - name: Build artifacts - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - declare -a targets=("x86_64-windows" "x86_64-linux" "x86_64-macos" "x86-windows" "x86-linux" "aarch64-linux" "aarch64-macos" "wasm32-wasi") - mkdir -p "artifacts/${{ steps.zls_version.outputs.zls_version }}/" - - for target in "${targets[@]}"; do - mkdir -p artifacts/${{ steps.zls_version.outputs.zls_version }}/$target - - echo "Building target ${target}..." - if [ "${GITHUB_REF##*/}" == "master" ]; then - echo "Building safe" - zig build -Dtarget=${target} -Dcpu=baseline -Doptimize=ReleaseSafe --prefix artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/ - else - echo "Building debug as action is not running on master" - zig build -Dtarget=${target} -Dcpu=baseline --prefix artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/ - fi - - mv artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/bin/* artifacts/${{ steps.zls_version.outputs.zls_version }}/${target} - rmdir artifacts/${{ steps.zls_version.outputs.zls_version }}/${target}/bin - done - - wget https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json - - cp index.json artifacts/old-index.json - - jq --arg targets "${targets[*]}" '.latest = "${{ steps.zls_version.outputs.zls_version }}" | .versions["${{ steps.zls_version.outputs.zls_version }}"] = { - "date": now | todateiso8601, - "builtWithZigVersion": "${{ steps.zig_version.outputs.zig_version }}", - "zlsVersion": "${{ steps.zls_version.outputs.zls_version }}", - "zlsMinimumBuildVersion": "${{ steps.zls_version.outputs.zls_minimum_build_version }}", - "commit": "${{ github.sha }}", - "targets": ($targets / " "), - }' index.json > artifacts/index.json - - - uses: BetaHuhn/do-spaces-action@v2 - if: ${{ matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/master' }} - with: - access_key: ${{ secrets.DO_SPACES_ACCESS_KEY }} - secret_key: ${{ secrets.DO_SPACES_SECRET_KEY }} - space_name: zigtools-releases - space_region: nyc3 - source: artifacts/ - out_dir: zls/ diff --git a/build.zig b/build.zig index cef888d493..6daabec0ec 100644 --- a/build.zig +++ b/build.zig @@ -136,6 +136,45 @@ pub fn build(b: *Build) !void { }, }); + const targets: []const std.Target.Query = &.{ + .{ .cpu_arch = .x86_64, .os_tag = .windows }, + .{ .cpu_arch = .x86_64, .os_tag = .linux }, + .{ .cpu_arch = .x86_64, .os_tag = .macos }, + .{ .cpu_arch = .x86, .os_tag = .windows }, + .{ .cpu_arch = .x86, .os_tag = .linux }, + .{ .cpu_arch = .aarch64, .os_tag = .linux }, + .{ .cpu_arch = .aarch64, .os_tag = .macos }, + .{ .cpu_arch = .wasm32, .os_tag = .wasi }, + }; + + const release_step = b.step("release", "Build all release binaries"); + + for (targets) |target_query| { + const exe = b.addExecutable(.{ + .name = "zls", + .root_source_file = .{ .path = "src/main.zig" }, + .target = b.resolveTargetQuery(target_query), + .optimize = optimize, + .single_threaded = single_threaded, + .use_llvm = use_llvm, + .use_lld = use_llvm, + }); + exe.pie = pie; + exe.root_module.addImport("exe_options", exe_options_module); + exe.root_module.addImport("tracy", tracy_module); + exe.root_module.addImport("known-folders", known_folders_module); + exe.root_module.addImport("zls", zls_module); + + const target_output = b.addInstallArtifact(exe, .{ + .dest_dir = .{ + .override = .{ + .custom = try target_query.zigTriple(b.allocator), + }, + }, + }); + release_step.dependOn(&target_output.step); + } + const exe = b.addExecutable(.{ .name = "zls", .root_source_file = .{ .path = "src/main.zig" }, From 7d3d7d14b468d50b0f0ae49f441897fbaae463c6 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 05:14:44 +0100 Subject: [PATCH 07/18] remove the -Dcoverage_output_dir option outputting the coverage data to zig-out/coverage is slightly less cursed than with having a output directory option. --- .github/workflows/coverage.yml | 2 +- build.zig | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9aa10d7c9c..075707c7c8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -28,6 +28,6 @@ jobs: uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} - directory: zig-out/kcov/kcov-merged + directory: zig-out/coverage/kcov-merged fail_ci_if_error: true verbose: true diff --git a/build.zig b/build.zig index 6daabec0ec..4e3931caf5 100644 --- a/build.zig +++ b/build.zig @@ -41,7 +41,6 @@ pub fn build(b: *Build) !void { const enable_tracy_allocation = b.option(bool, "enable_tracy_allocation", "Enable using TracyAllocator to monitor allocations.") orelse enable_tracy; const enable_tracy_callstack = b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse enable_tracy; const coverage = b.option(bool, "generate_coverage", "Generate coverage data with kcov") orelse false; - const coverage_output_dir = b.option([]const u8, "coverage_output_dir", "Output directory for coverage data") orelse b.pathJoin(&.{ b.install_prefix, "kcov" }); const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); const data_version = b.option([]const u8, "data_version", "The Zig version your compiler is.") orelse "master"; const data_version_path = b.option([]const u8, "version_data_path", "Manually specify zig language reference file"); @@ -222,6 +221,7 @@ pub fn build(b: *Build) !void { test_step.dependOn(&b.addRunArtifact(src_tests).step); if (coverage) { + const coverage_output_dir = b.makeTempPath(); const include_pattern = b.fmt("--include-pattern=/src", .{}); const exclude_pattern = b.fmt("--exclude-pattern=/src/stage2", .{}); const args = &[_]std.Build.Step.Run.Arg{ @@ -245,13 +245,19 @@ pub fn build(b: *Build) !void { merge_step.addArgs(&.{ "kcov", "--merge", - coverage_output_dir, + b.pathJoin(&.{ coverage_output_dir, "output" }), b.pathJoin(&.{ coverage_output_dir, "test" }), }); - merge_step.step.dependOn(&b.addRemoveDirTree(coverage_output_dir).step); merge_step.step.dependOn(&tests_run.step); merge_step.step.dependOn(&src_tests_run.step); - test_step.dependOn(&merge_step.step); + + const install_coverage = b.addInstallDirectory(.{ + .source_dir = .{ .path = b.pathJoin(&.{ coverage_output_dir, "output" }) }, + .install_dir = .{ .custom = "coverage" }, + .install_subdir = "", + }); + install_coverage.step.dependOn(&merge_step.step); + test_step.dependOn(&install_coverage.step); } } From f5cb9b97e75d91a9160dabf31b8bd9cc190c11ab Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 05:20:30 +0100 Subject: [PATCH 08/18] CI: pass --summary all Good to have some insight on whats going on. --- .github/workflows/coverage.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 075707c7c8..54b71a2fb1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -22,7 +22,7 @@ jobs: - name: Run Tests with kcov run: | kcov --version - zig build test -Dgenerate_coverage + zig build test -Dgenerate_coverage --summary all - name: Upload to Codecov uses: codecov/codecov-action@v3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 20b4842c12..7da139349f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,4 +28,4 @@ jobs: run: zig fmt --check . - name: Run Tests - run: zig build test + run: zig build test --summary all From 3deb8ec66a09bc414ab94239516f068509d2c5da Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 6 Feb 2024 05:24:42 +0100 Subject: [PATCH 09/18] CI: update codecov/codecov-action to v4 --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 54b71a2fb1..24f796a092 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,7 +25,7 @@ jobs: zig build test -Dgenerate_coverage --summary all - name: Upload to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} directory: zig-out/coverage/kcov-merged From 0718557da18905c4a3b1a9f5c90f0476f70ccdc5 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:24:54 +0100 Subject: [PATCH 10/18] CI: upload separate release artifacts for latest master This should provide a download URL to the latest ZLS release that doesn't change which can be used in the [Installation Guide](https://github.com/zigtools/zls/wiki/Installation). --- .github/workflows/artifacts.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 65bb30c820..6c941f0e90 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -22,25 +22,27 @@ jobs: - name: Build artifacts run: | - zig build release -Dcpu=baseline -Doptimize=ReleaseSafe --summary all + mkdir -p artifacts/master - zls_version=$(zig-out/x86_64-linux/zls --version) + zig build release -Dcpu=baseline -Doptimize=ReleaseSafe --prefix artifacts/master --summary all + + zls_version=$(artifacts/master/x86_64-linux/zls --version) mkdir -p "artifacts/$zls_version/" - cp -r zig-out/* "artifacts/$zls_version/" + cp -r artifacts/master/* "artifacts/$zls_version/" wget https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json cp index.json artifacts/old-index.json - for file in zig-out/*; do - targets+=("${file#zig-out/}") + for file in artifacts/master/*; do + targets+=("${file#artifacts/master/}") done jq \ --arg targets "${targets[*]}" \ --arg zig_version "$(zig version)" \ - --arg zls_version "$(zig-out/x86_64-linux/zls --version)" \ - --arg zls_minimum_build_version "$(zig-out/x86_64-linux/zls --minimum-build-version)" \ + --arg zls_version "$(artifacts/master/x86_64-linux/zls --version)" \ + --arg zls_minimum_build_version "$(artifacts/master/x86_64-linux/zls --minimum-build-version)" \ '.latest = $zls_version | .versions[$zls_version] = { "date": now | todateiso8601, "builtWithZigVersion": $zig_version, From cc9062ed6fe78ad27ac2859557726a1f95dca40b Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:06:50 +0100 Subject: [PATCH 11/18] CI: don't re-trigger action on pull request I don't think this was necessary since we already trigger on push. --- .github/workflows/build_runner.yml | 4 ---- .github/workflows/coverage.yml | 3 ++- .github/workflows/main.yml | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_runner.yml b/.github/workflows/build_runner.yml index 2c989c1244..abc7c4c96f 100644 --- a/.github/workflows/build_runner.yml +++ b/.github/workflows/build_runner.yml @@ -5,10 +5,6 @@ on: paths: - ".github/workflows/build_runner.yml" - "src/build_runner/**" - pull_request: - paths: - - ".github/workflows/build_runner.yml" - - "src/build_runner/**" schedule: - cron: "0 0 * * *" workflow_dispatch: diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 24f796a092..b31f3896c5 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,6 +1,7 @@ name: Code Coverage -on: [push, pull_request] +on: + push: jobs: coverage: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7da139349f..4dcc94a132 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,7 +1,6 @@ name: CI on: - pull_request: push: schedule: - cron: "0 0 * * *" From 8c44b8a583609958b82c1ff2fe5cfbc7c5f7aaa3 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sun, 11 Feb 2024 04:52:53 +0100 Subject: [PATCH 12/18] CI: do not run deployment action concurrently This should hopefully avoid the potential issues that would arise when the index.json is updated concurrently by multiple jobs. --- .github/workflows/artifacts.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 6c941f0e90..dee6abebd6 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -6,6 +6,10 @@ on: - master workflow_dispatch: +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + jobs: deploy: if: github.repository_owner == 'zigtools' From c09bc14cbc3dfc9283d85f7a6dd7fee383aff9b8 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 13 Feb 2024 02:49:49 +0100 Subject: [PATCH 13/18] CI: remove invalid job dependency from release deployment --- .github/workflows/artifacts.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index dee6abebd6..7194e1e8b0 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -14,7 +14,6 @@ jobs: deploy: if: github.repository_owner == 'zigtools' runs-on: ubuntu-latest - needs: [build, check_build_runner] steps: - uses: actions/checkout@v4 From 5f57473c84ec4ec61d5b6901faaacac4c5444d1d Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 13 Feb 2024 03:11:51 +0100 Subject: [PATCH 14/18] CI: ensure that tags are fetched so that `zls --version` works The previous deployment just published ZLS 0.12.0 --- .github/workflows/artifacts.yml | 2 ++ .github/workflows/build_runner.yml | 2 ++ .github/workflows/fuzz.yml | 2 ++ .github/workflows/main.yml | 2 ++ 4 files changed, 8 insertions(+) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 7194e1e8b0..34699118ae 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -16,6 +16,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-tags: "true" - uses: goto-bus-stop/setup-zig@v2 with: diff --git a/.github/workflows/build_runner.yml b/.github/workflows/build_runner.yml index abc7c4c96f..b266d0b642 100644 --- a/.github/workflows/build_runner.yml +++ b/.github/workflows/build_runner.yml @@ -24,6 +24,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-tags: "true" - name: Grab zig uses: goto-bus-stop/setup-zig@v2 diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 7dcf61180c..d3fbb6ac21 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -64,12 +64,14 @@ jobs: if: github.event_name != 'pull_request_target' uses: actions/checkout@v4 with: + fetch-tags: "true" path: zls - name: Checkout zls (PR) if: github.event_name == 'pull_request_target' uses: actions/checkout@v4 with: + fetch-tags: "true" path: zls ref: "refs/pull/${{ github.event.number }}/merge" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4dcc94a132..4a7046bf73 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,8 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + with: + fetch-tags: "true" - uses: goto-bus-stop/setup-zig@v2 with: From 1bfb8a001938965298cc83022ea6adad8faaa4b4 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 13 Feb 2024 03:28:08 +0100 Subject: [PATCH 15/18] CI: fetch entire history to resolve ZLS version string I give up --- .github/workflows/artifacts.yml | 2 +- .github/workflows/build_runner.yml | 2 -- .github/workflows/fuzz.yml | 4 ++-- .github/workflows/main.yml | 2 -- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 34699118ae..aa669ea2a2 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-tags: "true" + fetch-depth: 0 # required to resolve the version string - uses: goto-bus-stop/setup-zig@v2 with: diff --git a/.github/workflows/build_runner.yml b/.github/workflows/build_runner.yml index b266d0b642..abc7c4c96f 100644 --- a/.github/workflows/build_runner.yml +++ b/.github/workflows/build_runner.yml @@ -24,8 +24,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-tags: "true" - name: Grab zig uses: goto-bus-stop/setup-zig@v2 diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index d3fbb6ac21..46ecd3ce25 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -64,14 +64,14 @@ jobs: if: github.event_name != 'pull_request_target' uses: actions/checkout@v4 with: - fetch-tags: "true" + fetch-depth: 0 path: zls - name: Checkout zls (PR) if: github.event_name == 'pull_request_target' uses: actions/checkout@v4 with: - fetch-tags: "true" + fetch-depth: 0 path: zls ref: "refs/pull/${{ github.event.number }}/merge" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a7046bf73..4dcc94a132 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - with: - fetch-tags: "true" - uses: goto-bus-stop/setup-zig@v2 with: From e26aad7adb00ebb44e6259daaae48971229c1c0a Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 13 Feb 2024 04:15:49 +0100 Subject: [PATCH 16/18] nix: update langref file --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5cfe2dd0ad..b759f44c3b 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ flake-utils.url = "github:numtide/flake-utils"; - langref.url = "https://raw.githubusercontent.com/ziglang/zig/63bd2bff12992aef0ce23ae4b344e9cb5d65f05d/doc/langref.html.in"; + langref.url = "https://raw.githubusercontent.com/ziglang/zig/54bbc73f8502fe073d385361ddb34a43d12eec39/doc/langref.html.in"; langref.flake = false; }; From faa87d230a9acd556f736960123a26c0d08bb78a Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 13 Feb 2024 04:17:24 +0100 Subject: [PATCH 17/18] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'langref': 'https://raw.githubusercontent.com/ziglang/zig/63bd2bff12992aef0ce23ae4b344e9cb5d65f05d/doc/langref.html.in?narHash=sha256-mYdDCBdNEIeMbavdhSo8qXqW%2B3fqPC8BAich7W3umrI%3D' → 'https://raw.githubusercontent.com/ziglang/zig/54bbc73f8502fe073d385361ddb34a43d12eec39/doc/langref.html.in?narHash=sha256-94broSBethRhPJr0G9no4TPyB8ee6BQ/hHK1QnLPln0%3D' • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/10b813040df67c4039086db0f6eaf65c536886c6' (2024-02-10) → 'github:NixOS/nixpkgs/2d627a2a704708673e56346fcb13d25344b8eaf3' (2024-02-12) • Updated input 'zig-overlay': 'github:mitchellh/zig-overlay/aa4edff6f53e64443ca77e8d9ffe866f29e5b3d4' (2024-02-11) → 'github:mitchellh/zig-overlay/06f4507d05f90a54409a5206fcfba5966eea0c03' (2024-02-13) --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 82242b0f0c..4b14781cc6 100644 --- a/flake.lock +++ b/flake.lock @@ -72,22 +72,22 @@ "langref": { "flake": false, "locked": { - "narHash": "sha256-mYdDCBdNEIeMbavdhSo8qXqW+3fqPC8BAich7W3umrI=", + "narHash": "sha256-94broSBethRhPJr0G9no4TPyB8ee6BQ/hHK1QnLPln0=", "type": "file", - "url": "https://raw.githubusercontent.com/ziglang/zig/63bd2bff12992aef0ce23ae4b344e9cb5d65f05d/doc/langref.html.in" + "url": "https://raw.githubusercontent.com/ziglang/zig/54bbc73f8502fe073d385361ddb34a43d12eec39/doc/langref.html.in" }, "original": { "type": "file", - "url": "https://raw.githubusercontent.com/ziglang/zig/63bd2bff12992aef0ce23ae4b344e9cb5d65f05d/doc/langref.html.in" + "url": "https://raw.githubusercontent.com/ziglang/zig/54bbc73f8502fe073d385361ddb34a43d12eec39/doc/langref.html.in" } }, "nixpkgs": { "locked": { - "lastModified": 1707588924, - "narHash": "sha256-0e1ce6X5ghapv6cAF9rxLZKeNyFHHXsLbGxN2cQQE8U=", + "lastModified": 1707743206, + "narHash": "sha256-AehgH64b28yKobC/DAWYZWkJBxL/vP83vkY+ag2Hhy4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "10b813040df67c4039086db0f6eaf65c536886c6", + "rev": "2d627a2a704708673e56346fcb13d25344b8eaf3", "type": "github" }, "original": { @@ -130,11 +130,11 @@ ] }, "locked": { - "lastModified": 1707611073, - "narHash": "sha256-sMsxVKXP5TLcaVMNlRZ7KlDsYGwDdJAMtY0DKmb+7fQ=", + "lastModified": 1707783766, + "narHash": "sha256-kD90pK+KAzr3UrohYRqE7fWUaEg4Mv3rk1IhubiHFUM=", "owner": "mitchellh", "repo": "zig-overlay", - "rev": "aa4edff6f53e64443ca77e8d9ffe866f29e5b3d4", + "rev": "06f4507d05f90a54409a5206fcfba5966eea0c03", "type": "github" }, "original": { From 88a352a46ce7fbf81aa009dec6f03bd7d08af2b1 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 13 Feb 2024 04:53:38 +0100 Subject: [PATCH 18/18] specify sort score of .Method completion kind --- src/features/completions.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/completions.zig b/src/features/completions.zig index c51357fa19..6c2011bb69 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -660,7 +660,7 @@ fn kindToSortScore(kind: types.CompletionItemKind) ?[]const u8 { .Variable => "2_", .Field => "3_", - .Function => "4_", + .Function, .Method => "4_", .Keyword, .Snippet, .EnumMember => "5_", @@ -673,7 +673,7 @@ fn kindToSortScore(kind: types.CompletionItemKind) ?[]const u8 { => "6_", else => { - log.debug(@typeName(types.CompletionItemKind) ++ "{s} has no sort score specified!", .{@tagName(kind)}); + log.debug(@typeName(types.CompletionItemKind) ++ ".{s} has no sort score specified!", .{@tagName(kind)}); return null; }, };