summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig34
1 files changed, 34 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 5f3ce06f..3c3c65f2 100644
--- a/build.zig
+++ b/build.zig
@@ -116,6 +116,13 @@ pub fn build(b: *std.Build) void {
if (target.result.os.tag == .freebsd or target.result.os.tag == .netbsd or target.result.os.tag == .openbsd)
root_mod.linkSystemLibrary("util", .{});
+ // The language backend (src/lsp_zls.zig) links ZLS as a MODULE — no zls
+ // binary, no JSON-RPC, no protocol. Everything except the browser gets it;
+ // emscripten does not, because the web shell has no threads and no-ops the
+ // lsp effect anyway, so paying to compile an analyser it can never call
+ // would be pure wasm.
+ const zls_backend = !is_emscripten;
+
const opts = b.addOptions();
opts.addOption(Platform, "platform", platform);
opts.addOption(bool, "syntax_highlighting", tree_sitter_grammars != .disabled);
@@ -123,9 +130,36 @@ pub fn build(b: *std.Build) void {
opts.addOption(bool, "syntax_minimal_grammars", tree_sitter_grammars == .minimal or tree_sitter_grammars == .full);
opts.addOption(bool, "syntax_full_grammars", tree_sitter_grammars == .full);
opts.addOption(bool, "enable_tracy", tracy != null);
+ opts.addOption(bool, "zls_backend", zls_backend);
+ // The stdlib this binary was compiled against, so `gd` on `std.mem.count`
+ // can open the same mem.zig the compiler used. ZLS resolves `@import("std")`
+ // through `zig_lib_dir` and nothing else; without it every std symbol is a
+ // silent miss, and asking the `zig` binary for it is the subprocess this
+ // whole backend exists to avoid. ZIG_LIB_DIR overrides it at runtime.
+ opts.addOption([]const u8, "zig_lib_dir", b.graph.zig_lib_directory.path orelse "");
root_mod.addOptions("pardes_config", opts);
hx_core_mod.addOptions("pardes_config", opts);
+ if (zls_backend) {
+ // .target/.optimize are mandatory: createZLSModule bakes them into the
+ // module it registers, so a mismatch here is a second compilation of
+ // the whole analyser rather than an error.
+ // `.target`/`.optimize` are MANDATORY: createZLSModule bakes them in,
+ // so a module built without them mismatches ours at link time.
+ // `version-string` is not cosmetic either — ZLS's build.zig shells out
+ // to `git describe` to name itself, and a package the build system
+ // fetched is an extracted tarball with no .git, so every single build
+ // printed a "Failed to run git describe" warning. We pin the commit in
+ // build.zig.zon, so we already know the answer.
+ const zls_dep = b.dependency("zls", .{
+ .target = target,
+ .optimize = optimize,
+ .@"version-string" = @as([]const u8, "0.16.1-dev"),
+ });
+ root_mod.addImport("zls", zls_dep.module("zls"));
+ hx_core_mod.addImport("zls", zls_dep.module("zls"));
+ }
+
// Tracy zones (src/tracy.zig): compile the client into the binary only when
// -Dtracy=<path> names a Tracy checkout; otherwise every zone is a no-op.
// Sampling/callstacks/system tracing stay off: tracy's symbol worker