Skip to content

Commit 7dccf5e

Browse files
committed
fix: handle new tarball name format as of 0.14.1
1 parent aa9ad5c commit 7dccf5e

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

common.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,45 @@ async function getTarballName() {
142142
win32: 'windows',
143143
}[os.platform()];
144144

145-
return `zig-${platform}-${arch}-${version}`;
145+
if (useLegacyTarballName(version)) {
146+
return `zig-${platform}-${arch}-${version}`;
147+
} else {
148+
return `zig-${arch}-${platform}-${version}`;
149+
}
150+
}
151+
// Before version 0.14.1 / dev version 0.15.0-dev.631+9a3540d61, Zig tarballs were named like:
152+
// `zig-linux-x86_64-0.14.0`
153+
// After that version, they are named like:
154+
// `zig-x86_64-linux-0.14.0`
155+
// So, the architecture and OS fields were flipped to align with how target triples work.
156+
function useLegacyTarballName(version) {
157+
// We are looking for full versions above
158+
const parts = version.split('.');
159+
if (parts.length == 3) {
160+
// We have a full version like '0.14.0'
161+
if (parts[0] !== "0") return false; // 1.x.x or greater
162+
if (parts[1] === "14" && parts[2] !== "0") return false; // 0.14.1 or greater
163+
const minor = parseInt(parts[1]);
164+
if (!Number.isFinite(minor)) return false; // malformed minor version
165+
if (minor >= 15) return false; // 0.15.x or greater
166+
return true; // 0.14.1
167+
} else if (parts.length == 4) {
168+
// We have a dev version like '0.15.0-dev.631+9a3540d61'
169+
if (parts[0] !== "0") return false; // 1.x.x or greater
170+
if (parts[1] === "15" && parts[2] == "0-dev") {
171+
const dev_version = parseInt(parts[3].split('+')[0]); // this is the '631' part in the example above
172+
if (!Number.isFinite(dev_version)) return false; // malformed dev version
173+
if (dev_version >= 631) return false; // 0.15.0-dev.631+9a3540d61 or greater
174+
return true; // 0.15.0-dev before the change
175+
}
176+
const minor = parseInt(parts[1]);
177+
if (!Number.isFinite(minor)) return false; // malformed minor version
178+
if (minor >= 15) return false; // 0.15.1-dev or greater (in practice this is 0.16.0-dev or greater)
179+
return true; // We caught 0.15.0-dev above, so this must be 0.14.x-dev or below.
180+
} else {
181+
// Malformed version
182+
return false;
183+
}
146184
}
147185

148186
async function getTarballExt() {

0 commit comments

Comments
 (0)