module embed
module lib/embed.mu
import "embed"
embed provides compile-time asset embedding.
The file macro reads a source-relative file on the build machine and expands to a string literal holding its bytes. The resulting program has no runtime dependency on the source asset.
Imports
Macros
file#
file(path) expands to a string literal holding the contents of path, read at COMPILE time and resolved relative to the source file the macro is written in -- not to the working directory of the program that runs.
css := embed.file("assets/site.css")
The produced program carries the bytes and has no runtime dependency on the asset, which is what makes a single native binary self-contained. A path that is not a string literal, or a file that cannot be read, is a compile error rather than a runtime one.
Source lib/embed.mu:98
macro.define("file", fn(path_node) {
resolved := _resolve_path(path_node)
if is_error(resolved) {
return resolved
}
data := io.read_file(resolved)
if is_error(data) {
return _embed_error(resolved + ": " + inspect(data))
}
return quote { unquote data }
})Internal helpers
Underscore-prefixed names are implementation detail. They are listed so the module's source reads without surprises, not as API — they may change at any time.
| _embed_error(message) | — |
| _literal_path(node) | — |
| _resolve_path(node) | — |
| _source_file(node) | — |
| _validate_relative(rel) | — |