Skip to main content

source

Macro source 

Source
macro_rules! source {
    ($path:literal $(, $key:ident = $val:expr)* $(,)?) => { ... };
}
Expand description

Produce a Source from a literal path, hashed at compile time.

The path string itself never appears in the final binary. Paths are relative to the project root as seen by the build tool.

Accepts optional build-time-only keyword arguments; the values are parsed by the build tool’s scanner (not used at runtime). Supported keys:

  • ignore = ["glob", ...] — extra glob patterns applied when gathering a directory, merged with the CLI-level --ignore list.
  • features = ["name", ...] — cargo-feature gate. The source is only embedded when at least one of the listed features is enabled via installrs --feature <name>.
i.file(installrs::source!("assets/config.toml"), "etc/myapp/config.toml")
    .install()?;
i.dir(source!("assets", ignore = ["*.bak", "scratch"]), "assets").install()?;
i.file(source!("pro.dat", features = ["pro"]), "pro.dat").install()?;