-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
rustc subcommand #1568
rustc subcommand #1568
Changes from 3 commits
754938f
77bb01e
b177d2a
512b217
53453c8
582e9d9
d8cd6f0
bd4d15f
c867813
dc33bfa
98c0e2d
2cd3c86
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,96 @@ | ||
use std::env; | ||
|
||
use cargo::ops::CompileOptions; | ||
use cargo::ops; | ||
use cargo::util::important_paths::{find_root_manifest_for_cwd}; | ||
use cargo::util::{CliResult, CliError, Config}; | ||
|
||
#[derive(RustcDecodable)] | ||
struct Options { | ||
arg_pkgid: Option<String>, | ||
arg_opts: Option<Vec<String>>, | ||
flag_profile: Option<String>, | ||
flag_jobs: Option<u32>, | ||
flag_features: Vec<String>, | ||
flag_no_default_features: bool, | ||
flag_target: Option<String>, | ||
flag_manifest_path: Option<String>, | ||
flag_verbose: bool, | ||
flag_release: bool, | ||
flag_lib: bool, | ||
flag_bin: Vec<String>, | ||
flag_example: Vec<String>, | ||
flag_test: Vec<String>, | ||
flag_bench: Vec<String>, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Compile a package and all of its dependencies | ||
|
||
Usage: | ||
cargo rustc [options] [<pkgid>] [--] [<opts>...] | ||
|
||
Options: | ||
-h, --help Print this message | ||
-p, --profile PROFILE The profile to compile for | ||
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. Ah I think that this flag (although I spec'd it originally) can just be removed |
||
-j N, --jobs N The number of jobs to run in parallel | ||
--lib Build only this package's library | ||
--bin NAME Build only the specified binary | ||
--example NAME Build only the specified example | ||
--test NAME Build only the specified test | ||
--bench NAME Build only the specified benchmark | ||
--release Build artifacts in release mode, with optimizations | ||
--features FEATURES Features to compile for the package | ||
--no-default-features Do not compile default features for the package | ||
--target TRIPLE Target triple which compiles will be for | ||
--manifest-path PATH Path to the manifest to fetch depednencies for | ||
-v, --verbose Use verbose output | ||
|
||
The <pkgid> specified (defaults to the current package) will have all of its | ||
dependencies compiled, and then the package itself will be compiled. This | ||
command requires that a lockfile is available and dependencies have been | ||
fetched. | ||
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. I think that this documentation may want to be touched up a bit, perhaps something along the lines of:
|
||
|
||
All of the trailing arguments are passed through to the *final* rustc | ||
invocation, not any of the dependencies. | ||
|
||
Dependencies will not be recompiled if they do not need to be, but the package | ||
specified will always be compiled. The compiler will receive a number of | ||
arguments unconditionally such as --extern, -L, etc. Note that dependencies are | ||
recompiled when the flags they're compiled with change, so it is not allowed to | ||
manually compile a package's dependencies and then compile the package against | ||
the artifacts just generated. | ||
"; | ||
|
||
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { | ||
debug!("executing; cmd=cargo-rustc; args={:?}", | ||
env::args().collect::<Vec<_>>()); | ||
config.shell().set_verbose(options.flag_verbose); | ||
|
||
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); | ||
let spec = options.arg_pkgid.as_ref().map(|s| &s[..]); | ||
|
||
let opts = CompileOptions { | ||
config: config, | ||
jobs: options.flag_jobs, | ||
target: options.flag_target.as_ref().map(|t| &t[..]), | ||
features: &options.flag_features, | ||
no_default_features: options.flag_no_default_features, | ||
spec: spec, | ||
exec_engine: None, | ||
mode: ops::CompileMode::Build, | ||
release: options.flag_release, | ||
filter: ops::CompileFilter::new(options.flag_lib, | ||
&options.flag_bin, | ||
&options.flag_test, | ||
&options.flag_example, | ||
&options.flag_bench), | ||
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]), | ||
}; | ||
|
||
ops::compile(&root, &opts).map(|_| None).map_err(|err| { | ||
CliError::from_boxed(err, 101) | ||
}) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ pub struct BuildConfig { | |
pub exec_engine: Option<Arc<Box<ExecEngine>>>, | ||
pub release: bool, | ||
pub doc_all: bool, | ||
pub target_rustc_args: Option<Vec<String>>, | ||
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. I think that it may be best to add this option to a By using a |
||
} | ||
|
||
#[derive(Clone, Default)] | ||
|
@@ -664,6 +665,10 @@ fn build_base_args(cx: &Context, | |
cmd.arg("-g"); | ||
} | ||
|
||
if let Some(ref args) = cx.build_config.target_rustc_args { | ||
cmd.args(args); | ||
} | ||
|
||
if debug_assertions && opt_level > 0 { | ||
cmd.args(&["-C", "debug-assertions=on"]); | ||
} else if !debug_assertions && opt_level == 0 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use std::path::MAIN_SEPARATOR as SEP; | ||
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. Very nice suite of tests! 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. Actually, what I would have liked is the ability to check the cargo ouput for |
||
use support::{execs, project, ProjectBuilder}; | ||
use support::{COMPILING, RUNNING}; | ||
use hamcrest::{assert_that}; | ||
|
||
fn setup() { | ||
} | ||
|
||
fn verbose_output_for_target(lib: bool, p: &ProjectBuilder) -> String { | ||
let (target, kind) = match lib { | ||
true => ("lib", "lib"), | ||
false => ("main", "bin"), | ||
}; | ||
format!("\ | ||
{compiling} {name} v{version} ({url}) | ||
{running} `rustc src{sep}{target}.rs --crate-name {name} --crate-type {kind} -g \ | ||
--out-dir {dir}{sep}target{sep}debug \ | ||
--emit=dep-info,link \ | ||
-L dependency={dir}{sep}target{sep}debug \ | ||
-L dependency={dir}{sep}target{sep}debug{sep}deps` | ||
", | ||
running = RUNNING, compiling = COMPILING, sep = SEP, | ||
dir = p.root().display(), url = p.url(), | ||
target = target, kind = kind, | ||
name = "foo", version = "0.0.1") | ||
} | ||
|
||
fn verbose_output_for_target_with_args(lib: bool, p: &ProjectBuilder, args: &str) -> String { | ||
verbose_output_for_target(lib, p).replace(" -g ", &format!(" -g {} ", args)) | ||
} | ||
|
||
test!(build_lib_for_foo { | ||
let p = project("foo") | ||
.file("Cargo.toml", r#" | ||
[package] | ||
|
||
name = "foo" | ||
version = "0.0.1" | ||
authors = ["wycats@example.com"] | ||
"#) | ||
.file("src/main.rs", r#" | ||
fn main() {} | ||
"#) | ||
.file("src/lib.rs", r#" "#); | ||
|
||
assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo"), | ||
execs() | ||
.with_status(0) | ||
.with_stdout(verbose_output_for_target(true, &p))); | ||
}); | ||
|
||
test!(build_lib_and_allow_unstable_options { | ||
let p = project("foo") | ||
.file("Cargo.toml", r#" | ||
[package] | ||
|
||
name = "foo" | ||
version = "0.0.1" | ||
authors = ["wycats@example.com"] | ||
"#) | ||
.file("src/main.rs", r#" | ||
fn main() {} | ||
"#) | ||
.file("src/lib.rs", r#" "#); | ||
|
||
assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo") | ||
.arg("--").arg("-Z").arg("unstable-options"), | ||
execs() | ||
.with_status(0) | ||
.with_stdout(verbose_output_for_target_with_args(true, &p, | ||
"-Z unstable-options"))); | ||
}); | ||
|
||
test!(build_main_and_allow_unstable_options { | ||
let p = project("foo") | ||
.file("Cargo.toml", r#" | ||
[package] | ||
|
||
name = "foo" | ||
version = "0.0.1" | ||
authors = ["wycats@example.com"] | ||
"#) | ||
.file("src/main.rs", r#" | ||
fn main() {} | ||
"#); | ||
|
||
assert_that(p.cargo_process("rustc").arg("-v").arg("foo") | ||
.arg("--").arg("-Z").arg("unstable-options"), | ||
execs() | ||
.with_status(0) | ||
.with_stdout(verbose_output_for_target_with_args(false, &p, | ||
"-Z unstable-options"))); | ||
}); |
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.
Ah when I originally wrote this spec we didn't have a
-p
argument, but nowadays this<pkgid>
argument should be specified through-p, --package
instead.