Browse the docs

silk.build.source.

Files of the package read while it compiles: shaders, tables and other data the program keeps as part of its code.

When to use#

Use Source.read for a file's bytes and Source.text for UTF-8 text, from runtime code or from a static fn that parses the file while the package compiles. Use silk.system.filesystem for files the program reads when it runs.

Details#

The path is relative to the directory that holds the package's silk.toml, uses / separators and has no . or .. segment, so a package reads only its own files. Write it as a string literal in the call: the build finds the files a package reads from those literals. The file's contents become a constant of the program. Editing the file rebuilds only the functions that read it.

Examples#

Embed a shader#

silk
import silk.build.source { Source }

pub fn sceneShader() -> &'static [u8] {
  return Source.read("shaders/scene.wgsl")
}

Import as Source with import silk.build.source { Source }.

Public declarations: 1.

Source#

silk
pub struct Source

The owner type of the package file reads. It has no fields and is never constructed.

Details#

Each operation is static: runtime code that calls one receives its result as a constant.

Implementation Source#

silk
impl Source

Associated function read#

silk
pub static fn read(path: string<'static>) -> &'static [u8]

Returns the bytes of the package file at path.

Gotchas#

A path that leaves the package, or names no file, is a compile error at the call.

Associated function text#

silk
pub static fn text(path: string<'static>) -> string<'static>

Returns the text of the package file at path.

Gotchas#

A file that is not valid UTF-8 is a compile error at the call, as is a path that leaves the package or names no file.

Category: Core.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page