diff --git a/.changes/1315.json b/.changes/1315.json new file mode 100644 index 000000000..c7aacc1c5 --- /dev/null +++ b/.changes/1315.json @@ -0,0 +1,4 @@ +{ + "description": "allow appending arbitrary arguments to container runtime", + "type": "added" +} diff --git a/src/config.rs b/src/config.rs index 063c2088f..14910381a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -101,6 +101,10 @@ impl Environment { get_possible_image(self, "IMAGE", "IMAGE_TOOLCHAIN", get_target, get_target) } + fn extra_args(&self, target: &Target) -> (Option>, Option>) { + self.get_values_for("EXTRA_ARGS", target, split_to_cloned_by_ws) + } + fn dockerfile(&self, target: &Target) -> (Option, Option) { self.get_values_for("DOCKERFILE", target, ToOwned::to_owned) } @@ -409,6 +413,10 @@ impl Config { ) } + pub fn extra_args(&self, target: &Target) -> Result>> { + self.get_from_ref(target, Environment::extra_args, CrossToml::extra_args) + } + pub fn env_volumes(&self, target: &Target) -> Result>> { self.get_from_ref(target, Environment::volumes, CrossToml::env_volumes) } diff --git a/src/cross_toml.rs b/src/cross_toml.rs index b079b04ce..fc51a935f 100644 --- a/src/cross_toml.rs +++ b/src/cross_toml.rs @@ -15,6 +15,8 @@ use std::str::FromStr; pub struct CrossEnvConfig { volumes: Option>, passthrough: Option>, + /// Additional arguments to the underlying container engine + extra_args: Option>, } /// Build configuration @@ -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 { self.build @@ -614,6 +624,7 @@ mod tests { env: CrossEnvConfig { volumes: Some(vec![p!("VOL1_ARG"), p!("VOL2_ARG")]), passthrough: Some(vec![p!("VAR1"), p!("VAR2")]), + extra_args: None, }, xargo: Some(true), build_std: None, @@ -652,6 +663,7 @@ mod tests { env: CrossEnvConfig { passthrough: Some(vec![p!("VAR1"), p!("VAR2")]), volumes: Some(vec![p!("VOL1_ARG"), p!("VOL2_ARG")]), + extra_args: None, }, xargo: Some(false), build_std: Some(true), @@ -670,6 +682,7 @@ mod tests { env: CrossEnvConfig { passthrough: None, volumes: None, + extra_args: None, }, xargo: None, build_std: None, @@ -740,6 +753,7 @@ mod tests { env: CrossEnvConfig { passthrough: None, volumes: Some(vec![p!("VOL")]), + extra_args: None, }, }, ); @@ -750,6 +764,7 @@ mod tests { env: CrossEnvConfig { volumes: None, passthrough: Some(vec![]), + extra_args: None, }, xargo: Some(true), build_std: None, @@ -824,6 +839,7 @@ mod tests { env: CrossEnvConfig { passthrough: None, volumes: None, + extra_args: None, }, build_std: None, xargo: Some(true), diff --git a/src/docker/local.rs b/src/docker/local.rs index 4f3653459..ace2de3d1 100644 --- a/src/docker/local.rs +++ b/src/docker/local.rs @@ -41,6 +41,7 @@ pub(crate) fn run( let mut docker = engine.subcommand("run"); docker.add_userns(); + docker.add_extra_args(&options)?; // Podman on macOS doesn't support selinux labels, see issue #756 #[cfg(target_os = "macos")] diff --git a/src/docker/remote.rs b/src/docker/remote.rs index 9a6d3185b..64f7e8b00 100644 --- a/src/docker/remote.rs +++ b/src/docker/remote.rs @@ -758,6 +758,9 @@ pub(crate) fn run( msg_info, ) .wrap_err("could not determine mount points")?; + docker + .add_extra_args(&options) + .wrap_err("could not determine additional container arguments")?; docker .add_seccomp(engine.kind, target, &paths.metadata) diff --git a/src/docker/shared.rs b/src/docker/shared.rs index 83ec3bfc9..21880fda1 100644 --- a/src/docker/shared.rs +++ b/src/docker/shared.rs @@ -955,6 +955,7 @@ pub(crate) trait DockerCommandExt { target: &Target, metadata: &CargoMetadata, ) -> Result<()>; + fn add_extra_args(&mut self, options: &DockerOptions) -> Result<()>; fn add_mounts( &mut self, options: &DockerOptions, @@ -1164,6 +1165,14 @@ impl DockerCommandExt for Command { Ok(()) } + fn add_extra_args(&mut self, options: &DockerOptions) -> Result<()> { + let extra_args = options.config.extra_args(&options.target)?; + if let Some(args) = extra_args { + self.args(args); + } + Ok(()) + } + fn add_mounts( &mut self, options: &DockerOptions,