Skip to content

commit langref.html.in to source control instead of downloading it #2000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,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 test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match filter") orelse &[0][]const u8{};
const data_version = b.option([]const u8, "data_version", "The Zig version your compiler is.");
const data_version_path = b.option([]const u8, "version_data_path", "Manually specify zig language reference file");
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 resolved_zls_version = getVersion(b);
Expand Down Expand Up @@ -91,44 +88,36 @@ pub fn build(b: *Build) !void {
const gen_exe = b.addExecutable(.{
.name = "zls_gen",
.root_source_file = b.path("src/tools/config_gen.zig"),
.target = b.host,
.target = b.graph.host,
.single_threaded = true,
});

const version_data_module = blk: {
const gen_version_data_cmd = b.addRunArtifact(gen_exe);
const version = if (zls_version.pre == null and zls_version.build == null) b.fmt("{}", .{zls_version}) else "master";
gen_version_data_cmd.addArgs(&.{ "--langref-version", version });

gen_version_data_cmd.addArg("--langref-path");
gen_version_data_cmd.addFileArg(b.path(b.fmt("src/tools/langref_{s}.html.in", .{version})));

gen_version_data_cmd.addArg("--generate-version-data");
const version_data_path = gen_version_data_cmd.addOutputFileArg("version_data.zig");

break :blk b.addModule("version_data", .{ .root_source_file = version_data_path });
};

const gen_cmd = b.addRunArtifact(gen_exe);
gen_cmd.addArgs(&.{
"--generate-config-path",
"--generate-config",
b.pathFromRoot("src/Config.zig"),
"--generate-schema-path",
"--generate-schema",
b.pathFromRoot("schema.json"),
});
if (b.args) |args| gen_cmd.addArgs(args);

const gen_step = b.step("gen", "Regenerate config files");
gen_step.dependOn(&gen_cmd.step);

const gen_version_data_cmd = b.addRunArtifact(gen_exe);
const resolved_data_version = data_version orelse if (zls_version.pre == null and zls_version.build == null) b.fmt("{}", .{zls_version}) else "master";
gen_version_data_cmd.addArgs(&.{ "--generate-version-data", resolved_data_version });
if (data_version_path) |path| {
gen_version_data_cmd.addArg("--langref_path");
gen_version_data_cmd.addFileArg(.{ .cwd_relative = path });
}
const version_data_file_name = if (data_version_path != null)
b.fmt("version_data_{s}.zig", .{resolved_data_version})
else blk: {
// invalidate version data periodically from cache because the website content may change
// setting `has_side_effects` would also be possible but that would always force a re-run
const timestamp = @divFloor(std.time.timestamp(), std.time.s_per_day);
break :blk b.fmt("version_data_{s}_{d}.zig", .{ resolved_data_version, timestamp });
};
gen_version_data_cmd.addArg("--generate-version-data-path");
const version_data_path: std.Build.LazyPath = if (override_version_data_file_path) |path|
.{ .cwd_relative = path }
else
gen_version_data_cmd.addOutputFileArg(version_data_file_name);
const version_data_module = b.addModule("version_data", .{ .root_source_file = version_data_path });

const zls_module = b.addModule("zls", .{
.root_source_file = b.path("src/zls.zig"),
.imports = &.{
Expand Down
13 changes: 0 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
gitignore.inputs.nixpkgs.follows = "nixpkgs";

flake-utils.url = "github:numtide/flake-utils";

# llvm: fix @wasmMemory{Size,Grow} for wasm64
langref.url = "https://raw.githubusercontent.com/ziglang/zig/eb7f318ea897d51082b70c84591242735c8a2c53/doc/langref.html.in";
langref.flake = false;
};

outputs = { self, nixpkgs, zig-overlay, gitignore, flake-utils, langref }:
outputs = { self, nixpkgs, zig-overlay, gitignore, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
Expand All @@ -34,14 +30,13 @@
dontConfigure = true;
dontInstall = true;
doCheck = true;
langref = langref;
buildPhase = ''
mkdir -p .cache
ln -s ${pkgs.callPackage ./deps.nix { zig = zig; }} .cache/p
zig build install --cache-dir $(pwd)/.zig-cache --global-cache-dir $(pwd)/.cache -Dversion_data_path=$langref -Dcpu=baseline -Doptimize=ReleaseSafe --prefix $out
zig build install --cache-dir $(pwd)/.zig-cache --global-cache-dir $(pwd)/.cache -Dcpu=baseline -Doptimize=ReleaseSafe --prefix $out
'';
checkPhase = ''
zig build test --cache-dir $(pwd)/.zig-cache --global-cache-dir $(pwd)/.cache -Dversion_data_path=$langref -Dcpu=baseline
zig build test --cache-dir $(pwd)/.zig-cache --global-cache-dir $(pwd)/.cache -Dcpu=baseline
'';
};
}
Expand Down
2 changes: 1 addition & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"default": false
},
"semantic_tokens": {
"description": "Set level of semantic tokens. Partial only includes information that requires semantic analysis.",
"description": "Set level of semantic tokens. `partial` only includes information that requires semantic analysis.",
"type": "string",
"enum": [
"none",
Expand Down
2 changes: 1 addition & 1 deletion src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build_on_save_step: []const u8 = "install",
/// Whether to automatically fix errors on save. Currently supports adding and removing discards.
enable_autofix: bool = false,

/// Set level of semantic tokens. Partial only includes information that requires semantic analysis.
/// Set level of semantic tokens. `partial` only includes information that requires semantic analysis.
semantic_tokens: enum {
none,
partial,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
"name": "semantic_tokens",
"description": "Set level of semantic tokens. Partial only includes information that requires semantic analysis.",
"description": "Set level of semantic tokens. `partial` only includes information that requires semantic analysis.",
"type": "enum",
"enum": [
"none",
Expand Down
Loading