Skip to content

Commit a7a516f

Browse files
committed
Dummy commit.
1 parent 8db82e4 commit a7a516f

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

docs/cross_toml.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ For example:
2121

2222
```toml
2323
[build.env]
24+
complete-cargo-config = true
2425
ignore-cargo-config = false
2526
volumes = ["VOL1_ARG", "VOL2_ARG"]
2627
passthrough = ["IMPORTANT_ENV_VARIABLES"]

src/cross_config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashMap;
22

33
use crate::config::{bool_from_envvar, split_to_cloned_by_ws, Environment};
4+
use crate::cross_toml::CargoConfigBehavior;
45
use crate::docker::custom::PreBuild;
56
use crate::shell::MessageInfo;
67
use crate::{CrossToml, Result, Target, TargetList};
@@ -84,6 +85,13 @@ impl CrossEnvironment {
8485
self.get_target_var(target, "RUNNER")
8586
}
8687

88+
// TODO(ahuszagh) Need to change this.
89+
// Need to have an enum here.
90+
91+
fn complete_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
92+
self.get_values_for("ENV_COMPLETE_CARGO_CONFIG", target, bool_from_envvar)
93+
}
94+
8795
fn ignore_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
8896
self.get_values_for("ENV_IGNORE_CARGO_CONFIG", target, bool_from_envvar)
8997
}
@@ -272,6 +280,17 @@ impl CrossConfig {
272280
self.env.custom_toolchain()
273281
}
274282

283+
// TODO(ahuszagh) This should actually be an enough
284+
// Ignore, default, complete.
285+
286+
pub fn env_complete_cargo_config(&self, target: &Target) -> Option<bool> {
287+
self.bool_from_config(
288+
target,
289+
CrossEnvironment::complete_cargo_config,
290+
CrossToml::env_complete_cargo_config,
291+
)
292+
}
293+
275294
pub fn env_ignore_cargo_config(&self, target: &Target) -> Option<bool> {
276295
self.bool_from_config(
277296
target,

src/cross_toml.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use serde::{Deserialize, Deserializer, Serialize};
1717
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
1818
#[serde(rename_all = "kebab-case")]
1919
pub struct CrossEnvConfig {
20+
// TODO(ahuszagh) Change to an enum
21+
cargo_config: Option<CargoConfigBehavior>,
22+
complete_cargo_config: Option<bool>,
2023
ignore_cargo_config: Option<bool>,
2124
volumes: Option<Vec<String>>,
2225
passthrough: Option<Vec<String>>,
@@ -84,6 +87,34 @@ pub struct CrossToml {
8487
pub build: CrossBuildConfig,
8588
}
8689

90+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
91+
#[serde(rename_all = "kebab-case")]
92+
pub enum CargoConfigBehavior {
93+
Ignore,
94+
#[serde(rename = "default")]
95+
Normal,
96+
Complete,
97+
}
98+
99+
impl Default for CargoConfigBehavior {
100+
fn default() -> CargoConfigBehavior {
101+
CargoConfigBehavior::Normal
102+
}
103+
}
104+
105+
impl FromStr for CargoConfigBehavior {
106+
type Err = eyre::Error;
107+
108+
fn from_str(s: &str) -> Result<CargoConfigBehavior> {
109+
match s {
110+
"ignore" => Ok(CargoConfigBehavior::Ignore),
111+
"default" => Ok(CargoConfigBehavior::Normal),
112+
"complete" => Ok(CargoConfigBehavior::Complete),
113+
_ => eyre::bail!("invalid cargo config behavior, got {s}"),
114+
}
115+
}
116+
}
117+
87118
impl CrossToml {
88119
/// Obtains the [`CrossToml`] from one of the possible locations
89120
///
@@ -324,6 +355,24 @@ impl CrossToml {
324355
self.get_value(target, |b| b.build_std, |t| t.build_std)
325356
}
326357

358+
/// Returns the cargo config behavior.
359+
pub fn env_cargo_config(&self, target: &Target) -> (Option<CargoConfigBehavior>, Option<CargoConfigBehavior>) {
360+
self.get_value(
361+
target,
362+
|b| b.env.cargo_config,
363+
|t| t.env.cargo_config,
364+
)
365+
}
366+
367+
/// Returns the whether to use the complete cargo config settings.
368+
pub fn env_complete_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
369+
self.get_value(
370+
target,
371+
|b| b.env.complete_cargo_config,
372+
|t| t.env.complete_cargo_config,
373+
)
374+
}
375+
327376
/// Returns the whether to ignore cargo config files.
328377
pub fn env_ignore_cargo_config(&self, target: &Target) -> (Option<bool>, Option<bool>) {
329378
self.get_value(
@@ -529,6 +578,18 @@ mod tests {
529578
};
530579
}
531580

581+
#[test]
582+
pub fn test_toml_cargo_config_behavior() -> Result<()> {
583+
assert_eq!(CargoConfigBehavior::Normal, toml::from_str("\"default\"")?);
584+
assert_eq!(CargoConfigBehavior::Ignore, toml::from_str("\"ignore\"")?);
585+
assert_eq!(CargoConfigBehavior::Complete, toml::from_str("\"complete\"")?);
586+
assert!(toml::from_str::<CargoConfigBehavior>("\"other\"").is_err());
587+
assert!(toml::from_str::<CargoConfigBehavior>("true").is_err());
588+
assert!(toml::from_str::<CargoConfigBehavior>("0").is_err());
589+
590+
Ok(())
591+
}
592+
532593
#[test]
533594
pub fn parse_empty_toml() -> Result<()> {
534595
let cfg = CrossToml {
@@ -549,6 +610,9 @@ mod tests {
549610
targets: HashMap::new(),
550611
build: CrossBuildConfig {
551612
env: CrossEnvConfig {
613+
// TODO(ahuszagh) Remove
614+
cargo_config: None,
615+
complete_cargo_config: None,
552616
ignore_cargo_config: Some(false),
553617
volumes: Some(vec![s!("VOL1_ARG"), s!("VOL2_ARG")]),
554618
passthrough: Some(vec![s!("VAR1"), s!("VAR2")]),
@@ -588,6 +652,9 @@ mod tests {
588652
},
589653
CrossTargetConfig {
590654
env: CrossEnvConfig {
655+
// TODO(ahuszagh) Remove
656+
cargo_config: None,
657+
complete_cargo_config: None,
591658
ignore_cargo_config: None,
592659
passthrough: Some(vec![s!("VAR1"), s!("VAR2")]),
593660
volumes: Some(vec![s!("VOL1_ARG"), s!("VOL2_ARG")]),
@@ -643,6 +710,9 @@ mod tests {
643710
pre_build: Some(PreBuild::Lines(vec![s!("echo 'Hello'")])),
644711
runner: None,
645712
env: CrossEnvConfig {
713+
// TODO(ahuszagh) Remove
714+
cargo_config: None,
715+
complete_cargo_config: None,
646716
ignore_cargo_config: None,
647717
passthrough: None,
648718
volumes: Some(vec![s!("VOL")]),
@@ -654,6 +724,9 @@ mod tests {
654724
targets: target_map,
655725
build: CrossBuildConfig {
656726
env: CrossEnvConfig {
727+
// TODO(ahuszagh) Remove
728+
cargo_config: None,
729+
complete_cargo_config: None,
657730
ignore_cargo_config: Some(true),
658731
volumes: None,
659732
passthrough: Some(vec![]),
@@ -714,6 +787,9 @@ mod tests {
714787
targets: HashMap::new(),
715788
build: CrossBuildConfig {
716789
env: CrossEnvConfig {
790+
// TODO(ahuszagh) Remove
791+
cargo_config: None,
792+
complete_cargo_config: None,
717793
ignore_cargo_config: None,
718794
passthrough: None,
719795
volumes: None,

0 commit comments

Comments
 (0)