EmbedRaw embeds a directory of files into a Linux x64 Kotlin/Native executable.
- Gradle plugin:
io.github.sgpublic.embed-raw - Core library:
io.github.sgpublic:embed-raw-core - Ktor extension:
io.github.sgpublic:embed-raw-ktor
The first release supports linuxX64 only.
plugins {
id("io.github.sgpublic.embed-raw") version "0.1.0-SNAPSHOT"
}
kotlin {
linuxX64 {
compilations.named("main") {
cinterops.create("embedRaw") {
defFile(layout.buildDirectory.file("embedRaw/web.def").get().asFile)
}
}
binaries.executable {
linkerOpts(layout.buildDirectory.file("embedRaw/web.o").get().asFile.absolutePath)
}
}
}
embedRaw {
sourceDirectory.set(layout.projectDirectory.dir("web"))
baseName.set("web")
}The plugin wires the generated cinterop and executable link tasks to generateEmbedRawInterop and embedRaw.
import embedRaw._binary_web_bin_start
import io.github.sgpublic.embedraw.embeddedRawResources
val resources = embeddedRawResources(_binary_web_bin_start ?: error("Embedded resources unavailable"))
val index = resources["index.html"]routing {
spa(resources) {
filesPath = "/"
index = "index.html"
}
}spa serves files containing an extension and returns the index file for extensionless paths, enabling client-side routing.