Skip to content

Commit

Permalink
Cache musl setup in GitHub tool-cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Mar 1, 2022
1 parent 66dc2bf commit a02f4df
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 55 deletions.
49 changes: 27 additions & 22 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

69 changes: 37 additions & 32 deletions src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,51 @@ import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import {IS_LINUX} from './constants'
import {exec} from '@actions/exec'
import {homedir} from 'os'
import {join} from 'path'
import {mkdirP} from '@actions/io'

const MUSL_NAME = 'x86_64-linux-musl-native'
const MUSL_VERSION = '10.2.1'

export async function setUpNativeImageMusl(): Promise<void> {
if (!IS_LINUX) {
core.warning('musl is only supported on Linux')
return
}
core.startGroup(`Setting up musl for GraalVM Native Image...`)
const basePath = join(homedir(), '.musl_feature')
await mkdirP(basePath)

const muslName = 'x86_64-linux-musl-native'
const muslDownloadPath = await tc.downloadTool(
`http://more.musl.cc/10/x86_64-linux-musl/${muslName}.tgz`
)
await tc.extractTar(muslDownloadPath, basePath)
const muslPath = join(basePath, muslName)
core.addPath(join(muslPath, 'bin'))
let toolPath = tc.find(MUSL_NAME, MUSL_VERSION)
if (toolPath) {
core.info(`Found ${MUSL_NAME} ${MUSL_VERSION} in tool-cache @ ${toolPath}`)
} else {
core.startGroup(`Setting up musl for GraalVM Native Image...`)
const muslDownloadPath = await tc.downloadTool(
`http://more.musl.cc/10/x86_64-linux-musl/${MUSL_NAME}.tgz`
)
const muslExtractPath = await tc.extractTar(muslDownloadPath)
const muslPath = join(muslExtractPath, MUSL_NAME)

const zlibVersion = '1.2.11'
const zlibDownloadPath = await tc.downloadTool(
`https://zlib.net/zlib-${zlibVersion}.tar.gz`
)
await tc.extractTar(zlibDownloadPath, basePath)
const zlibPath = join(basePath, `zlib-${zlibVersion}`)
const zlibBuildOptions = {
cwd: zlibPath,
env: {
...process.env,
CC: join(muslPath, 'bin', 'gcc')
const zlibVersion = '1.2.11'
const zlibDownloadPath = await tc.downloadTool(
`https://zlib.net/zlib-${zlibVersion}.tar.gz`
)
const zlibExtractPath = await tc.extractTar(zlibDownloadPath)
const zlibPath = join(zlibExtractPath, `zlib-${zlibVersion}`)
const zlibBuildOptions = {
cwd: zlibPath,
env: {
...process.env,
CC: join(muslPath, 'bin', 'gcc')
}
}
await exec(
'./configure',
[`--prefix=${muslPath}`, '--static'],
zlibBuildOptions
)
await exec('make', [], zlibBuildOptions)
await exec('make', ['install'], {cwd: zlibPath})

core.info(`Adding ${MUSL_NAME} ${MUSL_VERSION} to tool-cache ...`)
toolPath = await tc.cacheDir(muslPath, MUSL_NAME, MUSL_VERSION)
core.endGroup()
}
await exec(
'./configure',
[`--prefix=${muslPath}`, '--static'],
zlibBuildOptions
)
await exec('make', [], zlibBuildOptions)
await exec('make', ['install'], {cwd: zlibPath})
core.endGroup()
core.addPath(join(toolPath, 'bin'))
}

0 comments on commit a02f4df

Please sign in to comment.