Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handle architecture #68

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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