-
Notifications
You must be signed in to change notification settings - Fork 399
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
allow cross-util install
#1216
base: main
Are you sure you want to change the base?
allow cross-util install
#1216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
use clap::Args; | ||
use cross::{docker, rustc, shell::MessageInfo}; | ||
use eyre::Context; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct Install { | ||
#[clap(long)] | ||
target: Option<String>, | ||
#[clap(long)] | ||
root: String, | ||
/// Provide verbose diagnostic output. | ||
#[clap(short, long)] | ||
pub verbose: bool, | ||
/// Do not print | ||
#[clap(short, long)] | ||
pub quiet: bool, | ||
/// Coloring: auto, always, never | ||
#[clap(long)] | ||
pub color: Option<String>, | ||
/// Container engine (such as docker or podman). | ||
#[clap(long)] | ||
pub engine: Option<String>, | ||
/// Path to crate | ||
#[clap(long)] | ||
pub path: Option<String>, | ||
/// Path to Cross.toml | ||
#[clap(long)] | ||
pub config: Option<std::path::PathBuf>, | ||
#[clap(name = "crate")] | ||
krate: String, | ||
} | ||
|
||
impl Install { | ||
pub fn verbose(&self) -> bool { | ||
self.verbose | ||
} | ||
|
||
pub fn quiet(&self) -> bool { | ||
self.quiet | ||
} | ||
|
||
pub fn color(&self) -> Option<&str> { | ||
self.color.as_deref() | ||
} | ||
|
||
pub fn run(self, msg_info: &mut MessageInfo) -> cross::Result<std::process::ExitStatus> { | ||
let target_list = rustc::target_list(&mut cross::shell::Verbosity::Quiet.into())?; | ||
|
||
let host_version_meta = rustc::version_meta()?; | ||
let mut command = vec!["install".to_owned(), self.krate]; | ||
|
||
if let Some(target) = self.target { | ||
command.push(format!("--target={target}")); | ||
} | ||
command.push(format!("--root={}", self.root)); | ||
|
||
if let Some(engine) = self.engine { | ||
std::env::set_var(docker::CROSS_CONTAINER_ENGINE_VAR, engine); | ||
} | ||
|
||
let args = cross::cli::parse(command, &target_list)?; | ||
let Some(cross::CrossSetup { | ||
config, | ||
target, | ||
uses_xargo, | ||
uses_zig, | ||
uses_build_std, | ||
zig_version, | ||
toolchain, | ||
is_remote, | ||
engine, | ||
image, | ||
}) = cross::setup(&host_version_meta, None, &args, target_list, msg_info)? else { | ||
eyre::bail!("couldn't setup context for cross (see warning)") | ||
}; | ||
|
||
let mut is_nightly = toolchain.channel.contains("nightly"); | ||
let mut rustc_version = None; | ||
if let Some((version, channel, _)) = toolchain.rustc_version()? { | ||
is_nightly = channel == rustc_version::Channel::Nightly; | ||
rustc_version = Some(version); | ||
} | ||
Comment on lines
+79
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't emit warning on mismatch like normal cross does |
||
|
||
let available_targets = cross::rustup::setup_rustup(&toolchain, msg_info)?; | ||
|
||
cross::rustup::setup_components( | ||
&target, | ||
uses_xargo, | ||
uses_build_std, | ||
&toolchain, | ||
is_nightly, | ||
available_targets, | ||
&args, | ||
msg_info, | ||
)?; | ||
|
||
let filtered_args = cross::get_filtered_args( | ||
zig_version, | ||
&args, | ||
&target, | ||
&config, | ||
is_nightly, | ||
uses_build_std, | ||
); | ||
|
||
let cwd = std::env::current_dir()?; | ||
|
||
let paths = docker::DockerPaths::create( | ||
&engine, | ||
cross::CargoMetadata { | ||
workspace_root: cwd.clone(), | ||
target_directory: cross::file::absolute_path(self.root)?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is misleading
|
||
packages: vec![], | ||
workspace_members: vec![], | ||
}, | ||
cwd, | ||
toolchain.clone(), | ||
msg_info, | ||
)?; | ||
let mut options = docker::DockerOptions::new( | ||
engine, | ||
target.clone(), | ||
config, | ||
image, | ||
cross::CargoVariant::create(uses_zig, uses_xargo)?, | ||
rustc_version, | ||
); | ||
|
||
options.skip_target_dir = true; | ||
|
||
cross::install_interpreter_if_needed( | ||
&args, | ||
host_version_meta, | ||
&target, | ||
&options, | ||
msg_info, | ||
)?; | ||
|
||
let status = docker::run(options, paths, &filtered_args, msg_info) | ||
.wrap_err("could not run container")?; | ||
if !status.success() { | ||
cross::warn_on_failure(&target, &toolchain, msg_info)?; | ||
} | ||
Ok(status) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod clean; | ||
mod containers; | ||
mod images; | ||
mod install; | ||
|
||
pub use self::clean::*; | ||
pub use self::containers::*; | ||
pub use self::images::*; | ||
pub use self::install::*; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ pub struct DockerOptions { | |
pub target: Target, | ||
pub config: Config, | ||
pub image: Image, | ||
pub skip_target_dir: bool, | ||
pub cargo_variant: CargoVariant, | ||
// not all toolchains will provide this | ||
pub rustc_version: Option<RustcVersion>, | ||
|
@@ -52,6 +53,7 @@ impl DockerOptions { | |
target, | ||
config, | ||
image, | ||
skip_target_dir: false, | ||
cargo_variant, | ||
rustc_version, | ||
} | ||
|
@@ -1039,8 +1041,11 @@ impl DockerCommandExt for Command { | |
"-e", | ||
&format!("CROSS_RUST_SYSROOT={}", dirs.sysroot_mount_path()), | ||
]) | ||
.args(["-e", "CARGO_TARGET_DIR=/target"]) | ||
.args(["-e", &cross_runner]); | ||
|
||
if !options.skip_target_dir { | ||
self.args(["-e", "CARGO_TARGET_DIR=/target"]); | ||
} | ||
if options.cargo_variant.uses_zig() { | ||
// otherwise, zig has a permission error trying to create the cache | ||
self.args(["-e", "XDG_CACHE_HOME=/target/.zig-cache"]); | ||
Comment on lines
-1042
to
1051
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this comment about zig a problem? |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not implemented