Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Build {
/// Represents the artifacts produced by the build process.
#[derive(Clone, Debug)]
pub struct Artifacts {
root_dir: PathBuf,
include_dir: PathBuf,
lib_dir: PathBuf,
libs: Vec<String>,
Expand Down Expand Up @@ -254,6 +255,7 @@ impl Build {
}

Ok(Artifacts {
root_dir: out_dir.clone(),
include_dir,
lib_dir,
libs,
Expand Down Expand Up @@ -284,6 +286,11 @@ impl Version {
}

impl Artifacts {
/// Returns the directory containing the `include` and `lib` directories.
pub fn root_dir(&self) -> &Path {
&self.root_dir
}

/// Returns the directory containing the Lua headers.
pub fn include_dir(&self) -> &Path {
&self.include_dir
Expand All @@ -309,6 +316,17 @@ impl Artifacts {
println!("cargo:rustc-link-lib=static:-bundle={lib}");
}
}

/// Prints the necessary Cargo metadata such that dependent build scripts
/// can find the Lua install root and include directories in their
/// `DEP_LUA_ROOT` and `DEP_LUA_INCLUDE` environment variables.
///
/// This method is typically called in a build script to inform Cargo
/// about the Lua install location.
pub fn print_cargo_root(&self) {
println!("cargo:root={}", self.root_dir().display());
println!("cargo:include={}", self.include_dir().display());
}
}

trait ErrorContext<T> {
Expand Down