Skip to content

Commit 9ffc387

Browse files
committed
Update ARM architecture name
1 parent 6235aa8 commit 9ffc387

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

common.js

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function getTarballName() {
116116
const version = await getVersion();
117117

118118
let arch = {
119-
arm: 'armv7a',
119+
arm: 'arm',
120120
arm64: 'aarch64',
121121
loong64: 'loongarch64',
122122
mips: 'mips',
@@ -137,6 +137,11 @@ async function getTarballName() {
137137
arch = 'powerpc64le';
138138
}
139139

140+
// Before 0.15.1, Zig used 'armv7a' as the arch name for ARM binaries.
141+
if (arch === 'arm' && versionLessThan(version, "0.15.1")) {
142+
arch = 'armv7a';
143+
}
144+
140145
const platform = {
141146
aix: 'aix',
142147
android: 'android',
@@ -148,45 +153,44 @@ async function getTarballName() {
148153
win32: 'windows',
149154
}[os.platform()];
150155

151-
if (useLegacyTarballName(version)) {
156+
// Before 0.14.1, Zig tarballs were named like 'zig-linux-x86_64-0.14.0', with the arch
157+
// and OS fields reversed from the order we use today.
158+
if (versionLessThan(version, "0.15.0-dev.631+9a3540d61") && versionLessThan(version, "0.14.1")) {
152159
return `zig-${platform}-${arch}-${version}`;
153-
} else {
154-
return `zig-${arch}-${platform}-${version}`;
155160
}
161+
162+
return `zig-${arch}-${platform}-${version}`;
156163
}
157-
// Before version 0.14.1 / dev version 0.15.0-dev.631+9a3540d61, Zig tarballs were named like:
158-
// `zig-linux-x86_64-0.14.0`
159-
// After that version, they are named like:
160-
// `zig-x86_64-linux-0.14.0`
161-
// So, the architecture and OS fields were flipped to align with how target triples work.
162-
function useLegacyTarballName(version) {
163-
// We are looking for full versions above
164-
const parts = version.split('.');
165-
if (parts.length == 3) {
166-
// We have a full version like '0.14.0'
167-
if (parts[0] !== "0") return false; // 1.x.x or greater
168-
if (parts[1] === "14" && parts[2] !== "0") return false; // 0.14.1 or greater
169-
const minor = parseInt(parts[1]);
170-
if (!Number.isFinite(minor)) return false; // malformed minor version
171-
if (minor >= 15) return false; // 0.15.x or greater
172-
return true; // 0.14.1
173-
} else if (parts.length == 4) {
174-
// We have a dev version like '0.15.0-dev.631+9a3540d61'
175-
if (parts[0] !== "0") return false; // 1.x.x or greater
176-
if (parts[1] === "15" && parts[2] == "0-dev") {
177-
const dev_version = parseInt(parts[3].split('+')[0]); // this is the '631' part in the example above
178-
if (!Number.isFinite(dev_version)) return false; // malformed dev version
179-
if (dev_version >= 631) return false; // 0.15.0-dev.631+9a3540d61 or greater
180-
return true; // 0.15.0-dev before the change
181-
}
182-
const minor = parseInt(parts[1]);
183-
if (!Number.isFinite(minor)) return false; // malformed minor version
184-
if (minor >= 15) return false; // 0.15.1-dev or greater (in practice this is 0.16.0-dev or greater)
185-
return true; // We caught 0.15.0-dev above, so this must be 0.14.x-dev or below.
186-
} else {
187-
// Malformed version
188-
return false;
189-
}
164+
165+
// Returns `true` if `cur_ver` represents a version less then (i.e. older than) `min_ver`.
166+
// Otherwise, returns `false`.
167+
// If `cur_ver` or `min_ver` is malformed, returns `false`.
168+
function versionLessThan(cur_ver, min_ver) {
169+
const cur = parseVersion(cur_ver);
170+
const min = parseVersion(min_ver);
171+
if (cur === null || min === null) return false;
172+
// Treating 0.1.2 as 0.1.2-dev+INF makes the comparisons easy!
173+
const cur_dev = cur.dev === null ? Infinity : cur.dev;
174+
const min_dev = min.dev === null ? Infinity : min.dev;
175+
176+
if (cur.major != min.major) return cur.major < min.major;
177+
if (cur.minor != min.minor) return cur.minor < min.minor;
178+
if (cur.patch != min.patch) return cur.patch < min.patch;
179+
return cur.dev < min.dev;
180+
}
181+
182+
// Returns object with keys 'major', 'minor', 'patch', and 'dev'.
183+
// 'dev' is `null` if `str` was not a dev version.
184+
// On failure, returns `null`.
185+
function parseVersion(str) {
186+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-dev\.(\d+)\+[0-9a-f]*)?$/.exec(str);
187+
if (match === null) return null;
188+
return {
189+
major: parseInt(match[0]),
190+
minor: parseInt(match[1]),
191+
patch: parseInt(match[2]),
192+
dev: match[3] === null ? null : parseInt(match[3]),
193+
};
190194
}
191195

192196
async function getTarballExt() {

0 commit comments

Comments
 (0)