Expand description
§Cicero Distribution
Need to pack multiple files into a distribution?
Cicero provides an API for specifying the file structure and then deferring to your functions to provide the contents:
#[cfg(feature = "build")] {
use std::{fs, path::Path};
use cicero_distribution::{Distribution, build::Target, bundle::dir::DirBundler};
use cicero_path::repo_path;
fn main() -> cicero_core::Result<()> {
let distribution = Distribution::new("myproject")?;
let target = Target::x86_64_unknown_linux_gnu;
distribution
.add_file_from_path("README.md", repo_path!("README.md"))?
.add_file("myproject", |file| build_backend_executable(file, &target))?;
distribution
.dir("public")?
.add_all(|dir| build_frontend(dir))?;
let distribution_dir = distribution.bundle(DirBundler)?;
Ok(())
}
fn build_frontend(out_dir: &Path) -> cicero_core::Result<()> {
let build_out_dir: &Path = unimplemented!();
fs::rename(build_out_dir, out_dir)?;
Ok(())
}
fn build_backend_executable(out_file: &Path, target: &Target) -> cicero_core::Result<()> {
let build_out_file: &Path = unimplemented!();
fs::rename(build_out_file, out_file)?;
Ok(())
}
}Advantages to this approach:
- File structure is documented and trivially correct.
- Conflicts due to two code locations modifying the same files are practically eliminated.
- Obvious where to jump into the code to change a portion of the distribution.
- Less path wrangling. Your function has the complete path passed to it. No need to modify it further.
- Your functions become naturally testable. You can pass a temporary path (e.g. from
assert_fs) instead and assert on that.
Mind that this API may still see larger changes, as more features are implemented.
Modules§
- bundle
- Various bundlers for use with
Distribution::bundle. - filter
- Filter which paths in a
Distributionshould be included. - staging
- Add files into a distribution.
Structs§
- Distribution
- Bundle files into a directory or archive for providing a release build of your application to your users.
- Distribution
Options - Settings struct to configure how a
Distributionis built. - Error
- Error type for
cicero_distribution.
Type Aliases§
- Result
- Result type for
cicero_distribution.