Skip to content

Repository files navigation

EmbedRaw

EmbedRaw embeds a directory of files into a Linux x64 Kotlin/Native executable.

Modules

  • 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.

Plugin setup

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.

Reading resources

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"]

Ktor SPA

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.

About

EmbedRaw embeds a directory of files into a Linux x64 Kotlin/Native executable.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages