Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Closed
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
28 changes: 23 additions & 5 deletions src/versionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import which from "which";
import semver from "semver";

import * as minisign from "./minisign";
import { getVersion, getZigArchName, getZigOSName } from "./zigUtil";
import { getHostZigName, getVersion, getZigArchName, getZigOSName } from "./zigUtil";

const execFile = util.promisify(childProcess.execFile);
const chmod = util.promisify(fs.chmod);
Expand Down Expand Up @@ -68,7 +68,14 @@ export async function install(config: Config, version: semver.SemVer): Promise<s

async function installGuarded(config: Config, version: semver.SemVer): Promise<string> {
const exeName = config.exeName + (process.platform === "win32" ? ".exe" : "");
const subDirName = `${getZigOSName()}-${getZigArchName()}-${version.raw}`;
// After version 0.14.1/0.15.0-dev.631+9a3540d61 Zig tarballs put
// the architecture first like it is in target triples.
const subDirName =
config.exeName === "zig" &&
((version.prerelease.length === 0 && semver.gte(version, "0.14.1")) ||
semver.gte(version, "0.15.0-dev.631+9a3540d61"))
? `${getZigArchName()}-${getZigOSName()}-${version.raw}`
: `${getZigOSName()}-${getZigArchName()}-${version.raw}`;
const exeUri = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName, subDirName, exeName);

await setLastAccessTime(config, version);
Expand Down Expand Up @@ -124,7 +131,7 @@ async function installFromMirror(
const isWindows = process.platform === "win32";
const fileExtension = isWindows ? "zip" : "tar.xz";
const exeName = config.exeName + (isWindows ? ".exe" : "");
const subDirName = `${getZigOSName()}-${getZigArchName()}-${version.raw}`;
const subDirName = `${getHostZigName()}-${version.raw}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will fail for older Zig versions like 0.13.0. subDirName is also used to resolve the file name that should be downloaded.

const fileName = `${config.exeName}-${subDirName}.${fileExtension}`;

const installDir = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName, subDirName);
Expand Down Expand Up @@ -271,13 +278,24 @@ async function installFromMirror(
/** Returns all locally installed versions */
export async function query(config: Config): Promise<semver.SemVer[]> {
const available: semver.SemVer[] = [];
const prefix = `${getZigOSName()}-${getZigArchName()}`;
const prefix = getHostZigName();

// Remove after some time has passed from the prefix change.
const prefixOld = `${getZigOSName()}-${getZigArchName()}`;

const storageDir = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName);
try {
for (const [name] of await vscode.workspace.fs.readDirectory(storageDir)) {
if (name.startsWith(prefix)) {
available.push(new semver.SemVer(name.substring(prefix.length + 1)));
} else if (name.startsWith(prefixOld)) {
const version = name.substring(prefixOld.length + 1);
await vscode.workspace.fs.rename(
vscode.Uri.joinPath(storageDir, name),
vscode.Uri.joinPath(storageDir, `${prefix}-${version}`),
);
await setLastAccessTime(config, new semver.SemVer(version));
available.push(new semver.SemVer(version));
Comment on lines +291 to +298
Copy link
Collaborator

Choose a reason for hiding this comment

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

This converts all installed Zig and ZLS versions from $OS-$Arch-$Version to $Arch-$OS-$Version but this isn't how installGuarded will try to look them up. It still expects the old format for ZLS and older Zig versions.

}
}
} catch (e) {
Expand All @@ -293,7 +311,7 @@ export async function query(config: Config): Promise<semver.SemVer[]> {
/** Set the last access time of the (installed) version. */
async function setLastAccessTime(config: Config, version: semver.SemVer): Promise<void> {
await config.context.globalState.update(
`${config.exeName}-last-access-time-${getZigOSName()}-${getZigArchName()}-${version.raw}`,
`${config.exeName}-last-access-time-${getHostZigName()}-${version.raw}`,
Date.now(),
);
}
Expand Down