Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify arbitrary container arguments #1315

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
config: Allow passing arbitrary arguments
to container runtimes using a new configuration key under `build.env`.
This gives users the flexibility to work around issues such as #1012
without having to wait for a new release or creating their own forks of
`cross`.
  • Loading branch information
har7an committed Aug 21, 2023
commit ce617d50e0ea3aa494fb65a84307c9030d684bd7
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