@@ -3,9 +3,14 @@ import * as core from '@actions/core'
33import * as tc from '@actions/tool-cache'
44import { exec } from '../utils'
55import { join } from 'path'
6+ import { homedir } from 'os'
7+ import { promises as fs } from 'fs'
68
7- const MUSL_NAME = 'x86_64-linux-musl-native'
8- const MUSL_VERSION = '10.2.1'
9+ const MUSL_NAME = 'musl-gcc'
10+ const MUSL_VERSION = '1.2.4'
11+ const ZLIB_VERSION = '1.2.13'
12+
13+ // Build instructions: https://github.com/oracle/graal/blob/6dab549194b85252f88bda4ee825762d8b02c687/docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md?plain=1#L38-L67
914
1015export async function setUpNativeImageMusl ( ) : Promise < void > {
1116 if ( ! c . IS_LINUX ) {
@@ -14,38 +19,55 @@ export async function setUpNativeImageMusl(): Promise<void> {
1419 }
1520 let toolPath = tc . find ( MUSL_NAME , MUSL_VERSION )
1621 if ( toolPath ) {
17- core . info ( `Found ${ MUSL_NAME } ${ MUSL_VERSION } in tool-cache @ ${ toolPath } ` )
22+ core . info ( `Found musl ${ MUSL_VERSION } in tool-cache @ ${ toolPath } ` )
1823 } else {
19- core . startGroup ( `Setting up musl for GraalVM Native Image...` )
24+ core . startGroup ( `Building musl with zlib for GraalVM Native Image...` )
25+ // Build musl
26+ const muslHome = join ( homedir ( ) , 'musl-toolchain' )
2027 const muslDownloadPath = await tc . downloadTool (
21- `https://github.com/graalvm/setup-graalvm/ releases/download/x86_64-linux- musl-${ MUSL_VERSION } / ${ MUSL_NAME } .tgz `
28+ `https://musl.libc.org/ releases/musl-${ MUSL_VERSION } .tar.gz `
2229 )
2330 const muslExtractPath = await tc . extractTar ( muslDownloadPath )
24- const muslPath = join ( muslExtractPath , MUSL_NAME )
25-
26- const zlibCommit = 'ec3df00224d4b396e2ac6586ab5d25f673caa4c2'
31+ const muslPath = join ( muslExtractPath , `musl-${ MUSL_VERSION } ` )
32+ const muslBuildOptions = { cwd : muslPath }
33+ await exec (
34+ './configure' ,
35+ [ `--prefix=${ muslHome } ` , '--static' ] ,
36+ muslBuildOptions
37+ )
38+ await exec ( 'make' , [ ] , muslBuildOptions )
39+ await exec ( 'make' , [ 'install' ] , muslBuildOptions )
40+ const muslGCC = join ( muslHome , 'bin' , MUSL_NAME )
41+ await fs . symlink (
42+ muslGCC ,
43+ join ( muslHome , 'bin' , 'x86_64-linux-musl-gcc' ) ,
44+ 'file'
45+ )
46+ // Build zlib
2747 const zlibDownloadPath = await tc . downloadTool (
28- `https://github.com/madler /zlib/archive/ ${ zlibCommit } .tar.gz`
48+ `https://zlib.net/fossils /zlib- ${ ZLIB_VERSION } .tar.gz`
2949 )
3050 const zlibExtractPath = await tc . extractTar ( zlibDownloadPath )
31- const zlibPath = join ( zlibExtractPath , `zlib-${ zlibCommit } ` )
51+ const zlibPath = join ( zlibExtractPath , `zlib-${ ZLIB_VERSION } ` )
3252 const zlibBuildOptions = {
3353 cwd : zlibPath ,
3454 env : {
3555 ...process . env ,
36- CC : join ( muslPath , 'bin' , 'gcc' )
56+ CC : muslGCC
3757 }
3858 }
3959 await exec (
4060 './configure' ,
41- [ `--prefix=${ muslPath } ` , '--static' ] ,
61+ [ `--prefix=${ muslHome } ` , '--static' ] ,
4262 zlibBuildOptions
4363 )
4464 await exec ( 'make' , [ ] , zlibBuildOptions )
4565 await exec ( 'make' , [ 'install' ] , { cwd : zlibPath } )
46-
47- core . info ( `Adding ${ MUSL_NAME } ${ MUSL_VERSION } to tool-cache ...` )
48- toolPath = await tc . cacheDir ( muslPath , MUSL_NAME , MUSL_VERSION )
66+ // Store in cache
67+ core . info (
68+ `Adding musl ${ MUSL_VERSION } with zlib ${ ZLIB_VERSION } to tool-cache ...`
69+ )
70+ toolPath = await tc . cacheDir ( muslHome , MUSL_NAME , MUSL_VERSION )
4971 core . endGroup ( )
5072 }
5173 core . addPath ( join ( toolPath , 'bin' ) )
0 commit comments