Better handle architecture, fixes macOS silicon support (#68)

This commit is contained in:
David 2024-04-26 01:39:29 -06:00 committed by GitHub
parent 4f12c907f3
commit ef1fbe2694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 18 deletions

View File

@ -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)

View File

@ -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' })