Skip to content

Commit

Permalink
normalize line endings, thanks windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Jun 29, 2022
1 parent 29453b9 commit 21e933a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::shell::{self, MessageInfo};
use crate::docker::{ImageArchitecture, PossibleImage};
use crate::shell::{self, MessageInfo};
use crate::{CrossToml, Result, Target, TargetList};

use std::collections::HashMap;
Expand Down
4 changes: 2 additions & 2 deletions src/cross_toml.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![doc = include_str!("../docs/cross_toml.md")]

use crate::shell::{self, MessageInfo};
use crate::docker::PossibleImage;
use crate::shell::{self, MessageInfo};
use crate::{config, errors::*};
use crate::{Target, TargetList};
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -416,7 +416,7 @@ mod tests {

macro_rules! s {
($x:literal) => {
$x.to_string()
$x.parse()?
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/docker/custom.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io::Write;
use std::path::{Path, PathBuf};

use crate::shell::MessageInfo;
use crate::docker::{Engine, ImageArchitecture};
use crate::shell::MessageInfo;
use crate::{config::Config, docker, CargoMetadata, Target};
use crate::{errors::*, file, CommandExt, ToUtf8};

Expand Down
20 changes: 20 additions & 0 deletions src/docker/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ impl ImageArchitecture {
ImageArchitecture::from_target(TargetTriple::X86_64UnknownLinuxGnu);
pub const AARCH64_UNKNOWN_LINUX_GNU: Self =
ImageArchitecture::from_target(TargetTriple::Aarch64UnknownLinuxGnu);
pub fn docker_platform(&self) -> String {
if let Some(variant) = &self.variant {
format!("{}/{}/{variant}", self.os, self.architecture)
} else {
format!("{}/{}", self.os, self.architecture)
}
}
}

impl TryFrom<&str> for ImageArchitecture {
Expand Down Expand Up @@ -134,6 +141,12 @@ pub enum Architecture {
Wasm,
}

impl std::fmt::Display for Architecture {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.serialize(f)
}
}

// Supported Oses are on
// https://rust-lang.github.io/rustup-components-history/aarch64-unknown-linux-gnu.html
// where rust, rustc and cargo is available (e.g rustup toolchain add works)
Expand All @@ -155,6 +168,13 @@ pub enum Os {
//Plan9,
//Solaris,
}

impl std::fmt::Display for Os {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.serialize(f)
}
}

impl ImageArchitecture {
#[track_caller]
pub const fn from_target(target: TargetTriple) -> Self {
Expand Down
1 change: 0 additions & 1 deletion src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::extensions::{CommandExt, SafeCommand};
use crate::file::{self, write_file, PathExt, ToUtf8};
use crate::id;
use crate::rustc::QualifiedToolchain;
use crate::rustc::{self, VersionMetaExt};
use crate::shell::{self, MessageInfo, Verbosity};
use crate::Target;
use crate::{errors::*, TargetTriple};
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub mod file;
mod id;
mod interpreter;
pub mod rustc;
pub mod shell;
pub mod rustup;
pub mod shell;
pub mod temp;

use std::env;
Expand Down Expand Up @@ -391,7 +391,11 @@ impl Serialize for Target {
}
}

pub fn run(args: Args, target_list: TargetList, msg_info: MessageInfo) -> Result<Option<ExitStatus>> {
pub fn run(
args: Args,
target_list: TargetList,
msg_info: MessageInfo,
) -> Result<Option<ExitStatus>> {
if args.all.iter().any(|a| a == "--version" || a == "-V") && args.subcommand.is_none() {
println!(
concat!("cross ", env!("CARGO_PKG_VERSION"), "{}"),
Expand All @@ -416,7 +420,7 @@ pub fn run(args: Args, target_list: TargetList, msg_info: MessageInfo) -> Result
let image = match docker::get_image(&config, &target) {
Ok(i) => i,
Err(err) => {
shell::warn(err, args.msg_info)?;
shell::warn(err, args.msg_info)?;
return Ok(None);
}
};
Expand Down Expand Up @@ -489,8 +493,7 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
&toolchain,
&rustc_version,
&rustc_commit,
args.msg_info,

args.msg_info,
)?;
}
is_nightly = channel == Channel::Nightly;
Expand Down
16 changes: 8 additions & 8 deletions src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::docker::ImageArchitecture;
use crate::errors::*;
use crate::extensions::{env_program, CommandExt};
use crate::shell::MessageInfo;
use crate::Target;
use crate::TargetTriple;

#[derive(Debug)]
Expand Down Expand Up @@ -132,6 +131,7 @@ impl QualifiedToolchain {
let mut toolchain: QualifiedToolchain = QualifiedToolchain::parse(
sysroot.to_owned(),
&compat,
msg_info,
)
.wrap_err(
"could not parse CROSS_CUSTOM_TOOLCHAIN_COMPAT as a fully qualified toolchain name",
Expand All @@ -143,7 +143,7 @@ impl QualifiedToolchain {
// a toolchain installed by https://github.com/rust-lang/cargo-bisect-rustc
if name.starts_with("bisector-nightly") {
let (_, toolchain) = name.split_once('-').expect("should include -");
let mut toolchain = QualifiedToolchain::parse(sysroot.to_owned(), toolchain)
let mut toolchain = QualifiedToolchain::parse(sysroot.to_owned(), toolchain, msg_info)
.wrap_err("could not parse bisector toolchain")?;
toolchain.is_custom = true;
toolchain.full = name.to_string();
Expand Down Expand Up @@ -173,10 +173,10 @@ impl QualifiedToolchain {
toolchain.full = name.to_string();
return Ok(toolchain);
}
return Err(eyre::eyre!(
Err(eyre::eyre!(
"cross can not figure out what your custom toolchain is"
))
.suggestion("set `CROSS_CUSTOM_TOOLCHAIN_COMPAT` to a fully qualified toolchain name: i.e `nightly-aarch64-unknown-linux-musl`");
.suggestion("set `CROSS_CUSTOM_TOOLCHAIN_COMPAT` to a fully qualified toolchain name: i.e `nightly-aarch64-unknown-linux-musl`")
}

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

if std::env::var("CROSS_CUSTOM_TOOLCHAIN").is_err() {
QualifiedToolchain::parse(sysroot.clone(), default_toolchain_name)
QualifiedToolchain::parse(sysroot.clone(), default_toolchain_name, msg_info)
} else {
QualifiedToolchain::custom(default_toolchain_name, &sysroot, msg_info)
}
Expand Down Expand Up @@ -230,7 +230,7 @@ impl std::fmt::Display for QualifiedToolchain {
}

impl QualifiedToolchain {
fn parse(sysroot: PathBuf, toolchain: &str) -> Result<Self> {
fn parse(sysroot: PathBuf, toolchain: &str, msg_info: MessageInfo) -> Result<Self> {
match toolchain.parse::<Toolchain>() {
Ok(Toolchain {
channel,
Expand All @@ -247,7 +247,7 @@ impl QualifiedToolchain {
sysroot,
}),
Ok(_) | Err(_) if std::env::var("CROSS_CUSTOM_TOOLCHAIN").is_ok() => {
todo!()
QualifiedToolchain::custom(toolchain, &sysroot, msg_info)
}
Ok(_) => eyre::bail!("toolchain is not fully qualified"),
Err(e) => Err(e),
Expand All @@ -260,7 +260,7 @@ fn bisect() {
QualifiedToolchain::custom(
"bisector-nightly-2022-04-26-x86_64-unknown-linux-gnu",
"/tmp/cross/sysroot".as_ref(),
MessageInfo::create(true, false, None),
MessageInfo::create(true, false, None).unwrap(),
)
.unwrap();
}
Expand Down
24 changes: 14 additions & 10 deletions src/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use rustc_version::{Channel, Version};

use crate::errors::*;
pub use crate::extensions::{CommandExt, OutputExt};
use crate::shell::{MessageInfo, Verbosity};
use crate::rustc::QualifiedToolchain;
use crate::shell::{MessageInfo, Verbosity};
use crate::Target;

#[derive(Debug)]
Expand Down Expand Up @@ -45,7 +45,7 @@ fn rustup_command(msg_info: MessageInfo) -> Command {
}

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

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

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

Expand All @@ -77,9 +77,9 @@ pub fn available_targets(
// this is explicitly a string and not `QualifiedToolchain`, this is because we use this as a way to ensure that
// 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.
toolchain: &str,
msg_info: MessageInfo
msg_info: MessageInfo,
) -> Result<AvailableTargets> {
let mut cmd = Command::new("rustup");
let mut cmd = rustup_command(msg_info);
cmd.args(&["target", "list", "--toolchain", toolchain]);
let output = cmd
.run_and_get_output(msg_info)
Expand Down Expand Up @@ -120,7 +120,7 @@ cross will not attempt to configure the toolchain further so that it can run you
}

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

pub fn install(target: &Target, toolchain: &QualifiedToolchain, msg_info: MessageInfo) -> Result<()> {
pub fn install(
target: &Target,
toolchain: &QualifiedToolchain,
msg_info: MessageInfo,
) -> Result<()> {
let target = target.triple();
Command::new("rustup")
rustup_command(msg_info)
.args(&[
"target",
"add",
Expand All @@ -151,7 +155,7 @@ pub fn install_component(
toolchain: &QualifiedToolchain,
msg_info: MessageInfo,
) -> Result<()> {
Command::new("rustup")
rustup_command(msg_info)
.args(&[
"component",
"add",
Expand All @@ -168,7 +172,7 @@ pub fn component_is_installed(
toolchain: &QualifiedToolchain,
msg_info: MessageInfo,
) -> Result<bool> {
Ok(Command::new("rustup")
Ok(rustup_command(msg_info)
.args(&["component", "list", "--toolchain", &toolchain.to_string()])
.run_and_get_stdout(msg_info)?
.lines()
Expand Down
7 changes: 4 additions & 3 deletions xtask/src/build_docker_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::path::Path;

use crate::util::{cargo_metadata, gha_error, gha_output, gha_print};
use clap::Args;
use cross::shell::{self, MessageInfo};
use color_eyre::Section;
use cross::docker::ImageArchitecture;
use cross::shell::{self, MessageInfo};
use cross::{docker, CommandExt, ToUtf8};

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

docker_build.args(&["--platform", &platform.docker_platform()]);

if push {
docker_build.arg("--push");
} else if no_output {
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ pub static PROVIDED_IMAGES: &[ProvidedImage] = &["##,
pub fn ensure_correct_codegen() -> cross::Result<()> {
let provided_images = crate::util::get_cargo_workspace().join("src/docker/provided_images.rs");
let content = cross::file::read(provided_images)?;
assert_eq!(content, docker_images());
assert_eq!(content.replace("\r\n", "\n"), docker_images());
Ok(())
}

0 comments on commit 21e933a

Please sign in to comment.