Skip to content

Commit

Permalink
config: Allow passing arbitrary arguments
Browse files Browse the repository at this point in the history
to container runtimes using a new configuration key under `build.env`.
This gives users the flexibility to work around issues such as cross-rs#1012
without having to wait for a new release or creating their own forks of
`cross`.
  • Loading branch information
har7an committed Aug 21, 2023
1 parent 37c681a commit ce617d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl Environment {
get_possible_image(self, "IMAGE", "IMAGE_TOOLCHAIN", get_target, get_target)
}

fn extra_args(&self, target: &Target) -> (Option<Vec<String>>, Option<Vec<String>>) {
self.get_values_for("EXTRA_ARGS", target, split_to_cloned_by_ws)
}

fn dockerfile(&self, target: &Target) -> (Option<String>, Option<String>) {
self.get_values_for("DOCKERFILE", target, ToOwned::to_owned)
}
Expand Down Expand Up @@ -409,6 +413,10 @@ impl Config {
)
}

pub fn extra_args(&self, target: &Target) -> Result<Option<Vec<String>>> {
self.get_from_ref(target, Environment::extra_args, CrossToml::extra_args)
}

pub fn env_volumes(&self, target: &Target) -> Result<Option<Vec<String>>> {
self.get_from_ref(target, Environment::volumes, CrossToml::env_volumes)
}
Expand Down
10 changes: 10 additions & 0 deletions src/cross_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::str::FromStr;
pub struct CrossEnvConfig {
volumes: Option<Vec<String>>,
passthrough: Option<Vec<String>>,
/// Additional arguments to the underlying container engine
extra_args: Option<Vec<String>>,
}

/// Build configuration
Expand Down Expand Up @@ -362,6 +364,14 @@ impl CrossToml {
)
}

pub fn extra_args(&self, target: &Target) -> (Option<&[String]>, Option<&[String]>) {
self.get_ref(
target,
|build| build.env.extra_args.as_deref(),
|t| t.env.extra_args.as_deref(),
)
}

/// Returns the default target to build,
pub fn default_target(&self, target_list: &TargetList) -> Option<Target> {
self.build
Expand Down

0 comments on commit ce617d5

Please sign in to comment.