Skip to content

Commit

Permalink
Better handle architecture, fixes macOS silicon support (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgmbb authored Apr 26, 2024
1 parent 4f12c90 commit ef1fbe2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 32 additions & 13 deletions versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -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' })

Expand Down

0 comments on commit ef1fbe2

Please sign in to comment.