Skip to content
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

Multiple build runners #1411

Merged
merged 4 commits into from
Aug 19, 2023
Merged

Conversation

leecannon
Copy link
Member

@leecannon leecannon commented Aug 17, 2023

This PR uses a different build runner based on the runtime zig version.

This is not exactly aligned with the decision in #1020 but the maintenance burden to do this is not large:

  • On a new major release being tagged make a copy of build_runner/master.zig for that release and update the build_runner/BuildRunnerVersion.zig enum.
  • If the data output by the build runner is changed (build_runner/BuildConfig.zig) then the older build runners will need to be updated to match the json format.

Fixes #1396

@leecannon leecannon force-pushed the multiple_build_runners branch 4 times, most recently from 0c3598f to f75b8ff Compare August 17, 2023 22:12
@leecannon leecannon marked this pull request as draft August 17, 2023 22:12
@leecannon leecannon force-pushed the multiple_build_runners branch 2 times, most recently from 5db0a91 to 4f2017d Compare August 17, 2023 22:17
@leecannon leecannon marked this pull request as ready for review August 17, 2023 22:23
Copy link
Member

@Techatrix Techatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you can apply this patch to simplify the logic in BuildRunnerVersion.zig
I guess you did this because you didn't want to have the patch version in the enum but adding it in makes it so much simpler.

diff --git a/src/build_runner/0.10.zig b/src/build_runner/0.10.0.zig
similarity index 100%
rename from src/build_runner/0.10.zig
rename to src/build_runner/0.10.0.zig
diff --git a/src/build_runner/0.11.zig b/src/build_runner/0.11.0.zig
similarity index 100%
rename from src/build_runner/0.11.zig
rename to src/build_runner/0.11.0.zig
diff --git a/src/build_runner/BuildRunnerVersion.zig b/src/build_runner/BuildRunnerVersion.zig
index 7a2028a..24ef916 100644
--- a/src/build_runner/BuildRunnerVersion.zig
+++ b/src/build_runner/BuildRunnerVersion.zig
@@ -5,8 +5,8 @@ const build_options = @import("build_options");
 // There should be no need to have a build runner for minor patches (e.g. 0.10.1)
 pub const BuildRunnerVersion = enum {
     master,
-    @"0.11",
-    @"0.10",
+    @"0.11.0",
+    @"0.10.0",
 
     pub fn selectBuildRunnerVersion(runtime_zig_version: std.SemanticVersion) BuildRunnerVersion {
         const runtime_zig_version_simple = std.SemanticVersion{
@@ -23,44 +23,18 @@ pub const BuildRunnerVersion = enum {
         return switch (runtime_zig_version_simple.order(zls_version_simple)) {
             .eq, .gt => .master,
             .lt => blk: {
-                const build_runners = BuildRunnerVersion.non_master_build_runners;
-
-                for (build_runners) |build_runner| {
-                    switch (runtime_zig_version.order(build_runner.version)) {
-                        .eq, .gt => break :blk build_runner.tag,
+                const available_versions = std.meta.tags(BuildRunnerVersion);
+                for (available_versions[1..]) |build_runner_version| {
+                    const version = std.SemanticVersion.parse(@tagName(build_runner_version)) catch unreachable;
+                    switch (runtime_zig_version.order(version)) {
+                        .eq, .gt => break :blk build_runner_version,
                         .lt => {},
                     }
                 }
 
                 // failed to find compatible build runner, falling back to oldest supported version
-                break :blk BuildRunnerVersion.oldest_version;
+                break :blk available_versions[available_versions.len - 1];
             },
         };
     }
-
-    const oldest_version = blk: {
-        const tags = std.meta.tags(BuildRunnerVersion);
-        break :blk tags[tags.len - 1];
-    };
-
-    const NonMasterBuildRunner = struct { tag: BuildRunnerVersion, version: std.SemanticVersion };
-
-    const non_master_build_runners = blk: {
-        const tags = std.meta.tags(BuildRunnerVersion);
-
-        var build_runners: [tags.len - 1]NonMasterBuildRunner = .{};
-
-        var i: usize = 0;
-
-        for (tags) |tag| {
-            if (tag == .master) continue;
-            build_runners[i] = .{
-                .tag = tag,
-                .version = std.SemanticVersion.parse(@tagName(tag) ++ ".0") catch unreachable,
-            };
-            i += 1;
-        }
-
-        break :blk build_runners;
-    };
 };

src/Server.zig Outdated Show resolved Hide resolved
src/Server.zig Outdated Show resolved Hide resolved
@leecannon leecannon merged commit 5e6c6c1 into zigtools:master Aug 19, 2023
5 checks passed
@leecannon leecannon deleted the multiple_build_runners branch August 19, 2023 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zls is broken in bun's repo
2 participants