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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
#![allow(clippy::needless_doctest_main)] //! Adds the feature to print the build information to your program with minimal boilerplate. //! //! 1. Call `ever!()` at the top of `main` function of your program. //! //! ```rust //! use ever::ever; //! //! fn main() { //! ever!(); //! //! println!("Hello, world!"); //! } //! ``` //! //! 2. Set the environment variable `EVER` to `1` when starting the program. The build information is printed and the program exits with status `1`. //! //! ```bash,ignore //! $ EVER=1 ./your_program //! your_program 0.1.0 (debug): //! //! date: Sat Dec 5 11:17:09 2020 +0900 //! commit: 49fec228607448df6fcb8950171441a1f56c2e7b-dirty //! user: yushiomote //! host: your_host //! builddir: /home/yushiomote/your_program //! rustc: 1.48.0 (7eac88abb 2020-11-16) //! ``` //! //! If you want to change the environment variable name, pass your alternative as the argument. //! //! ```rust //! # use ever::ever; //! ever!("MY_VERSION"); //! ``` //! //! ```bash,text //! $ MY_VERSION=1 ./your_program //! ``` //! //! ## Dump `Cargo.lock` //! //! By setting the environment variable to `dump_lock`, the program dumps the content of `Cargo.lock` used during build. //! //! ```bash,ignore //! $ EVER=dump_lock ./your_program //! # This file is automatically @generated by Cargo. //! # It is not intended for manual editing. //! [[package]] //! name = "autocfg" //! version = "1.0.1" //! source = "registry+https://github.com/rust-lang/crates.io-index" //! ... //! ``` //! //! ## Individual parameters //! //! Provides macros to get individual parameters. //! //! ```rust //! use ever::{build_commit_hash, build_dir, build_date}; //! //! fn main() { //! println!("build_commit_hash: {}", build_commit_hash!()); //! println!("build_dir: {}", build_dir!()); //! println!("build_date: {}", build_date!()); //! } //! ``` //! //! All the types returned by those macros are `&'static str`. //! //! ## Note //! //! The build information is retrieved only when the source file where `ever` macro is called is compiled. //! use proc_macro_hack::proc_macro_hack; /// Prints the build information when the environment variable is set. /// /// See [`the top page`](index.html) for the usage. #[proc_macro_hack] pub use ever_macro::ever; /// Returns the package name. /// /// ```rust /// // Prints "your_program" /// println!("{}", ever::package_name!()) /// ``` #[proc_macro_hack] pub use ever_macro::package_name; /// Returns the package version. /// /// ```rust /// // Prints "0.1.0" /// println!("{}", ever::package_version!()) /// ``` #[proc_macro_hack] pub use ever_macro::package_version; /// Returns the package description. /// /// ```rust /// // Prints "your awesome package" /// println!("{}", ever::package_description!()) /// ``` #[proc_macro_hack] pub use ever_macro::package_description; /// Returns the build date. /// /// ```rust /// // Prints "Sat Dec 5 10:47:42 2020 +0900" /// println!("{}", ever::build_date!()); /// ``` #[proc_macro_hack] pub use ever_macro::build_date; /// Returns the build mode, which is either `release` or `debug`. /// /// ```rust /// // Prints "release" /// println!("{}", ever::build_mode!()); /// ``` #[proc_macro_hack] pub use ever_macro::build_mode; /// Returns the git commit hash. /// /// If the repository has uncommited files, the hash is suffixed with `-dirty`. /// /// ```rust /// // Prints "49fec228607448df6fcb8950171441a1f56c2e7b-dirty" /// println!("{}", ever::build_commit_hash!()); /// ``` #[proc_macro_hack] pub use ever_macro::build_commit_hash; /// Returns the username who builds the package. /// /// ```rust /// // Prints "your_username" /// println!("{}", ever::build_commit_hash!()); /// ``` #[proc_macro_hack] pub use ever_macro::build_username; /// Returns the hostname where the package is built. /// /// ```rust /// // Prints "your_hostname" /// println!("{}", ever::build_hostname!()); /// ``` #[proc_macro_hack] pub use ever_macro::build_hostname; /// Returns the directory path where the package is built. /// /// ```rust /// // Prints "/path/to/your_build_dir" /// println!("{}", ever::build_dir!()); /// ``` #[proc_macro_hack] pub use ever_macro::build_dir; /// Returns the version of rustc used to build the program. /// /// ```rust /// // Prints "" /// println!("{}", ever::rustc_version!()); /// ``` #[proc_macro_hack] pub use ever_macro::rustc_version; /// Returns the content of `Cargo.lock` to build the program. /// /// ```rust /// // Prints "/path/to/your_build_dir" /// println!("{}", ever::lock_file!()); /// ``` #[proc_macro_hack] pub use ever_macro::lock_file;