vergen_lib

Trait AddCustomEntries

Source
pub trait AddCustomEntries<K: Into<String> + Ord, V: Into<String>> {
    // Required methods
    fn add_calculated_entries(
        &self,
        idempotent: bool,
        cargo_rustc_env_map: &mut BTreeMap<K, V>,
        cargo_rerun_if_changed: &mut CargoRerunIfChanged,
        cargo_warning: &mut CargoWarning,
    ) -> Result<()>;
    fn add_default_entries(
        &self,
        config: &DefaultConfig,
        cargo_rustc_env_map: &mut BTreeMap<K, V>,
        cargo_rerun_if_changed: &mut CargoRerunIfChanged,
        cargo_warning: &mut CargoWarning,
    ) -> Result<()>;
}
Expand description

This trait should be implemented to allow the vergen emitter to properly emit your custom instructions.

§Example

#[derive(Default)]
struct Custom {}

impl AddCustomEntries<&str, &str> for Custom {
    fn add_calculated_entries(
        &self,
        _idempotent: bool,
        cargo_rustc_env_map: &mut BTreeMap<&str, &str>,
        _cargo_rerun_if_changed: &mut CargoRerunIfChanged,
        cargo_warning: &mut CargoWarning,
    ) -> Result<()> {
        cargo_rustc_env_map.insert("vergen-cl", "custom_instruction");
        cargo_warning.push("custom instruction generated".to_string());
        Ok(())
    }

    fn add_default_entries(
        &self,
        _config: &DefaultConfig,
        _cargo_rustc_env_map: &mut BTreeMap<&str, &str>,
        _cargo_rerun_if_changed: &mut CargoRerunIfChanged,
        _cargo_warning: &mut CargoWarning,
    ) -> Result<()> {
        Ok(())
    }
}

§Then in [build.rs]

let build = BuildBuilder::all_build()?;
let cargo = CargoBuilder::all_cargo()?;
let gix = GixBuilder::all_git()?;
let rustc = RustcBuilder::all_rustc()?;
let si = SysinfoBuilder::all_sysinfo()?;
Emitter::default()
    .add_instructions(&build)?
    .add_instructions(&cargo)?
    .add_instructions(&gix)?
    .add_instructions(&rustc)?
    .add_instructions(&si)?
    .add_custom_instructions(&Custom::default())?
    .emit()

Required Methods§

Source

fn add_calculated_entries( &self, idempotent: bool, cargo_rustc_env_map: &mut BTreeMap<K, V>, cargo_rerun_if_changed: &mut CargoRerunIfChanged, cargo_warning: &mut CargoWarning, ) -> Result<()>

Try to add instructions entries to the various given arguments.

  • Write to the cargo_rustc_env map to emit ‘cargo:rustc-env=NAME=VALUE’ instructions.
  • Write to the cargo_rerun_if_changed vector to emit ‘cargo:rerun-if-changed=VALUE’ instructions.
  • Write to the cargo_warning vector to emit ‘cargo:warning=VALUE’ instructions.
§Errors

If an error occurs, the vergen emitter will use add_default_entries to generate output. This assumes generating instructions may fail in some manner so a anyhow::Result is returned.

Source

fn add_default_entries( &self, config: &DefaultConfig, cargo_rustc_env_map: &mut BTreeMap<K, V>, cargo_rerun_if_changed: &mut CargoRerunIfChanged, cargo_warning: &mut CargoWarning, ) -> Result<()>

Based on the given configuration, emit either default idempotent output or generate a failue.

  • Write to the cargo_rustc_env map to emit ‘cargo:rustc-env=NAME=VALUE’ instructions.
  • Write to the cargo_rerun_if_changed vector to emit ‘cargo:rerun-if-changed=VALUE’ instructions.
  • Write to the cargo_warning vector to emit ‘cargo:warning=VALUE’ instructions.
§Errors

This assumes generating instructions may fail in some manner so a anyhow::Result is returned.

Implementors§