Skip to content

Conversation

@Vexu
Copy link
Member

@Vexu Vexu commented Nov 14, 2025

I meant to do this as a follow up to #438 but then forgot about it.

Copy link
Collaborator

@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.

The mirror fetching could also be made lazy to further reduce requests made for community-mirrors.txt.

This may also make it viable to report a message to the user if we failed to fetch the mirror list.

diff --git a/src/versionManager.ts b/src/versionManager.ts
index 3e595e7..14d1643 100644
--- a/src/versionManager.ts
+++ b/src/versionManager.ts
@@ -36,7 +36,7 @@ export interface Config {
      * `"version"` for Zig, `"--version"` for ZLS
      */
     versionArg: string;
-    mirrorUrls: vscode.Uri[];
+    getMirrorUrls: () => Promise<vscode.Uri[]>;
     canonicalUrl: {
         release: vscode.Uri;
         nightly: vscode.Uri;
@@ -93,7 +93,7 @@ async function installGuarded(config: Config, version: semver.SemVer): Promise<s
         throw new Error(`Can't install ${config.title} because 'tar' could not be found`);
     }
 
-    const mirrors = [...config.mirrorUrls]
+    const mirrors = [...(await config.getMirrorUrls())]
         .map((mirror) => ({ mirror, sort: Math.random() }))
         .sort((a, b) => a.sort - b.sort)
         .map(({ mirror }) => mirror);
diff --git a/src/zigSetup.ts b/src/zigSetup.ts
index 6c6e7ad..e8d5021 100644
--- a/src/zigSetup.ts
+++ b/src/zigSetup.ts
@@ -713,7 +713,9 @@ export async function setupZig(context: vscode.ExtensionContext) {
         /** https://ziglang.org/download */
         minisignKey: minisign.parseKey("RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U"),
         versionArg: "version",
-        mirrorUrls: await getMirrors(context),
+        getMirrorUrls() {
+            return getMirrors(context);
+        },
         canonicalUrl: {
             release: vscode.Uri.parse("https://ziglang.org/download"),
             nightly: vscode.Uri.parse("https://ziglang.org/builds"),
diff --git a/src/zls.ts b/src/zls.ts
index 0a72eb2..0bdc3b6 100644
--- a/src/zls.ts
+++ b/src/zls.ts
@@ -511,7 +511,9 @@ export async function activate(context: vscode.ExtensionContext) {
         /** https://github.com/zigtools/release-worker */
         minisignKey: minisign.parseKey("RWR+9B91GBZ0zOjh6Lr17+zKf5BoSuFvrx2xSeDE57uIYvnKBGmMjOex"),
         versionArg: "--version",
-        mirrorUrls: [],
+        getMirrorUrls() {
+            return Promise.resolve([]);
+        },
         canonicalUrl: {
             release: vscode.Uri.parse("https://builds.zigtools.org"),
             nightly: vscode.Uri.parse("https://builds.zigtools.org"),

Co-authored-by: Techatrix <[email protected]>
@Vexu
Copy link
Member Author

Vexu commented Nov 15, 2025

The mirror fetching could also be made lazy to further reduce requests made for community-mirrors.txt.

Even better, thanks!

This enables zig.install to work even if ziglang.org is down.
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.

2 participants