diff --git a/index.js b/index.js index 6f55d2b..4e54cb1 100644 --- a/index.js +++ b/index.js @@ -14,12 +14,12 @@ const { const TOOL_NAME = 'zig' -async function downloadZig (platform, version, useCache = true) { +async function downloadZig (arch, platform, version, useCache = true) { const ext = extForPlatform(platform) const { downloadUrl, variantName, version: useVersion } = version.includes('+') - ? resolveCommit(platform, version) - : await resolveVersion(platform, version) + ? resolveCommit(arch, platform, version) + : await resolveVersion(arch, platform, version) const cachedPath = toolCache.find(TOOL_NAME, useVersion) if (cachedPath) { @@ -29,7 +29,7 @@ async function downloadZig (platform, version, useCache = true) { const cacheKey = `${TOOL_NAME}-${variantName}` if (useCache) { - const restorePath = path.join(process.env.RUNNER_TOOL_CACHE, TOOL_NAME, useVersion, os.arch()) + const restorePath = path.join(process.env.RUNNER_TOOL_CACHE, TOOL_NAME, useVersion, arch) actions.info(`attempting restore of ${cacheKey} to ${restorePath}`) const restoredKey = await cache.restoreCache([restorePath], cacheKey) if (restoredKey) { @@ -67,7 +67,7 @@ async function main () { return } - const zigPath = await downloadZig(os.platform(), version, useCache === 'true') + const zigPath = await downloadZig(os.arch(), os.platform(), version, useCache === 'true') // Add the `zig` binary to the $PATH actions.addPath(zigPath) diff --git a/versions.js b/versions.js index b4c962a..f1ab138 100644 --- a/versions.js +++ b/versions.js @@ -10,16 +10,25 @@ function extForPlatform (platform) { }[platform] } -function resolveCommit (platform, version) { + +function resolveCommit (arch, platform, version) { const ext = extForPlatform(platform) - const addrhost = { - linux: 'linux-x86_64', - darwin: 'macos-x86_64', - win32: 'windows-x86_64' + const resolvedOs = { + linux: 'linux', + darwin: 'macos', + win32: 'windows' }[platform] - const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}` - const variantName = `zig-${addrhost}-${version}` + const resolvedArch = { + arm: 'armv7a', + arm64: 'aarch64', + ppc64: 'powerpc64', + riscv64: 'riscv64', + x64: 'x86_64', + } [arch] + + const downloadUrl = `https://ziglang.org/builds/zig-${resolvedOs}-${resolvedArch}-${version}.${ext}` + const variantName = `zig-${resolvedOs}-${resolvedArch}-${version}` return { downloadUrl, variantName, version } } @@ -36,13 +45,23 @@ function getJSON (opts) { }) } -async function resolveVersion (platform, version) { +async function resolveVersion (arch, platform, version) { const ext = extForPlatform(platform) - const host = { - linux: 'x86_64-linux', - darwin: 'x86_64-macos', - win32: 'x86_64-windows' - }[platform] || platform + const resolvedOs = { + linux: 'linux', + darwin: 'macos', + win32: 'windows' + }[platform] + + const resolvedArch = { + arm: 'armv7a', + arm64: 'aarch64', + ppc64: 'powerpc64', + riscv64: 'riscv64', + x64: 'x86_64', + } [arch] + + const host = `${resolvedArch}-${resolvedOs}` const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })