Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 61dcbdb

Browse files
committed
resolve the correct tarball name for ZLS 0.15.0+ and arm
1 parent 557f841 commit 61dcbdb

File tree

4 files changed

+65
-65
lines changed

4 files changed

+65
-65
lines changed

src/versionManager.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import which from "which";
1212
import semver from "semver";
1313

1414
import * as minisign from "./minisign";
15-
import { getHostZigName, getVersion, getZigArchName, getZigOSName } from "./zigUtil";
15+
import * as zigUtil from "./zigUtil";
1616

1717
const execFile = util.promisify(childProcess.execFile);
1818
const chmod = util.promisify(fs.chmod);
@@ -69,7 +69,7 @@ export async function install(config: Config, version: semver.SemVer): Promise<s
6969

7070
async function installGuarded(config: Config, version: semver.SemVer): Promise<string> {
7171
const exeName = config.exeName + (process.platform === "win32" ? ".exe" : "");
72-
const subDirName = `${getHostZigName()}-${version.raw}`;
72+
const subDirName = `${getTargetName()}-${version.raw}`;
7373
const exeUri = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName, subDirName, exeName);
7474

7575
await setLastAccessTime(config, version);
@@ -145,7 +145,7 @@ async function installFromMirror(
145145

146146
const isWindows = process.platform === "win32";
147147
const exeName = config.exeName + (isWindows ? ".exe" : "");
148-
const subDirName = `${getHostZigName()}-${version.raw}`;
148+
const subDirName = `${getTargetName()}-${version.raw}`;
149149
const fileName = config.getArtifactName(version);
150150

151151
const installDir = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName, subDirName);
@@ -249,7 +249,7 @@ async function installFromMirror(
249249
} catch {}
250250
}
251251

252-
const exeVersion = getVersion(exeUri.fsPath, config.versionArg);
252+
const exeVersion = zigUtil.getVersion(exeUri.fsPath, config.versionArg);
253253
if (!exeVersion || exeVersion.compare(version) !== 0) {
254254
try {
255255
await vscode.workspace.fs.delete(installDir, { recursive: true, useTrash: false });
@@ -278,7 +278,7 @@ async function installFromMirror(
278278
/** Returns all locally installed versions */
279279
export async function query(config: Config): Promise<semver.SemVer[]> {
280280
const available: semver.SemVer[] = [];
281-
const prefix = getHostZigName();
281+
const prefix = getTargetName();
282282

283283
const storageDir = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName);
284284
try {
@@ -315,7 +315,7 @@ async function getTarExePath(): Promise<string | null> {
315315
/** Set the last access time of the (installed) version. */
316316
async function setLastAccessTime(config: Config, version: semver.SemVer): Promise<void> {
317317
await config.context.globalState.update(
318-
`${config.exeName}-last-access-time-${getHostZigName()}-${version.raw}`,
318+
`${config.exeName}-last-access-time-${getTargetName()}-${version.raw}`,
319319
Date.now(),
320320
);
321321
}
@@ -357,8 +357,8 @@ async function removeUnusedInstallations(config: Config) {
357357

358358
/** Remove after some time has passed from the prefix change. */
359359
export async function convertOldInstallPrefixes(config: Config): Promise<void> {
360-
const oldPrefix = `${getZigOSName()}-${getZigArchName()}`;
361-
const newPrefix = `${getZigArchName()}-${getZigOSName()}`;
360+
const oldPrefix = `${zigUtil.getZigOSName()}-${zigUtil.getZigArchName("armv7a")}`;
361+
const newPrefix = getTargetName();
362362

363363
const storageDir = vscode.Uri.joinPath(config.context.globalStorageUri, config.exeName);
364364
try {
@@ -386,3 +386,7 @@ export async function convertOldInstallPrefixes(config: Config): Promise<void> {
386386
}
387387
} catch {}
388388
}
389+
390+
function getTargetName(): string {
391+
return `${zigUtil.getZigArchName("armv7a")}-${zigUtil.getZigOSName()}`;
392+
}

src/zigSetup.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@ import semver from "semver";
77

88
import * as minisign from "./minisign";
99
import * as versionManager from "./versionManager";
10-
import {
11-
VersionIndex,
12-
ZigVersion,
13-
asyncDebounce,
14-
getHostZigName,
15-
getZigArchName,
16-
getZigOSName,
17-
resolveExePathAndVersion,
18-
workspaceConfigUpdateNoThrow,
19-
} from "./zigUtil";
10+
import * as zigUtil from "./zigUtil";
2011
import { ZigProvider } from "./zigProvider";
2112

2213
let statusItem: vscode.StatusBarItem;
@@ -41,7 +32,7 @@ async function installZig(context: vscode.ExtensionContext, temporaryVersion?: s
4132

4233
if (!version) {
4334
// Lookup zig in $PATH
44-
const result = resolveExePathAndVersion("zig", "version");
35+
const result = zigUtil.resolveExePathAndVersion("zig", "version");
4536
if ("exe" in result) {
4637
await vscode.workspace.getConfiguration("zig").update("path", undefined, true);
4738
zigProvider.set(result);
@@ -62,7 +53,7 @@ async function installZig(context: vscode.ExtensionContext, temporaryVersion?: s
6253
try {
6354
const exePath = await versionManager.install(versionManagerConfig, version);
6455
const zigConfig = vscode.workspace.getConfiguration("zig");
65-
await workspaceConfigUpdateNoThrow(zigConfig, "path", undefined, true);
56+
await zigUtil.workspaceConfigUpdateNoThrow(zigConfig, "path", undefined, true);
6657
zigProvider.set({ exe: exePath, version: version });
6758
} catch (err) {
6859
zigProvider.set(null);
@@ -116,21 +107,21 @@ async function getLatestTaggedZigVersion(context: vscode.ExtensionContext): Prom
116107
*
117108
* Throws an exception when no network connection is available.
118109
*/
119-
async function getVersions(): Promise<ZigVersion[]> {
110+
async function getVersions(): Promise<zigUtil.ZigVersion[]> {
120111
const [zigIndexJson, machIndexJson] = await Promise.all(
121112
["https://ziglang.org/download/index.json", "https://pkg.machengine.org/zig/index.json"].map(async (url) => {
122113
const response = await fetch(url);
123-
return response.json() as Promise<VersionIndex>;
114+
return response.json() as Promise<zigUtil.VersionIndex>;
124115
}),
125116
);
126117
const indexJson = { ...machIndexJson, ...zigIndexJson };
127118

128-
const hostName = getHostZigName();
129-
const result: ZigVersion[] = [];
119+
const result: zigUtil.ZigVersion[] = [];
130120
for (const [key, value] of Object.entries(indexJson)) {
131121
const name = key === "master" ? "nightly" : key;
132122
const version = new semver.SemVer(value.version ?? key);
133-
const release = value[hostName];
123+
const targetName = `${getZigArchName(version)}-${zigUtil.getZigOSName()}`;
124+
const release = value[targetName];
134125
if (release) {
135126
result.push({
136127
name: name,
@@ -144,13 +135,23 @@ async function getVersions(): Promise<ZigVersion[]> {
144135
}
145136
if (result.length === 0) {
146137
throw Error(
147-
`no pre-built Zig is available for your system '${hostName}', you can build it yourself using https://github.com/ziglang/zig-bootstrap`,
138+
`no pre-built Zig is available for your system '${zigUtil.getZigArchName("arm")}-${zigUtil.getZigOSName()}}', you can build it yourself using https://github.com/ziglang/zig-bootstrap`,
148139
);
149140
}
150141
sortVersions(result);
151142
return result;
152143
}
153144

145+
function getZigArchName(zigVersion: semver.SemVer): string {
146+
switch (zigVersion.compare(new semver.SemVer("0.15.0-dev.836+080ee25ec"))) {
147+
case -1:
148+
case 0:
149+
return zigUtil.getZigArchName("armv7a");
150+
case 1:
151+
return zigUtil.getZigArchName("arm");
152+
}
153+
}
154+
154155
function sortVersions(versions: { name?: string; version: semver.SemVer; isMach: boolean }[]) {
155156
versions.sort((lhs, rhs) => {
156157
// Mach versions except `mach-latest` move to the end
@@ -236,7 +237,7 @@ async function selectVersionAndInstall(context: vscode.ExtensionContext) {
236237
});
237238
}
238239

239-
const zigInPath = resolveExePathAndVersion("zig", "version");
240+
const zigInPath = zigUtil.resolveExePathAndVersion("zig", "version");
240241
if (!("message" in zigInPath)) {
241242
items.push({
242243
label: "Use Zig in PATH",
@@ -285,7 +286,7 @@ async function selectVersionAndInstall(context: vscode.ExtensionContext) {
285286
break;
286287
case "Use Zig in PATH":
287288
const zigConfig = vscode.workspace.getConfiguration("zig");
288-
await workspaceConfigUpdateNoThrow(zigConfig, "path", "zig", true);
289+
await zigUtil.workspaceConfigUpdateNoThrow(zigConfig, "path", "zig", true);
289290
break;
290291
case "Manually Specify Path":
291292
const uris = await vscode.window.showOpenDialog({
@@ -591,10 +592,10 @@ export async function setupZig(context: vscode.ExtensionContext) {
591592
const zigConfig = vscode.workspace.getConfiguration("zig");
592593
const zigPath = zigConfig.get<string>("path", "");
593594
if (zigPath.startsWith(context.globalStorageUri.fsPath)) {
594-
await workspaceConfigUpdateNoThrow(zigConfig, "path", undefined, true);
595+
await zigUtil.workspaceConfigUpdateNoThrow(zigConfig, "path", undefined, true);
595596
}
596597

597-
await workspaceConfigUpdateNoThrow(zigConfig, "initialSetupDone", undefined, true);
598+
await zigUtil.workspaceConfigUpdateNoThrow(zigConfig, "initialSetupDone", undefined, true);
598599

599600
await context.workspaceState.update("zig-version", undefined);
600601

@@ -668,9 +669,9 @@ export async function setupZig(context: vscode.ExtensionContext) {
668669
(version.prerelease.length === 0 && semver.gte(version, "0.14.1")) ||
669670
semver.gte(version, "0.15.0-dev.631+9a3540d61")
670671
) {
671-
return `zig-${getZigArchName()}-${getZigOSName()}-${version.raw}.${fileExtension}`;
672+
return `zig-${getZigArchName(version)}-${zigUtil.getZigOSName()}-${version.raw}.${fileExtension}`;
672673
} else {
673-
return `zig-${getZigOSName()}-${getZigArchName()}-${version.raw}.${fileExtension}`;
674+
return `zig-${zigUtil.getZigOSName()}-${getZigArchName(version)}-${version.raw}.${fileExtension}`;
674675
}
675676
},
676677
};
@@ -689,7 +690,7 @@ export async function setupZig(context: vscode.ExtensionContext) {
689690
const watcher1 = vscode.workspace.createFileSystemWatcher("**/.zigversion");
690691
const watcher2 = vscode.workspace.createFileSystemWatcher("**/build.zig.zon");
691692

692-
const refreshZigInstallation = asyncDebounce(async () => {
693+
const refreshZigInstallation = zigUtil.asyncDebounce(async () => {
693694
if (!vscode.workspace.getConfiguration("zig").get<string>("path")) {
694695
await installZig(context);
695696
} else {

src/zigUtil.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,22 @@ export async function shouldCheckUpdate(context: vscode.ExtensionContext, key: s
170170
return true;
171171
}
172172

173-
export function getZigArchName(): string {
173+
export function getZigArchName(armName: string): string {
174174
switch (process.arch) {
175175
case "ia32":
176176
return "x86";
177177
case "x64":
178178
return "x86_64";
179179
case "arm":
180-
return "armv7a";
180+
return armName;
181181
case "arm64":
182182
return "aarch64";
183183
case "ppc":
184184
return "powerpc";
185185
case "ppc64":
186186
return "powerpc64le";
187+
case "loong64":
188+
return "loongarch64";
187189
default:
188190
return process.arch;
189191
}
@@ -199,10 +201,6 @@ export function getZigOSName(): string {
199201
}
200202
}
201203

202-
export function getHostZigName(): string {
203-
return `${getZigArchName()}-${getZigOSName()}`;
204-
}
205-
206204
export function getVersion(
207205
filePath: string,
208206
/**

src/zls.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import semver from "semver";
1313

1414
import * as minisign from "./minisign";
1515
import * as versionManager from "./versionManager";
16-
import {
17-
getHostZigName,
18-
getZigArchName,
19-
getZigOSName,
20-
handleConfigOption,
21-
resolveExePathAndVersion,
22-
workspaceConfigUpdateNoThrow,
23-
} from "./zigUtil";
16+
import * as zigUtil from "./zigUtil";
2417
import { zigProvider } from "./zigSetup";
2518

2619
const ZIG_MODE = [
@@ -114,16 +107,16 @@ async function getZLSPath(context: vscode.ExtensionContext): Promise<{ exe: stri
114107
if (!!zlsExePath) {
115108
// This will fail on older ZLS version that do not support `zls --version`.
116109
// It should be more likely that the given executable is invalid than someone using ZLS 0.9.0 or older.
117-
const result = resolveExePathAndVersion(zlsExePath, "--version");
110+
const result = zigUtil.resolveExePathAndVersion(zlsExePath, "--version");
118111
if ("message" in result) {
119112
vscode.window
120113
.showErrorMessage(`Unexpected 'zig.zls.path': ${result.message}`, "install ZLS", "open settings")
121114
.then(async (response) => {
122115
switch (response) {
123116
case "install ZLS":
124117
const zlsConfig = vscode.workspace.getConfiguration("zig.zls");
125-
await workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
126-
await workspaceConfigUpdateNoThrow(zlsConfig, "path", undefined);
118+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
119+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "path", undefined);
127120
break;
128121
case "open settings":
129122
await vscode.commands.executeCommand("workbench.action.openSettings", "zig.zls.path");
@@ -179,7 +172,7 @@ function configurationMiddleware(params: ConfigurationParams): LSPAny[] | Respon
179172

180173
if (typeof value === "string") {
181174
// Make sure that `""` gets converted to `undefined` and resolve predefined values
182-
value = value ? handleConfigOption(value, workspaceFolder ?? "guess") : undefined;
175+
value = value ? zigUtil.handleConfigOption(value, workspaceFolder ?? "guess") : undefined;
183176
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
184177
// Recursively update the config options
185178
const newValue: Record<string, unknown> = {};
@@ -277,13 +270,13 @@ async function validateAdditionalOptions(): Promise<void> {
277270
switch (response) {
278271
case `Use ${optionName} instead`:
279272
const { [optionName]: newValue, ...updatedAdditionalOptions } = additionalOptions;
280-
await workspaceConfigUpdateNoThrow(
273+
await zigUtil.workspaceConfigUpdateNoThrow(
281274
configuration,
282275
"additionalOptions",
283276
Object.keys(updatedAdditionalOptions).length ? updatedAdditionalOptions : undefined,
284277
true,
285278
);
286-
await workspaceConfigUpdateNoThrow(configuration, section, newValue, true);
279+
await zigUtil.workspaceConfigUpdateNoThrow(configuration, section, newValue, true);
287280
break;
288281
case "Show zig.zls.additionalOptions":
289282
await vscode.commands.executeCommand("workbench.action.openSettingsJson", {
@@ -367,19 +360,20 @@ async function fetchVersion(
367360
void vscode.window.showErrorMessage(`Unable to fetch ZLS: ${response.message as string}`);
368361
return null;
369362
}
363+
const version = new semver.SemVer(response.version);
364+
const armName = semver.gte(version, "0.15.0") ? "arm" : "armv7a";
365+
const targetName = `${zigUtil.getZigArchName(armName)}-${zigUtil.getZigOSName()}`;
370366

371-
const hostName = getHostZigName();
372-
373-
if (!(hostName in response)) {
367+
if (!(targetName in response)) {
374368
void vscode.window.showErrorMessage(
375369
`A prebuilt ZLS ${response.version} binary is not available for your system. You can build it yourself with https://github.com/zigtools/zls#from-source`,
376370
);
377371
return null;
378372
}
379373

380374
return {
381-
version: new semver.SemVer(response.version),
382-
artifact: response[hostName] as ArtifactEntry,
375+
version: version,
376+
artifact: response[targetName] as ArtifactEntry,
383377
};
384378
}
385379

@@ -401,10 +395,10 @@ async function isEnabled(): Promise<boolean> {
401395
);
402396
switch (response) {
403397
case "Yes":
404-
await workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
398+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
405399
return true;
406400
case "No":
407-
await workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "off", true);
401+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "off", true);
408402
return false;
409403
case undefined:
410404
return false;
@@ -455,8 +449,8 @@ export async function activate(context: vscode.ExtensionContext) {
455449
const zlsConfig = vscode.workspace.getConfiguration("zig.zls");
456450
const zlsPath = zlsConfig.get<string>("path", "");
457451
if (zlsPath.startsWith(context.globalStorageUri.fsPath)) {
458-
await workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
459-
await workspaceConfigUpdateNoThrow(zlsConfig, "path", undefined, true);
452+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
453+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "path", undefined, true);
460454
}
461455
}
462456

@@ -475,7 +469,10 @@ export async function activate(context: vscode.ExtensionContext) {
475469
},
476470
getArtifactName(version) {
477471
const fileExtension = process.platform === "win32" ? "zip" : "tar.xz";
478-
return `zls-${getZigOSName()}-${getZigArchName()}-${version.raw}.${fileExtension}`;
472+
const targetName = semver.gte(version, "0.15.0")
473+
? `${zigUtil.getZigArchName("arm")}-${zigUtil.getZigOSName()}`
474+
: `${zigUtil.getZigOSName()}-${zigUtil.getZigArchName("armv7a")}`;
475+
return `zls-${targetName}-${version.raw}.${fileExtension}`;
479476
},
480477
};
481478

@@ -492,14 +489,14 @@ export async function activate(context: vscode.ExtensionContext) {
492489
statusItem,
493490
vscode.commands.registerCommand("zig.zls.enable", async () => {
494491
const zlsConfig = vscode.workspace.getConfiguration("zig.zls");
495-
await workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
492+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
496493
}),
497494
vscode.commands.registerCommand("zig.zls.stop", async () => {
498495
await stopClient();
499496
}),
500497
vscode.commands.registerCommand("zig.zls.startRestart", async () => {
501498
const zlsConfig = vscode.workspace.getConfiguration("zig.zls");
502-
await workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
499+
await zigUtil.workspaceConfigUpdateNoThrow(zlsConfig, "enabled", "on", true);
503500
await restartClient(context);
504501
}),
505502
vscode.commands.registerCommand("zig.zls.openOutput", () => {

0 commit comments

Comments
 (0)