Skip to content

Commit

Permalink
skip target dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Mar 24, 2023
1 parent 7783c0b commit f3fe659
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
23 changes: 19 additions & 4 deletions src/bin/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use eyre::Context;
pub struct Install {
#[clap(long)]
target: Option<String>,
#[clap(long)]
root: String,
/// Provide verbose diagnostic output.
#[clap(short, long)]
pub verbose: bool,
Expand Down Expand Up @@ -50,6 +52,8 @@ impl Install {
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);
}
Expand Down Expand Up @@ -101,9 +105,19 @@ impl Install {

let cwd = std::env::current_dir()?;

let paths =
docker::DockerPaths::create(&engine, todo!(), cwd, toolchain.clone(), msg_info)?;
let options = docker::DockerOptions::new(
let paths = docker::DockerPaths::create(
&engine,
cross::CargoMetadata {
workspace_root: cwd.clone(),
target_directory: cross::file::absolute_path(self.root)?,
packages: vec![],
workspace_members: vec![],
},
cwd,
toolchain.clone(),
msg_info,
)?;
let mut options = docker::DockerOptions::new(
engine,
target.clone(),
config,
Expand All @@ -112,6 +126,8 @@ impl Install {
rustc_version,
);

options.skip_target_dir = true;

cross::install_interpreter_if_needed(
&args,
host_version_meta,
Expand All @@ -122,7 +138,6 @@ impl Install {

let status = docker::run(options, paths, &filtered_args, msg_info)
.wrap_err("could not run container")?;
let needs_host = args.subcommand.map_or(false, |sc| sc.needs_host(is_remote));
if !status.success() {
cross::warn_on_failure(&target, &toolchain, msg_info)?;
}
Expand Down
21 changes: 11 additions & 10 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,20 @@ pub(crate) fn run(
package_dirs.mount_root()
),
]);
docker
.args([
"-v",
&format!(
"{}:{}:z,ro",
toolchain_dirs.get_sysroot().to_utf8()?,
toolchain_dirs.sysroot_mount_path()
),
])
.args([
docker.args([
"-v",
&format!(
"{}:{}:z,ro",
toolchain_dirs.get_sysroot().to_utf8()?,
toolchain_dirs.sysroot_mount_path()
),
]);
if !options.skip_target_dir {
docker.args([
"-v",
&format!("{}:/target:z", package_dirs.target().to_utf8()?),
]);
}
docker.add_cwd(&paths)?;

// When running inside NixOS or using Nix packaging we need to add the Nix
Expand Down
7 changes: 6 additions & 1 deletion src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -52,6 +53,7 @@ impl DockerOptions {
target,
config,
image,
skip_target_dir: false,
cargo_variant,
rustc_version,
}
Expand Down Expand Up @@ -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"]);
Expand Down

0 comments on commit f3fe659

Please sign in to comment.