mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-03 13:58:28 +08:00
GraalVM native image build of psoserv.
This commit is contained in:
parent
74938bb253
commit
2a510ec116
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,4 +12,4 @@ build
|
||||
karma.config.generated.js
|
||||
|
||||
# Config
|
||||
/psoserv/*.conf
|
||||
/psoserv/psoserv.conf
|
||||
|
@ -1,5 +1,8 @@
|
||||
# Phantasmal PSO Server
|
||||
|
||||
This server is far from complete, the only functionality that works at the moment is the proxy
|
||||
server.
|
||||
|
||||
## Configuration
|
||||
|
||||
Put a psoserv.conf file in the directory where psoserv will run or pass
|
||||
@ -71,3 +74,22 @@ proxy: {
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Developers
|
||||
|
||||
## Building and Running
|
||||
|
||||
Build with `./gradlew :psoserv:build` or run with `./gradlew :psoserv:run`.
|
||||
|
||||
## Native Builds with GraalVM
|
||||
|
||||
You can create a native build using [GraalVM](https://www.graalvm.org/) by
|
||||
running `./gradlew :psoserv:nativeBuild`.
|
||||
|
||||
Prerequisites:
|
||||
|
||||
- Make sure the JAVA_HOME environment variable points to a GraalVM JDK
|
||||
- Install native-image with `gu` (the GraalVM updater tool)
|
||||
- Install necessary libraries on Linux
|
||||
- Install MSVC and use a x64 Native Tools Command Prompt for running gradle on Windows
|
||||
- See the [manual](https://www.graalvm.org/reference-manual/native-image/) for details
|
||||
|
@ -1,11 +1,47 @@
|
||||
import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask
|
||||
|
||||
plugins {
|
||||
id("world.phantasmal.jvm")
|
||||
kotlin("plugin.serialization")
|
||||
application
|
||||
id("org.graalvm.buildtools.native") version "0.9.2"
|
||||
}
|
||||
|
||||
val mainClassFqn = "world.phantasmal.psoserv.MainKt"
|
||||
val agentOutputDir = File(buildDir, "agent-output")
|
||||
|
||||
application {
|
||||
mainClass.set("world.phantasmal.psoserv.MainKt")
|
||||
mainClass.set(mainClassFqn)
|
||||
}
|
||||
|
||||
val nativeAgentRun by tasks.registering(JavaExec::class) {
|
||||
description = "Run with the GraalVM native-image-agent to produce reflection info etc. for the nativeBuild task."
|
||||
group = "application"
|
||||
|
||||
dependsOn(tasks.build)
|
||||
outputs.dir(agentOutputDir)
|
||||
|
||||
mainClass.set(mainClassFqn)
|
||||
classpath = sourceSets.main.get().runtimeClasspath
|
||||
jvmArgs = listOf("-agentlib:native-image-agent=config-output-dir=$agentOutputDir")
|
||||
args = listOf(
|
||||
"--nostart",
|
||||
"--config=graalvm-agent.conf",
|
||||
)
|
||||
}
|
||||
|
||||
nativeBuild {
|
||||
imageName.set("psoserv")
|
||||
mainClass.set(mainClassFqn)
|
||||
buildArgs.addAll(
|
||||
"--allow-incomplete-classpath",
|
||||
"-H:ConfigurationFileDirectories=$agentOutputDir",
|
||||
)
|
||||
}
|
||||
|
||||
tasks.withType<BuildNativeImageTask>().configureEach {
|
||||
dependsOn(nativeAgentRun)
|
||||
inputs.dir(agentOutputDir)
|
||||
}
|
||||
|
||||
val serializationVersion: String by project.extra
|
||||
|
30
psoserv/graalvm-agent.conf
Normal file
30
psoserv/graalvm-agent.conf
Normal file
@ -0,0 +1,30 @@
|
||||
patch: {}
|
||||
auth: {}
|
||||
account: {}
|
||||
ships: [
|
||||
{
|
||||
blocks: [block_1]
|
||||
},
|
||||
]
|
||||
blocks: [
|
||||
{
|
||||
name: block_1
|
||||
},
|
||||
]
|
||||
proxy: {
|
||||
remoteAddress: localhost
|
||||
servers: [
|
||||
{
|
||||
name: pc_proxy
|
||||
version: PC
|
||||
bindPort: 11000
|
||||
remotePort: 21000
|
||||
}
|
||||
{
|
||||
name: bb_proxy
|
||||
version: BB
|
||||
bindPort: 11001
|
||||
remotePort: 21001
|
||||
}
|
||||
]
|
||||
}
|
@ -32,18 +32,20 @@ fun main(args: Array<String>) {
|
||||
|
||||
// Try to get config file location from arguments first.
|
||||
var configFile: File? = null
|
||||
var start = true
|
||||
|
||||
// Parse arguments.
|
||||
for (arg in args) {
|
||||
val split = arg.split('=')
|
||||
val param = split[0]
|
||||
val value = split.getOrNull(1)
|
||||
|
||||
if (split.size == 2) {
|
||||
val (param, value) = split
|
||||
|
||||
when (param) {
|
||||
"--config" -> {
|
||||
configFile = File(value)
|
||||
}
|
||||
when (param) {
|
||||
"--config" -> {
|
||||
configFile = value?.let(::File)
|
||||
}
|
||||
"--nostart" -> {
|
||||
start = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,12 +77,16 @@ fun main(args: Array<String>) {
|
||||
val accountStore = AccountStore(LOGGER)
|
||||
val servers = initialize(config, accountStore)
|
||||
|
||||
if (servers.isEmpty()) {
|
||||
LOGGER.info { "No servers configured, stopping." }
|
||||
} else {
|
||||
LOGGER.info { "Starting up." }
|
||||
if (start) {
|
||||
if (servers.isEmpty()) {
|
||||
LOGGER.info { "No servers configured, stopping." }
|
||||
} else {
|
||||
LOGGER.info { "Starting up." }
|
||||
|
||||
servers.forEach(Server::start)
|
||||
servers.forEach(Server::start)
|
||||
}
|
||||
} else {
|
||||
LOGGER.info { "Not starting, configuration OK." }
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
LOGGER.error(e) { "Failed to start up." }
|
||||
|
@ -53,7 +53,7 @@ val copyAssemblyWorkerJsTask = tasks.register<Copy>("copyAssemblyWorkerJs") {
|
||||
}
|
||||
|
||||
// TODO: Figure out how to make this work with --continuous.
|
||||
tasks.getByName("processResources").dependsOn(copyAssemblyWorkerJsTask)
|
||||
tasks.named("processResources").configure { dependsOn(copyAssemblyWorkerJsTask) }
|
||||
|
||||
tasks.register<Copy>("generateAssets") {
|
||||
dependsOn(":web:assets-generation:generateAssets")
|
||||
|
Loading…
Reference in New Issue
Block a user