rustolio-build-utils 0.1.0

Build Utilities to use in the build.rs for the rustolio framework
Documentation
//
// SPDX-License-Identifier: MPL-2.0
//
// Copyright (c) 2026 Tobias Binnewies. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

use std::{
    env,
    path::{Component, PathBuf},
};

use rustolio_utils::prelude::*;

use crate::Result;

pub fn manifest_dir() -> Result<PathBuf> {
    Ok(PathBuf::from(
        env::var("CARGO_MANIFEST_DIR").context("CARGO_MANIFEST_DIR not set")?,
    ))
}

pub fn static_dir() -> Result<PathBuf> {
    let dir = manifest_dir()?.join("static");
    Ok(dir)
}

pub fn pkg_dir() -> Result<PathBuf> {
    let dir = manifest_dir()?.join("pkg");
    Ok(dir)
}

pub fn out_dir() -> Result<PathBuf> {
    Ok(env::var("OUT_DIR").context("OUT_DIR not set")?.into())
}

pub fn target_dir() -> Result<PathBuf> {
    let out_dir: PathBuf = out_dir()?;
    let mut target = PathBuf::new();
    for dir in out_dir.components() {
        target.push(dir);
        if matches!(dir, Component::Normal(d) if d == "target") {
            break;
        }
    }
    Ok(target)
}

pub fn web_build_dir() -> Result<PathBuf> {
    Ok(target_dir()?.join("rustolio-web-build"))
}

pub fn tmp_dir() -> Result<PathBuf> {
    Ok(target_dir()?.join("tmp"))
}