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' const TOOL_NAME = 'zig'
async function downloadZig (platform, version, useCache = true) { async function downloadZig (arch, platform, version, useCache = true) {
const ext = extForPlatform(platform) const ext = extForPlatform(platform)
const { downloadUrl, variantName, version: useVersion } = version.includes('+') const { downloadUrl, variantName, version: useVersion } = version.includes('+')
? resolveCommit(platform, version) ? resolveCommit(arch, platform, version)
: await resolveVersion(platform, version) : await resolveVersion(arch, platform, version)
const cachedPath = toolCache.find(TOOL_NAME, useVersion) const cachedPath = toolCache.find(TOOL_NAME, useVersion)
if (cachedPath) { if (cachedPath) {
@ -29,7 +29,7 @@ async function downloadZig (platform, version, useCache = true) {
const cacheKey = `${TOOL_NAME}-${variantName}` const cacheKey = `${TOOL_NAME}-${variantName}`
if (useCache) { 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}`) actions.info(`attempting restore of ${cacheKey} to ${restorePath}`)
const restoredKey = await cache.restoreCache([restorePath], cacheKey) const restoredKey = await cache.restoreCache([restorePath], cacheKey)
if (restoredKey) { if (restoredKey) {
@ -67,7 +67,7 @@ async function main () {
return 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 // Add the `zig` binary to the $PATH
actions.addPath(zigPath) actions.addPath(zigPath)

View File

@ -10,16 +10,25 @@ function extForPlatform (platform) {
}[platform] }[platform]
} }
function resolveCommit (platform, version) {
function resolveCommit (arch, platform, version) {
const ext = extForPlatform(platform) const ext = extForPlatform(platform)
const addrhost = { const resolvedOs = {
linux: 'linux-x86_64', linux: 'linux',
darwin: 'macos-x86_64', darwin: 'macos',
win32: 'windows-x86_64' win32: 'windows'
}[platform] }[platform]
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}` const resolvedArch = {
const variantName = `zig-${addrhost}-${version}` 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 } 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 ext = extForPlatform(platform)
const host = { const resolvedOs = {
linux: 'x86_64-linux', linux: 'linux',
darwin: 'x86_64-macos', darwin: 'macos',
win32: 'x86_64-windows' win32: 'windows'
}[platform] || platform }[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' }) const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })