libcnb.rs

libcnb.rs is a Rust language binding of the Cloud Native Buildpacks spec. It is a non-opinionated implementation adding language constructs and convenience methods for working with the spec. It values strong adherence to the spec and data formats.
Usage
Here's a quick start template that can be cloned.
View the examples for some buildpack samples.
All spec data files are implemented in the libcnb::data module.
libcnb::platform::Platform represents the /platform directory in the CNB spec.
Example Buildpack
A basic hello world buildpack looks like:
Detect
For /bin/detect, libcnb::detect::cnb_runtime_detect handles processing the arguments (made available through libcnb::detect::DetectContext and handling the lifecycle of the detect script (including exiting with libcnb::detect::DetectOutcome). This function will exit and write the build plan where applicable. The buildpack author is responsible for writing the FnOnce(DetectContext<P>) -> Result<DetectOutcome, E> where E: std::fmt::Display that libcnb::detect::cnb_runtime_detect] takes.
use libcnb::{
data::build_plan::BuildPlan,
detect::{DetectOutcome, GenericDetectContext},
};
use rust_cnb_starter::messages;
fn main() {
libcnb::detect::cnb_runtime_detect(detect)
}
fn detect(_context: GenericDetectContext) -> Result<DetectOutcome, std::io::Error> {
println!("/bin/detect is running!");
Ok(DetectOutcome::Pass(BuildPlan::new()))
}Build
For /bin/build, libcnb::build::cnb_runtime_build will handle processing the arguments and exiting. Arguments and layer creation can be found on libcnb::build::BuildContext. If an error is raised, libcnb::build::cnb_runtime_build will print out an error message and exit with an error status code. The buildpack author is responsible for defining a Fn(BuildContext<P>) -> Result<(), E> where E: std::fmt::Display, P: libcnb::platform::Platform.
use libcnb::build::GenericBuildContext;
use std::collections::HashMap;
fn main() {
libcnb::build::cnb_runtime_build(build);
}
fn build(context: GenericBuildContext) -> Result<(), std::io::Error> {
println!("/bin/build is running!");
println!("App source @ {:?}", context.app_dir);
Ok(())
}Installation
Add the following to your Cargo.toml file:
[dependencies]
libcnb = "0.1.0"Compiler support requires rustc 1.31+ for 2018 edition