Introduce native-image-musl feature.

This commit is contained in:
Fabio Niephaus
2022-01-20 17:49:45 +01:00
parent b1f65935b2
commit 778131f1d6
8 changed files with 172 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ import * as otypes from '@octokit/types'
import {homedir} from 'os'
import {join} from 'path'
export const IS_LINUX = process.platform === 'linux'
export const IS_MACOS = process.platform === 'darwin'
export const IS_WINDOWS = process.platform === 'win32'

47
src/features.ts Normal file
View File

@@ -0,0 +1,47 @@
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'
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'))
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')
}
}
await exec(
'./configure',
[`--prefix=${muslPath}`, '--static'],
zlibBuildOptions
)
await exec('make', [], zlibBuildOptions)
await exec('make', ['install'], {cwd: zlibPath})
core.endGroup()
}

View File

@@ -6,21 +6,26 @@ import {mkdirP} from '@actions/io'
import {setUpDependencies} from './dependencies'
import {setUpGUComponents} from './gu'
import {setUpMandrel} from './mandrel'
import {setUpNativeImageMusl} from './features'
import {setUpWindowsEnvironment} from './msvc'
async function run(): Promise<void> {
try {
const graalvmVersion: string = core.getInput('version', {required: true})
const javaVersion: string = core.getInput('java-version', {required: true})
const graalvmVersion = core.getInput('version', {required: true})
const javaVersion = core.getInput('java-version', {required: true})
const componentsString: string = core.getInput('components')
const components: string[] =
componentsString.length > 0 ? componentsString.split(',') : []
const setJavaHome = core.getInput('set-java-home') === 'true'
const enableNativeImageMusl = core.getInput('native-image-musl') === 'true'
if (c.IS_WINDOWS) {
setUpWindowsEnvironment()
}
setUpDependencies(components)
await setUpDependencies(components)
if (enableNativeImageMusl) {
await setUpNativeImageMusl()
}
await mkdirP(c.GRAALVM_BASE)