Skip to content

Commit 21e933a

Browse files
committed
normalize line endings, thanks windows
1 parent 29453b9 commit 21e933a

File tree

10 files changed

+59
-32
lines changed

10 files changed

+59
-32
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::shell::{self, MessageInfo};
21
use crate::docker::{ImageArchitecture, PossibleImage};
2+
use crate::shell::{self, MessageInfo};
33
use crate::{CrossToml, Result, Target, TargetList};
44

55
use std::collections::HashMap;

src/cross_toml.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![doc = include_str!("../docs/cross_toml.md")]
22

3-
use crate::shell::{self, MessageInfo};
43
use crate::docker::PossibleImage;
4+
use crate::shell::{self, MessageInfo};
55
use crate::{config, errors::*};
66
use crate::{Target, TargetList};
77
use serde::de::DeserializeOwned;
@@ -416,7 +416,7 @@ mod tests {
416416

417417
macro_rules! s {
418418
($x:literal) => {
419-
$x.to_string()
419+
$x.parse()?
420420
};
421421
}
422422

src/docker/custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io::Write;
22
use std::path::{Path, PathBuf};
33

4-
use crate::shell::MessageInfo;
54
use crate::docker::{Engine, ImageArchitecture};
5+
use crate::shell::MessageInfo;
66
use crate::{config::Config, docker, CargoMetadata, Target};
77
use crate::{errors::*, file, CommandExt, ToUtf8};
88

src/docker/image.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ impl ImageArchitecture {
7171
ImageArchitecture::from_target(TargetTriple::X86_64UnknownLinuxGnu);
7272
pub const AARCH64_UNKNOWN_LINUX_GNU: Self =
7373
ImageArchitecture::from_target(TargetTriple::Aarch64UnknownLinuxGnu);
74+
pub fn docker_platform(&self) -> String {
75+
if let Some(variant) = &self.variant {
76+
format!("{}/{}/{variant}", self.os, self.architecture)
77+
} else {
78+
format!("{}/{}", self.os, self.architecture)
79+
}
80+
}
7481
}
7582

7683
impl TryFrom<&str> for ImageArchitecture {
@@ -134,6 +141,12 @@ pub enum Architecture {
134141
Wasm,
135142
}
136143

144+
impl std::fmt::Display for Architecture {
145+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
146+
self.serialize(f)
147+
}
148+
}
149+
137150
// Supported Oses are on
138151
// https://rust-lang.github.io/rustup-components-history/aarch64-unknown-linux-gnu.html
139152
// where rust, rustc and cargo is available (e.g rustup toolchain add works)
@@ -155,6 +168,13 @@ pub enum Os {
155168
//Plan9,
156169
//Solaris,
157170
}
171+
172+
impl std::fmt::Display for Os {
173+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
174+
self.serialize(f)
175+
}
176+
}
177+
158178
impl ImageArchitecture {
159179
#[track_caller]
160180
pub const fn from_target(target: TargetTriple) -> Self {

src/docker/shared.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::extensions::{CommandExt, SafeCommand};
1414
use crate::file::{self, write_file, PathExt, ToUtf8};
1515
use crate::id;
1616
use crate::rustc::QualifiedToolchain;
17-
use crate::rustc::{self, VersionMetaExt};
1817
use crate::shell::{self, MessageInfo, Verbosity};
1918
use crate::Target;
2019
use crate::{errors::*, TargetTriple};

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub mod file;
2828
mod id;
2929
mod interpreter;
3030
pub mod rustc;
31-
pub mod shell;
3231
pub mod rustup;
32+
pub mod shell;
3333
pub mod temp;
3434

3535
use std::env;
@@ -391,7 +391,11 @@ impl Serialize for Target {
391391
}
392392
}
393393

394-
pub fn run(args: Args, target_list: TargetList, msg_info: MessageInfo) -> Result<Option<ExitStatus>> {
394+
pub fn run(
395+
args: Args,
396+
target_list: TargetList,
397+
msg_info: MessageInfo,
398+
) -> Result<Option<ExitStatus>> {
395399
if args.all.iter().any(|a| a == "--version" || a == "-V") && args.subcommand.is_none() {
396400
println!(
397401
concat!("cross ", env!("CARGO_PKG_VERSION"), "{}"),
@@ -416,7 +420,7 @@ pub fn run(args: Args, target_list: TargetList, msg_info: MessageInfo) -> Result
416420
let image = match docker::get_image(&config, &target) {
417421
Ok(i) => i,
418422
Err(err) => {
419-
shell::warn(err, args.msg_info)?;
423+
shell::warn(err, args.msg_info)?;
420424
return Ok(None);
421425
}
422426
};
@@ -489,8 +493,7 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
489493
&toolchain,
490494
&rustc_version,
491495
&rustc_commit,
492-
args.msg_info,
493-
496+
args.msg_info,
494497
)?;
495498
}
496499
is_nightly = channel == Channel::Nightly;

src/rustc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::docker::ImageArchitecture;
88
use crate::errors::*;
99
use crate::extensions::{env_program, CommandExt};
1010
use crate::shell::MessageInfo;
11-
use crate::Target;
1211
use crate::TargetTriple;
1312

1413
#[derive(Debug)]
@@ -132,6 +131,7 @@ impl QualifiedToolchain {
132131
let mut toolchain: QualifiedToolchain = QualifiedToolchain::parse(
133132
sysroot.to_owned(),
134133
&compat,
134+
msg_info,
135135
)
136136
.wrap_err(
137137
"could not parse CROSS_CUSTOM_TOOLCHAIN_COMPAT as a fully qualified toolchain name",
@@ -143,7 +143,7 @@ impl QualifiedToolchain {
143143
// a toolchain installed by https://github.com/rust-lang/cargo-bisect-rustc
144144
if name.starts_with("bisector-nightly") {
145145
let (_, toolchain) = name.split_once('-').expect("should include -");
146-
let mut toolchain = QualifiedToolchain::parse(sysroot.to_owned(), toolchain)
146+
let mut toolchain = QualifiedToolchain::parse(sysroot.to_owned(), toolchain, msg_info)
147147
.wrap_err("could not parse bisector toolchain")?;
148148
toolchain.is_custom = true;
149149
toolchain.full = name.to_string();
@@ -173,10 +173,10 @@ impl QualifiedToolchain {
173173
toolchain.full = name.to_string();
174174
return Ok(toolchain);
175175
}
176-
return Err(eyre::eyre!(
176+
Err(eyre::eyre!(
177177
"cross can not figure out what your custom toolchain is"
178178
))
179-
.suggestion("set `CROSS_CUSTOM_TOOLCHAIN_COMPAT` to a fully qualified toolchain name: i.e `nightly-aarch64-unknown-linux-musl`");
179+
.suggestion("set `CROSS_CUSTOM_TOOLCHAIN_COMPAT` to a fully qualified toolchain name: i.e `nightly-aarch64-unknown-linux-musl`")
180180
}
181181

182182
pub fn host(&self) -> &ImageArchitecture {
@@ -198,7 +198,7 @@ impl QualifiedToolchain {
198198
.ok_or_else(|| eyre::eyre!("toolchain was not utf-8"))?;
199199

200200
if std::env::var("CROSS_CUSTOM_TOOLCHAIN").is_err() {
201-
QualifiedToolchain::parse(sysroot.clone(), default_toolchain_name)
201+
QualifiedToolchain::parse(sysroot.clone(), default_toolchain_name, msg_info)
202202
} else {
203203
QualifiedToolchain::custom(default_toolchain_name, &sysroot, msg_info)
204204
}
@@ -230,7 +230,7 @@ impl std::fmt::Display for QualifiedToolchain {
230230
}
231231

232232
impl QualifiedToolchain {
233-
fn parse(sysroot: PathBuf, toolchain: &str) -> Result<Self> {
233+
fn parse(sysroot: PathBuf, toolchain: &str, msg_info: MessageInfo) -> Result<Self> {
234234
match toolchain.parse::<Toolchain>() {
235235
Ok(Toolchain {
236236
channel,
@@ -247,7 +247,7 @@ impl QualifiedToolchain {
247247
sysroot,
248248
}),
249249
Ok(_) | Err(_) if std::env::var("CROSS_CUSTOM_TOOLCHAIN").is_ok() => {
250-
todo!()
250+
QualifiedToolchain::custom(toolchain, &sysroot, msg_info)
251251
}
252252
Ok(_) => eyre::bail!("toolchain is not fully qualified"),
253253
Err(e) => Err(e),
@@ -260,7 +260,7 @@ fn bisect() {
260260
QualifiedToolchain::custom(
261261
"bisector-nightly-2022-04-26-x86_64-unknown-linux-gnu",
262262
"/tmp/cross/sysroot".as_ref(),
263-
MessageInfo::create(true, false, None),
263+
MessageInfo::create(true, false, None).unwrap(),
264264
)
265265
.unwrap();
266266
}

src/rustup.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_version::{Channel, Version};
77

88
use crate::errors::*;
99
pub use crate::extensions::{CommandExt, OutputExt};
10-
use crate::shell::{MessageInfo, Verbosity};
1110
use crate::rustc::QualifiedToolchain;
11+
use crate::shell::{MessageInfo, Verbosity};
1212
use crate::Target;
1313

1414
#[derive(Debug)]
@@ -45,7 +45,7 @@ fn rustup_command(msg_info: MessageInfo) -> Command {
4545
}
4646

4747
pub fn active_toolchain(msg_info: MessageInfo) -> Result<String> {
48-
let out = Command::new("rustup")
48+
let out = rustup_command(msg_info)
4949
.args(&["show", "active-toolchain"])
5050
.run_and_get_output(msg_info)?;
5151

@@ -58,7 +58,7 @@ pub fn active_toolchain(msg_info: MessageInfo) -> Result<String> {
5858
}
5959

6060
pub fn installed_toolchains(msg_info: MessageInfo) -> Result<Vec<String>> {
61-
let out = Command::new("rustup")
61+
let out = rustup_command(msg_info)
6262
.args(&["toolchain", "list"])
6363
.run_and_get_stdout(msg_info)?;
6464

@@ -77,9 +77,9 @@ pub fn available_targets(
7777
// this is explicitly a string and not `QualifiedToolchain`, this is because we use this as a way to ensure that
7878
// the toolchain is an official toolchain, if this errors on `is a custom toolchain`, we tell the user to set CROSS_CUSTOM_TOOLCHAIN to handle the logic needed.
7979
toolchain: &str,
80-
msg_info: MessageInfo
80+
msg_info: MessageInfo,
8181
) -> Result<AvailableTargets> {
82-
let mut cmd = Command::new("rustup");
82+
let mut cmd = rustup_command(msg_info);
8383
cmd.args(&["target", "list", "--toolchain", toolchain]);
8484
let output = cmd
8585
.run_and_get_output(msg_info)
@@ -120,7 +120,7 @@ cross will not attempt to configure the toolchain further so that it can run you
120120
}
121121

122122
pub fn install_toolchain(toolchain: &QualifiedToolchain, msg_info: MessageInfo) -> Result<()> {
123-
Command::new("rustup")
123+
rustup_command(msg_info)
124124
.args(&[
125125
"toolchain",
126126
"add",
@@ -132,9 +132,13 @@ pub fn install_toolchain(toolchain: &QualifiedToolchain, msg_info: MessageInfo)
132132
.wrap_err_with(|| format!("couldn't install toolchain `{toolchain}`"))
133133
}
134134

135-
pub fn install(target: &Target, toolchain: &QualifiedToolchain, msg_info: MessageInfo) -> Result<()> {
135+
pub fn install(
136+
target: &Target,
137+
toolchain: &QualifiedToolchain,
138+
msg_info: MessageInfo,
139+
) -> Result<()> {
136140
let target = target.triple();
137-
Command::new("rustup")
141+
rustup_command(msg_info)
138142
.args(&[
139143
"target",
140144
"add",
@@ -151,7 +155,7 @@ pub fn install_component(
151155
toolchain: &QualifiedToolchain,
152156
msg_info: MessageInfo,
153157
) -> Result<()> {
154-
Command::new("rustup")
158+
rustup_command(msg_info)
155159
.args(&[
156160
"component",
157161
"add",
@@ -168,7 +172,7 @@ pub fn component_is_installed(
168172
toolchain: &QualifiedToolchain,
169173
msg_info: MessageInfo,
170174
) -> Result<bool> {
171-
Ok(Command::new("rustup")
175+
Ok(rustup_command(msg_info)
172176
.args(&["component", "list", "--toolchain", &toolchain.to_string()])
173177
.run_and_get_stdout(msg_info)?
174178
.lines()

xtask/src/build_docker_image.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::path::Path;
33

44
use crate::util::{cargo_metadata, gha_error, gha_output, gha_print};
55
use clap::Args;
6-
use cross::shell::{self, MessageInfo};
7-
use color_eyre::Section;
86
use cross::docker::ImageArchitecture;
7+
use cross::shell::{self, MessageInfo};
98
use cross::{docker, CommandExt, ToUtf8};
109

1110
#[derive(Args, Debug)]
@@ -70,7 +69,7 @@ pub struct BuildDockerImage {
7069
pub build_arg: Vec<String>,
7170
// [os/arch[/variant]=]toolchain
7271
#[clap(long, short = 'a', action = clap::builder::ArgAction::Append)]
73-
platform: Vec<ImageArchitecture>,
72+
pub platform: Vec<ImageArchitecture>,
7473
/// Targets to build for
7574
#[clap()]
7675
pub targets: Vec<crate::ImageTarget>,
@@ -179,6 +178,8 @@ pub fn build_docker_image(
179178
docker_build.args(&["buildx", "build"]);
180179
docker_build.current_dir(&docker_root);
181180

181+
docker_build.args(&["--platform", &platform.docker_platform()]);
182+
182183
if push {
183184
docker_build.arg("--push");
184185
} else if no_output {

xtask/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ pub static PROVIDED_IMAGES: &[ProvidedImage] = &["##,
7474
pub fn ensure_correct_codegen() -> cross::Result<()> {
7575
let provided_images = crate::util::get_cargo_workspace().join("src/docker/provided_images.rs");
7676
let content = cross::file::read(provided_images)?;
77-
assert_eq!(content, docker_images());
77+
assert_eq!(content.replace("\r\n", "\n"), docker_images());
7878
Ok(())
7979
}

0 commit comments

Comments
 (0)