diff --git a/build.zig b/build.zig index 78105f4..862b32a 100644 --- a/build.zig +++ b/build.zig @@ -2,8 +2,6 @@ const builtin = @import("builtin"); const std = @import("std"); const zig = @import("zig"); -const Exe = enum { zig, zls }; - pub fn build(b: *std.Build) !void { const zig_dep = b.dependency("zig", .{}); @@ -51,7 +49,6 @@ pub fn build(b: *std.Build) !void { }, }), }); - setBuildOptions(b, exe, .zig); const install = b.addInstallArtifact(exe, .{}); b.getInstallStep().dependOn(&install.step); @@ -64,31 +61,6 @@ pub fn build(b: *std.Build) !void { break :blk exe; }; - { - const exe = b.addExecutable(.{ - .name = "zls", - .root_module = b.createModule(.{ - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - .single_threaded = true, - .imports = &.{ - .{ .name = "zig", .module = zig_mod }, - .{ .name = "version", .module = dev_version_embed }, - }, - }), - }); - setBuildOptions(b, exe, .zls); - const install = b.addInstallArtifact(exe, .{}); - - const run = b.addRunArtifact(exe); - run.step.dependOn(&install.step); - if (b.args) |args| { - run.addArgs(args); - } - b.step("zls", "").dependOn(&run.step); - } - const test_step = b.step("test", ""); addTests(b, dev_version, anyzig, test_step, .{ .make_build_steps = true }); @@ -154,12 +126,6 @@ fn makeCalVersion() ![11]u8 { return buf; } -fn setBuildOptions(b: *std.Build, exe: *std.Build.Step.Compile, exe_kind: Exe) void { - const o = b.addOptions(); - o.addOption(Exe, "exe", exe_kind); - exe.root_module.addOptions("build_options", o); -} - const SharedTestOptions = struct { make_build_steps: bool, failing_to_execute_foreign_is_an_error: bool = true, @@ -622,8 +588,6 @@ fn ci( const target_dest_dir: std.Build.InstallDir = .{ .custom = ci_target_str }; - const install_exes = b.step(b.fmt("install-{s}", .{ci_target_str}), ""); - ci_step.dependOn(install_exes); const zig_exe = b.addExecutable(.{ .name = "zig", .root_module = b.createModule(.{ @@ -637,27 +601,11 @@ fn ci( }, }), }); - setBuildOptions(b, zig_exe, .zig); - install_exes.dependOn( + const install_exe = b.step(b.fmt("install-{s}", .{ci_target_str}), ""); + ci_step.dependOn(install_exe); + install_exe.dependOn( &b.addInstallArtifact(zig_exe, .{ .dest_dir = .{ .override = target_dest_dir } }).step, ); - const zls_exe = b.addExecutable(.{ - .name = "zls", - .root_module = b.createModule(.{ - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - .single_threaded = true, - .imports = &.{ - .{ .name = "zig", .module = zig_mod }, - .{ .name = "version", .module = release_version_embed }, - }, - }), - }); - setBuildOptions(b, zls_exe, .zls); - install_exes.dependOn( - &b.addInstallArtifact(zls_exe, .{ .dest_dir = .{ .override = target_dest_dir } }).step, - ); const target_test_step = b.step(b.fmt("test-{s}", .{ci_target_str}), ""); addTests(b, release_version, zig_exe, target_test_step, .{ @@ -678,7 +626,7 @@ fn ci( ci_target_str, target.result, target_dest_dir, - install_exes, + install_exe, host_zip_exe, )); } @@ -690,14 +638,11 @@ fn makeCiArchiveStep( ci_target_str: []const u8, target: std.Target, target_install_dir: std.Build.InstallDir, - install_exes: *std.Build.Step, + install_exe: *std.Build.Step, host_zip_exe: *std.Build.Step.Compile, ) *std.Build.Step { const install_path = b.getInstallPath(.prefix, "."); - // not sure yet if we want to include zls.exe in our archives? - const include_zls = false; - if (target.os.tag == .windows) { const out_zip_file = b.pathJoin(&.{ install_path, @@ -707,15 +652,11 @@ fn makeCiArchiveStep( zip.addArg(out_zip_file); zip.addArg("zig.exe"); zip.addArg("zig.pdb"); - if (include_zls) { - zip.addArg("zls.exe"); - zip.addArg("zls.pdb"); - } zip.cwd = .{ .cwd_relative = b.getInstallPath( target_install_dir, ".", ) }; - zip.step.dependOn(install_exes); + zip.step.dependOn(install_exe); return &zip.step; } @@ -729,13 +670,10 @@ fn makeCiArchiveStep( targz, "zig", }); - if (include_zls) { - tar.addArg("zls"); - } tar.cwd = .{ .cwd_relative = b.getInstallPath( target_install_dir, ".", ) }; - tar.step.dependOn(install_exes); + tar.step.dependOn(install_exe); return &tar.step; } diff --git a/src/main.zig b/src/main.zig index 0884370..587241a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,5 @@ const std = @import("std"); const builtin = @import("builtin"); -const build_options = @import("build_options"); const assert = std.debug.assert; const io = std.io; const fs = std.fs; @@ -31,8 +30,6 @@ pub const std_options: std.Options = .{ .logFn = anyzigLog, }; -pub const exe_str = @tagName(build_options.exe); - const Verbosity = enum { debug, warn, @@ -273,8 +270,8 @@ fn determineSemanticVersion(scratch: Allocator, build_root: BuildRoot) !Semantic } errExit( - "build.zig.zon is missing minimum_zig_version, either add it or run '{s} VERSION' to specify a version", - .{@tagName(build_options.exe)}, + "build.zig.zon is missing minimum_zig_version, either add it or run 'zig VERSION' to specify a version", + .{}, ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -312,26 +309,25 @@ pub fn main() !void { const maybe_command: ?[]const u8 = if (cmdline_offset >= cmdline.len()) null else cmdline.arg(cmdline_offset); + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // NOTE: I'm not sure if it should be "zig VERSION zls" or "zig zls VERSION"? + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + const build_root_options = blk: { var options: FindBuildRootOptions = .{}; - switch (build_options.exe) { - .zig => { - if (maybe_command) |command| { - if (std.mem.eql(u8, command, "build")) { - var index: usize = cmdline_offset + 1; - while (index < cmdline.len()) : (index += 1) { - const arg = cmdline.arg(index); - if (std.mem.eql(u8, arg, "--build-file")) { - if (index == cmdline.len()) break; - index += 1; - options.build_file = cmdline.arg(index); - log.info("build file '{s}'", .{options.build_file.?}); - } - } + if (maybe_command) |command| { + if (std.mem.eql(u8, command, "build")) { + var index: usize = cmdline_offset + 1; + while (index < cmdline.len()) : (index += 1) { + const arg = cmdline.arg(index); + if (std.mem.eql(u8, arg, "--build-file")) { + if (index == cmdline.len()) break; + index += 1; + options.build_file = cmdline.arg(index); + log.info("build file '{s}'", .{options.build_file.?}); } } - }, - .zls => {}, + } } break :blk options; }; @@ -345,7 +341,7 @@ pub fn main() !void { ); std.process.exit(0xff); } - if (build_options.exe == .zig and (std.mem.eql(u8, command, "init") or std.mem.eql(u8, command, "init-exe") or std.mem.eql(u8, command, "init-lib"))) { + if (std.mem.eql(u8, command, "init") or std.mem.eql(u8, command, "init-exe") or std.mem.eql(u8, command, "init-lib")) { const is_help = blk_is_help: { var index: usize = cmdline_offset + 1; while (index < cmdline.len()) : (index += 1) { @@ -368,7 +364,7 @@ pub fn main() !void { const build_root = try findBuildRoot(arena, build_root_options) orelse { try std.io.getStdErr().writeAll( "no build.zig to pull a zig version from, you can:\n" ++ - " 1. run '" ++ exe_str ++ " VERSION' to specify a version\n" ++ + " 1. run 'zig VERSION' to specify a version\n" ++ " 2. run from a directory where a build.zig can be found\n", ); std.process.exit(0xff); @@ -401,6 +397,8 @@ pub fn main() !void { std.log.info("master is at {}", .{semantic_version}); } + if (true) @panic("todo: see if this is a 'zig zls' command"); + const hashstore_path = try std.fs.path.join(arena, &.{ app_data_path, "hashstore" }); // no need to free try hashstore.init(hashstore_path);