mirror of
https://github.com/graalvm/setup-graalvm.git
synced 2025-01-19 03:43:02 +08:00
Introduce native-image-musl feature.
This commit is contained in:
parent
b1f65935b2
commit
778131f1d6
21
.github/workflows/test.yml
vendored
21
.github/workflows/test.yml
vendored
@ -71,8 +71,27 @@ jobs:
|
||||
java --version
|
||||
native-image.cmd --version
|
||||
if: runner.os == 'Windows'
|
||||
test-native-image-musl:
|
||||
name: native-image-musl on ubuntu-latest
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run setup-graalvm action
|
||||
uses: ./
|
||||
with:
|
||||
version: 'latest'
|
||||
java-version: '17'
|
||||
components: 'native-image'
|
||||
native-image-musl: 'true'
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build static HelloWorld image with Native Image and musl
|
||||
run: |
|
||||
echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
|
||||
javac HelloWorld.java
|
||||
native-image --static --libc=musl HelloWorld
|
||||
./helloworld
|
||||
test-additional:
|
||||
name: Extensive tests on ubuntu-latest
|
||||
name: extensive tests on ubuntu-latest
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -94,6 +94,8 @@ jobs:
|
||||
| `components` | `''` | Comma-spearated list of GraalVM components (e.g., `native-image` or `ruby,nodejs`) that will be installed by the [GraalVM Updater][gu]. |
|
||||
| `github-token` | `''` | Token for communication with the GitHub API. Please set to `${{ secrets.GITHUB_TOKEN }}` (see [templates](#templates)) to allow the action to authenticate with the GitHub API, which helps to reduce rate limiting issues. |
|
||||
| `set-java-home` | `'true'` | If set to `'true'`, instructs the action to set `$JAVA_HOME` to the path of the GraalVM installation. |
|
||||
| `native-image-musl` | `'false'` | If set to `'true'`, sets up [musl] for building [static images][native-image-static] with GraalVM Native Image *(Linux only)*. [Example usage][native-image-musl-build] (be sure to replace `uses: ./` with `uses: graalvm/setup-graalvm@v1`). |
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
@ -108,7 +110,10 @@ Only pull requests from committers that can be verified as having signed the OCA
|
||||
[mandrel]: https://github.com/graalvm/mandrel
|
||||
[mandrel-releases]: https://github.com/graalvm/mandrel/releases
|
||||
[mandrel-stable]: https://github.com/graalvm/mandrel/releases/latest
|
||||
[musl]: https://musl.libc.org/
|
||||
[native-image]: https://www.graalvm.org/native-image/
|
||||
[native-image-musl-build]: https://github.com/graalvm/setup-graalvm/blob/main/.github/workflows/test.yml
|
||||
[native-image-static]: https://github.com/oracle/graal/blob/fa6f4a974dedacf4688dcc430dd100849d9882f2/docs/reference-manual/native-image/StaticImages.md
|
||||
[oca]: https://oca.opensource.oracle.com
|
||||
[releases]: https://github.com/graalvm/graalvm-ce-builds/releases
|
||||
[repo]: https://github.com/oracle/graal
|
||||
|
10
action.yml
10
action.yml
@ -13,16 +13,20 @@ inputs:
|
||||
description: 'Java version (11 or 17, 8 or 16 for older releases).'
|
||||
components:
|
||||
required: false
|
||||
description: 'Comma-separated list of GraalVM components to be installed'
|
||||
description: 'Comma-separated list of GraalVM components to be installed.'
|
||||
default: ''
|
||||
github-token:
|
||||
required: false
|
||||
description: 'Set it to secrets.GITHUB_TOKEN to increase rate limits when accessing the GitHub API'
|
||||
description: 'Set it to secrets.GITHUB_TOKEN to increase rate limits when accessing the GitHub API.'
|
||||
default: ''
|
||||
set-java-home:
|
||||
required: false
|
||||
description: 'Set $JAVA_HOME to the GraalVM installation. Default: true'
|
||||
description: 'Set $JAVA_HOME to the GraalVM installation. Default: true.'
|
||||
default: 'true'
|
||||
native-image-musl:
|
||||
required: false
|
||||
description: 'Set up musl for static image building with GraalVM Native Image.'
|
||||
default: 'false'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
85
dist/index.js
generated
vendored
85
dist/index.js
generated
vendored
@ -7,9 +7,10 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.MANDREL_NAMESPACE = exports.JDK_HOME_SUFFIX = exports.GRAALVM_PLATFORM = exports.GRAALVM_GH_USER = exports.GRAALVM_FILE_EXTENSION = exports.GRAALVM_BASE = exports.VERSION_LATEST = exports.VERSION_DEV = exports.IS_WINDOWS = exports.IS_MACOS = void 0;
|
||||
exports.MANDREL_NAMESPACE = exports.JDK_HOME_SUFFIX = exports.GRAALVM_PLATFORM = exports.GRAALVM_GH_USER = exports.GRAALVM_FILE_EXTENSION = exports.GRAALVM_BASE = exports.VERSION_LATEST = exports.VERSION_DEV = exports.IS_WINDOWS = exports.IS_MACOS = exports.IS_LINUX = void 0;
|
||||
const os_1 = __nccwpck_require__(2037);
|
||||
const path_1 = __nccwpck_require__(1017);
|
||||
exports.IS_LINUX = process.platform === 'linux';
|
||||
exports.IS_MACOS = process.platform === 'darwin';
|
||||
exports.IS_WINDOWS = process.platform === 'win32';
|
||||
exports.VERSION_DEV = 'dev';
|
||||
@ -95,6 +96,81 @@ function setUpDependencies(components) {
|
||||
exports.setUpDependencies = setUpDependencies;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5938:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.setUpNativeImageMusl = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const tc = __importStar(__nccwpck_require__(7784));
|
||||
const constants_1 = __nccwpck_require__(5105);
|
||||
const exec_1 = __nccwpck_require__(1514);
|
||||
const os_1 = __nccwpck_require__(2037);
|
||||
const path_1 = __nccwpck_require__(1017);
|
||||
const io_1 = __nccwpck_require__(7436);
|
||||
function setUpNativeImageMusl() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!constants_1.IS_LINUX) {
|
||||
core.warning('musl is only supported on Linux');
|
||||
return;
|
||||
}
|
||||
core.startGroup(`Setting up musl for GraalVM Native Image...`);
|
||||
const basePath = (0, path_1.join)((0, os_1.homedir)(), '.musl_feature');
|
||||
yield (0, io_1.mkdirP)(basePath);
|
||||
const muslName = 'x86_64-linux-musl-native';
|
||||
const muslDownloadPath = yield tc.downloadTool(`http://more.musl.cc/10/x86_64-linux-musl/${muslName}.tgz`);
|
||||
yield tc.extractTar(muslDownloadPath, basePath);
|
||||
const muslPath = (0, path_1.join)(basePath, muslName);
|
||||
core.addPath((0, path_1.join)(muslPath, 'bin'));
|
||||
const zlibVersion = '1.2.11';
|
||||
const zlibDownloadPath = yield tc.downloadTool(`https://zlib.net/zlib-${zlibVersion}.tar.gz`);
|
||||
yield tc.extractTar(zlibDownloadPath, basePath);
|
||||
const zlibPath = (0, path_1.join)(basePath, `zlib-${zlibVersion}`);
|
||||
const zlibBuildOptions = {
|
||||
cwd: zlibPath,
|
||||
env: Object.assign(Object.assign({}, process.env), { CC: (0, path_1.join)(muslPath, 'bin', 'gcc') })
|
||||
};
|
||||
yield (0, exec_1.exec)('./configure', [`--prefix=${muslPath}`, '--static'], zlibBuildOptions);
|
||||
yield (0, exec_1.exec)('make', [], zlibBuildOptions);
|
||||
yield (0, exec_1.exec)('make', ['install'], { cwd: zlibPath });
|
||||
core.endGroup();
|
||||
});
|
||||
}
|
||||
exports.setUpNativeImageMusl = setUpNativeImageMusl;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1763:
|
||||
@ -276,6 +352,7 @@ const io_1 = __nccwpck_require__(7436);
|
||||
const dependencies_1 = __nccwpck_require__(6031);
|
||||
const gu_1 = __nccwpck_require__(3466);
|
||||
const mandrel_1 = __nccwpck_require__(438);
|
||||
const features_1 = __nccwpck_require__(5938);
|
||||
const msvc_1 = __nccwpck_require__(4765);
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@ -285,10 +362,14 @@ function run() {
|
||||
const componentsString = core.getInput('components');
|
||||
const components = 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) {
|
||||
(0, msvc_1.setUpWindowsEnvironment)();
|
||||
}
|
||||
(0, dependencies_1.setUpDependencies)(components);
|
||||
yield (0, dependencies_1.setUpDependencies)(components);
|
||||
if (enableNativeImageMusl) {
|
||||
yield (0, features_1.setUpNativeImageMusl)();
|
||||
}
|
||||
yield (0, io_1.mkdirP)(c.GRAALVM_BASE);
|
||||
// Download or build GraalVM
|
||||
let graalVMHome;
|
||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -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
47
src/features.ts
Normal 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()
|
||||
}
|
11
src/main.ts
11
src/main.ts
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user