1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Most of libcnb's public API returns user-provided errors, making error docs redundant.
// This lint is too noisy and enforces a style that reduces readability in many cases.
// Internals that need to be public for macros
pub use Buildpack;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
/// Provides types for CNB data formats. Is a re-export of the `libcnb-data` crate.
pub use libcnb_data as data;
const LIBCNB_SUPPORTED_BUILDPACK_API: BuildpackApi =
BuildpackApi ;
/// Generates a main function for the given buildpack.
///
/// It will create the main function and wires up the buildpack to the framework.
///
/// # Example:
/// ```
/// use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
/// use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder};
/// use libcnb::generic::{GenericError, GenericMetadata, GenericPlatform};
/// use libcnb::{buildpack_main, Buildpack};
///
/// pub(crate) struct MyBuildpack;
///
/// impl Buildpack for MyBuildpack {
/// type Platform = GenericPlatform;
/// type Metadata = GenericMetadata;
/// type Error = GenericError;
///
/// fn detect(&self, context: DetectContext<Self>) -> libcnb::Result<DetectResult, Self::Error> {
/// DetectResultBuilder::pass().build()
/// }
///
/// fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
/// BuildResultBuilder::new().build()
/// }
/// }
///
/// buildpack_main!(MyBuildpack);
/// ```
/// Resolves the path to an additional buildpack binary by Cargo target name.
///
/// This can be used to copy additional binaries to layers or use them for exec.d.
///
/// To add an additional binary to a buildpack, add a new file with a main function to `bin/`.
/// Cargo will [automatically configure it as a binary target](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#target-auto-discovery)
/// with the name of file.
///
/// **Note**: This only works properly if the buildpack is packaged with `libcnb-cargo`/`libcnb-test`.
///
/// ```no_run,compile_fail
/// use libcnb::additional_buildpack_binary_path;
/// # let layer_dir = std::path::PathBuf::from(".");
///
/// std::fs::copy(
/// // This would not compile in this doctest since there is no `runtime_tool` binary target.
/// additional_buildpack_binary_path!("runtime_tool"),
/// layer_dir.join("runtime_tool"),
/// )
/// .unwrap();
/// ```