Skip to content

Cross with managed volumes #131

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

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main() {
cargo init --lib --name foo $td
pushd $td
echo '#![no_std]' > src/lib.rs
cross check --target $TARGET
cross +nightly check --target $TARGET
popd
rm -rf $td
fi
Expand All @@ -37,7 +37,7 @@ main() {
https://github.com/japaric/cortest $td

pushd $td
cross run --target $TARGET --example hello --release
cross +nightly run --target $TARGET --example hello --release
popd

rm -rf $td
Expand All @@ -58,7 +58,7 @@ main() {
[build]
xargo = true
EOF
cross build --features c --lib --target $TARGET
cross +nightly build --features c --lib --target $TARGET
popd

rm -rf $td
Expand All @@ -73,7 +73,7 @@ EOF
git clone --depth 1 https://github.com/rust-lang/cargo $td

pushd $td
cross build --target $TARGET
cross +nightly build --target $TARGET
popd

rm -rf $td
Expand All @@ -84,7 +84,7 @@ EOF
git clone --depth 1 https://github.com/bluss/rust-itertools $td

pushd $td
cross build --target $TARGET
cross +nightly build --target $TARGET
popd

rm -rf $td
Expand All @@ -94,7 +94,7 @@ EOF
git clone --depth 1 https://github.com/japaric/xargo $td

pushd $td
cross build --target $TARGET
cross +nightly build --target $TARGET
popd

rm -rf $td
Expand All @@ -112,7 +112,7 @@ EOF
$td

pushd $td
cross test \
cross +nightly test \
--no-default-features \
--features "gen-tests mangled-names" \
--target $TARGET
Expand All @@ -130,9 +130,9 @@ EOF
mkdir examples tests
echo "fn main() { println!(\"Example!\"); }" > examples/e.rs
echo "#[test] fn t() {}" > tests/t.rs
cross run --target $TARGET
cross run --target $TARGET --example e
cross test --target $TARGET
cross +nightly run --target $TARGET
cross +nightly run --target $TARGET --example e
cross +nightly test --target $TARGET
popd

rm -rf $td
Expand All @@ -147,9 +147,9 @@ EOF
pushd $td
cargo update -p gcc
if [ $RUN ]; then
cross run --target $TARGET
cross +nightly run --target $TARGET
else
cross build --target $TARGET
cross +nightly build --target $TARGET
fi
popd

Expand All @@ -173,7 +173,7 @@ EOF
pushd $td
# avoid problems building openssl-sys in a virtual workspace
rm -f Cargo.toml
cd openssl-sys && cross build --target $TARGET
cd openssl-sys && cross +nightly build --target $TARGET
popd

rm -rf $td
Expand Down
16 changes: 0 additions & 16 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ pub enum Subcommand {
Deb,
}

impl Subcommand {
pub fn needs_docker(&self) -> bool {
match *self {
Subcommand::Other => false,
_ => true,
}
}

pub fn needs_interpreter(&self) -> bool {
match *self {
Subcommand::Run | Subcommand::Test => true,
_ => false,
}
}
}

impl<'a> From<&'a str> for Subcommand {
fn from(s: &str) -> Subcommand {
match s {
Expand Down
23 changes: 15 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@ use std::env;

use Target;
use cargo::Subcommand;
use rustc::TargetList;

pub struct Args {
pub all: Vec<String>,
pub subcommand: Option<Subcommand>,
pub target: Option<Target>,
pub toolchain: Option<String>,
}

pub fn parse(target_list: &TargetList) -> Args {
let all: Vec<_> = env::args().skip(1).collect();
pub fn parse() -> Args {
let mut all: Vec<_> = env::args().skip(1).collect();

let mut target = None;
let mut sc = None;
let mut tc = None;

// Attempt to find toolchain
if all.len() > 0 && all[0].starts_with('+') && tc.is_none() {
tc = Some(all[0][1..].to_owned());
all.remove(0);
}

{
let mut args = all.iter();
while let Some(arg) = args.next() {
if !arg.starts_with('-') && sc.is_none() {
sc = Some(Subcommand::from(&**arg))
sc = Some(Subcommand::from(&**arg));
continue;
}

if arg == "--target" {
target = args.next().map(|s| Target::from(&**s, target_list))
target = args.next().map(|s| Target::from(&**s))
} else if arg.starts_with("--target=") {
target = arg.splitn(2, '=')
.nth(1)
.map(|s| Target::from(&*s, target_list))
} else if !arg.starts_with('-') && sc.is_none() {
sc = Some(Subcommand::from(&**arg));
.map(|s| Target::from(&*s))
}
}
}
Expand All @@ -39,5 +45,6 @@ pub fn parse(target_list: &TargetList) -> Args {
all: all,
subcommand: sc,
target: target,
toolchain: tc,
}
}
42 changes: 8 additions & 34 deletions src/docker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::borrow::Cow;
use std::path::PathBuf;
use std::process::{Command, ExitStatus};
use std::{env, fs};

Expand All @@ -10,7 +9,7 @@ use cargo::Root;
use errors::*;
use extensions::CommandExt;
use id;
use rustc;
use volume::VolumeInfo;

lazy_static! {
/// Retrieve the Docker Daemon version.
Expand Down Expand Up @@ -48,47 +47,20 @@ pub fn docker_command(subcommand: &str) -> Command {
docker
}

/// Register binfmt interpreters
pub fn register(target: &Target, verbose: bool) -> Result<()> {
let cmd = if target.is_windows() {
// https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html
"mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc && \
echo ':wine:M::MZ::/usr/bin/run-detectors:' > /proc/sys/fs/binfmt_misc/register"
} else {
"apt-get update && apt-get install --no-install-recommends -y \
binfmt-support qemu-user-static"
};
docker_command("run")
.arg("--privileged")
.arg("--rm")
.arg("-it")
.arg("ubuntu:16.04")
.args(&["sh", "-c", cmd])
.run(verbose)
}

pub fn run(target: &Target,
args: &[String],
root: &Root,
toml: Option<&Toml>,
uses_xargo: bool,
verbose: bool)
verbose: bool,
vol_info: &VolumeInfo)
-> Result<ExitStatus> {
let root = root.path();
let home_dir = env::home_dir().ok_or_else(|| "couldn't get home directory. Is $HOME not set?")?;
let cargo_dir = env::var_os("CARGO_HOME")
.map(PathBuf::from)
.unwrap_or_else(|| home_dir.join(".cargo"));
let xargo_dir = env::var_os("XARGO_HOME")
.map(PathBuf::from)
.unwrap_or_else(|| home_dir.join(".xargo"));
let target_dir = root.join("target");

// create the directories we are going to mount before we mount them,
// otherwise `docker` will create them but they will be owned by `root`
fs::create_dir(&target_dir).ok();
fs::create_dir(&cargo_dir).ok();
fs::create_dir(&xargo_dir).ok();

let mut cmd = if uses_xargo {
Command::new("xargo")
Expand Down Expand Up @@ -133,10 +105,12 @@ pub fn run(target: &Target,

docker
.args(&["-e", "XARGO_HOME=/xargo"])
.args(&["-v", &format!("{}:/xargo", xargo_dir.display())])
.args(&["-v", &format!("{}:/cargo", cargo_dir.display())])

.args(&["-v", &format!("{}:/xargo", &vol_info.xargo_dir)])
.args(&["-v", &format!("{}:/cargo", &vol_info.cargo_dir)])
.args(&["-v", &format!("{}:/rust:ro", &vol_info.rust_dir)])

.args(&["-v", &format!("{}:/project:ro", root.display())])
.args(&["-v", &format!("{}:/rust:ro", rustc::sysroot(verbose)?.display())])
.args(&["-v", &format!("{}:/target", target_dir.display())])
.args(&["-w", "/project"])
.args(&["-it", &image(toml, target)?])
Expand Down
28 changes: 0 additions & 28 deletions src/interpreter.rs

This file was deleted.

Loading