Skip to main content

rl_lang/tooling/
dev.rs

1use serde::Deserialize;
2
3/// Represents the full `rl.toml` project manifest.
4#[derive(Deserialize)]
5pub struct RlToml {
6    pub project: Project,
7}
8
9/// The `[project]` section of `rl.toml`.
10#[derive(Deserialize)]
11pub struct Project {
12    /// The project name.
13    pub name: String,
14    /// The project version string (e.g. `"0.1.0"`).
15    pub version: String,
16    /// Path to the entry point relative to the project root (e.g. `"src/main.rl"`).
17    pub entry: String,
18}
19
20/// Reads and parses `rl.toml` from the current directory.
21///
22/// Exits with code `1` if:
23/// - `rl.toml` is not found in the current directory
24/// - the file content is not valid TOML or doesn't match [`RlToml`]
25pub fn read_rl_toml() -> RlToml {
26    let content = std::fs::read_to_string("rl.toml").unwrap_or_else(|_| {
27        eprintln!("error: no rl.toml found in current directory");
28        std::process::exit(1);
29    });
30
31    toml::from_str(&content).unwrap_or_else(|e| {
32        eprintln!("error: invalid rl.toml - {}", e);
33        std::process::exit(1);
34    })
35}