#pkl #configuration-language #apple #codegen

rpkl

Bindings and codegen for Apple's Pkl configuration language

10 unstable releases (3 breaking)

new 0.4.1 Feb 17, 2025
0.3.5 Nov 13, 2024
0.3.0 Jul 23, 2024

#112 in Configuration

Download history 155/week @ 2024-10-30 113/week @ 2024-11-06 340/week @ 2024-11-13 292/week @ 2024-11-20 425/week @ 2024-11-27 222/week @ 2024-12-04 126/week @ 2024-12-11 138/week @ 2024-12-18 181/week @ 2024-12-25 311/week @ 2025-01-01 359/week @ 2025-01-08 422/week @ 2025-01-15 844/week @ 2025-01-22 603/week @ 2025-01-29 510/week @ 2025-02-05 865/week @ 2025-02-12

2,889 downloads per month
Used in 10 crates (4 directly)

MIT license

135KB
3.5K SLoC

rpkl

crates.io docs.rs

Language bindings to Pkl for Rust.

Requires the pkl binary to be available on your path. You can install pkl for your os using the steps from their docs: https://pkl-lang.org/main/current/pkl-cli/index.html#installation

Usage

ip = "127.0.0.1"

database {
    username = "admin"
    password = "secret"
}
#[derive(Deserialize)]
struct Config {
    ip: String,
    database: Database,
}

#[derive(Deserialize)]
struct Database {
    username: String,
    password: String,
}

let config: Config = rpkl::from_config("./config.pkl")?;

Evaluator Options

You can pass options to the evaluator, such as properties, by using from_config_with_options.

username = read("prop:username")
password = read("prop:password")
let options = EvaluatorOptions::default()
.properties([("username", "root"), ("password", "password123")]);

let config: Config = rpkl::from_config_with_options("./config.pkl", Some(options))?;

Codegen

Mostly works, but still a WIP. If you want to try it out, you can enable the codegen feature.

let mut evaluator = rpkl::evaluator::Evaluator::new()?;
let pkl_mod = evaluator.evaluate_module(PathBuf::from("./config.pkl"))?;
pkl_mod.codegen()?;

Dependencies

~0.8–7.5MB
~55K SLoC