Skip to content

Commit 117984b

Browse files
committed
rustc: Start "stabilizing" some flags
This commit shuffles around some CLI flags of the compiler to some more stable locations with some renamings. The changes made were: * The `-v` flag has been repurposes as the "verbose" flag. The version flag has been renamed to `-V`. * The `-h` screen has been split into two parts. Most top-level options (not all) show with `-h`, and the remaining options (generally obscure) can be shown with `--help -v` which is a "verbose help screen" * The `-V` flag (version flag now) has lost its argument as it is now requested with `rustc -vV` "verbose version". * The `--emit` option has had its `ir` and `bc` variants renamed to `llvm-ir` and `llvm-bc` to emphasize that they are LLVM's IR/bytecode. * The `--emit` option has grown a new variant, `dep-info`, which subsumes the `--dep-info` CLI argument. The `--dep-info` flag is now deprecated. * The `--parse-only`, `--no-trans`, and `--no-analysis` flags have moved behind the `-Z` family of flags. * The `--debuginfo` and `--opt-level` flags were moved behind the top-level `-C` flag. * The `--print-file-name` and `--print-crate-name` flags were moved behind one global `--print` flag which now accepts one of `crate-name`, `file-names`, or `sysroot`. This global `--print` flag is intended to serve as a mechanism for learning various metadata about the compiler itself. No warnings are currently enabled to allow tools like Cargo to have time to migrate to the new flags before spraying warnings to all users.
1 parent f9a4849 commit 117984b

File tree

16 files changed

+276
-154
lines changed

16 files changed

+276
-154
lines changed

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
16661666
// FIXME (#9639): This needs to handle non-utf8 paths
16671667
let mut link_args = vec!("-L".to_string(),
16681668
aux_dir.as_str().unwrap().to_string());
1669-
let llvm_args = vec!("--emit=bc,obj".to_string(),
1669+
let llvm_args = vec!("--emit=llvm-bc,obj".to_string(),
16701670
"--crate-type=lib".to_string());
16711671
link_args.extend(llvm_args.into_iter());
16721672
let args = make_compile_args(config,

src/etc/rust-lldb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TMPFILE=`mktemp /tmp/rust-lldb-commands.XXXXXX`
1919
trap "rm -f $TMPFILE; exit" INT TERM EXIT
2020

2121
# Find out where to look for the pretty printer Python module
22-
RUSTC_SYSROOT=`rustc -Zprint-sysroot`
22+
RUSTC_SYSROOT=`rustc --print sysroot`
2323

2424
# Write the LLDB script to the tempfile
2525
echo "command script import \"$RUSTC_SYSROOT/lib/rustlib/etc/lldb_rust_formatters.py\"" >> $TMPFILE

src/librustc/session/config.rs

+190-70
Large diffs are not rendered by default.

src/librustc_driver/lib.rs

+63-56
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use syntax::diagnostic;
4646

4747
use rustc_trans::back::link;
4848
use rustc::session::{config, Session, build_session};
49-
use rustc::session::config::Input;
49+
use rustc::session::config::{Input, PrintRequest};
5050
use rustc::lint::Lint;
5151
use rustc::lint;
5252
use rustc::metadata;
@@ -101,6 +101,8 @@ fn run_compiler(args: &[String]) {
101101
}
102102

103103
let sopts = config::build_session_options(&matches);
104+
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
105+
let ofile = matches.opt_str("o").map(|o| Path::new(o));
104106
let (input, input_file_path) = match matches.free.len() {
105107
0u => {
106108
if sopts.describe_lints {
@@ -109,13 +111,10 @@ fn run_compiler(args: &[String]) {
109111
describe_lints(&ls, false);
110112
return;
111113
}
112-
113114
let sess = build_session(sopts, None, descriptions);
114-
if sess.debugging_opt(config::PRINT_SYSROOT) {
115-
println!("{}", sess.sysroot().display());
115+
if print_crate_info(&sess, None, &odir, &ofile) {
116116
return;
117117
}
118-
119118
early_error("no input filename given");
120119
}
121120
1u => {
@@ -133,13 +132,14 @@ fn run_compiler(args: &[String]) {
133132

134133
let sess = build_session(sopts, input_file_path, descriptions);
135134
let cfg = config::build_configuration(&sess);
136-
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
137-
let ofile = matches.opt_str("o").map(|o| Path::new(o));
135+
if print_crate_info(&sess, Some(&input), &odir, &ofile) {
136+
return
137+
}
138138

139139
let pretty = matches.opt_default("pretty", "normal").map(|a| {
140140
pretty::parse_pretty(&sess, a.as_slice())
141141
});
142-
match pretty {
142+
match pretty.into_iter().next() {
143143
Some((ppm, opt_uii)) => {
144144
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
145145
return;
@@ -161,10 +161,6 @@ fn run_compiler(args: &[String]) {
161161
return;
162162
}
163163

164-
if print_crate_info(&sess, &input, &odir, &ofile) {
165-
return;
166-
}
167-
168164
driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
169165
}
170166

@@ -185,12 +181,8 @@ pub fn commit_date_str() -> Option<&'static str> {
185181

186182
/// Prints version information and returns None on success or an error
187183
/// message on panic.
188-
pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
189-
let verbose = match matches.opt_str("version").as_ref().map(|s| s.as_slice()) {
190-
None => false,
191-
Some("verbose") => true,
192-
Some(s) => return Some(format!("Unrecognized argument: {}", s))
193-
};
184+
pub fn version(binary: &str, matches: &getopts::Matches) {
185+
let verbose = matches.opt_present("verbose");
194186

195187
println!("{} {}", binary, option_env!("CFG_VERSION").unwrap_or("unknown version"));
196188
if verbose {
@@ -201,18 +193,27 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
201193
println!("host: {}", config::host_triple());
202194
println!("release: {}", unw(release_str()));
203195
}
204-
None
205196
}
206197

207-
fn usage() {
198+
fn usage(verbose: bool) {
199+
let groups = if verbose {
200+
config::optgroups()
201+
} else {
202+
config::short_optgroups()
203+
};
208204
let message = format!("Usage: rustc [OPTIONS] INPUT");
205+
let extra_help = if verbose {
206+
""
207+
} else {
208+
"\n --help -v Print the full set of options rustc accepts"
209+
};
209210
println!("{}\n\
210211
Additional help:
211212
-C help Print codegen options
212213
-W help Print 'lint' options and default settings
213-
-Z help Print internal options for debugging rustc\n",
214-
getopts::usage(message.as_slice(),
215-
config::optgroups().as_slice()));
214+
-Z help Print internal options for debugging rustc{}\n",
215+
getopts::usage(message.as_slice(), groups.as_slice()),
216+
extra_help);
216217
}
217218

218219
fn describe_lints(lint_store: &lint::LintStore, loaded_plugins: bool) {
@@ -360,7 +361,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
360361
let _binary = args.remove(0).unwrap();
361362

362363
if args.is_empty() {
363-
usage();
364+
usage(false);
364365
return None;
365366
}
366367

@@ -373,7 +374,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
373374
};
374375

375376
if matches.opt_present("h") || matches.opt_present("help") {
376-
usage();
377+
usage(matches.opt_present("verbose"));
377378
return None;
378379
}
379380

@@ -397,49 +398,55 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
397398
}
398399

399400
if matches.opt_present("version") {
400-
match version("rustc", &matches) {
401-
Some(err) => early_error(err.as_slice()),
402-
None => return None
403-
}
401+
version("rustc", &matches);
402+
return None;
404403
}
405404

406405
Some(matches)
407406
}
408407

409408
fn print_crate_info(sess: &Session,
410-
input: &Input,
409+
input: Option<&Input>,
411410
odir: &Option<Path>,
412411
ofile: &Option<Path>)
413412
-> bool {
414-
let (crate_name, crate_file_name) = sess.opts.print_metas;
415-
// these nasty nested conditions are to avoid doing extra work
416-
if crate_name || crate_file_name {
417-
let attrs = parse_crate_attrs(sess, input);
418-
let t_outputs = driver::build_output_filenames(input,
419-
odir,
420-
ofile,
421-
attrs.as_slice(),
422-
sess);
423-
let id = link::find_crate_name(Some(sess), attrs.as_slice(), input);
424-
425-
if crate_name {
426-
println!("{}", id);
427-
}
428-
if crate_file_name {
429-
let crate_types = driver::collect_crate_types(sess, attrs.as_slice());
430-
let metadata = driver::collect_crate_metadata(sess, attrs.as_slice());
431-
*sess.crate_metadata.borrow_mut() = metadata;
432-
for &style in crate_types.iter() {
433-
let fname = link::filename_for_input(sess, style, id.as_slice(),
434-
&t_outputs.with_extension(""));
435-
println!("{}", fname.filename_display());
413+
if sess.opts.prints.len() == 0 { return false }
414+
415+
let attrs = input.map(|input| parse_crate_attrs(sess, input));
416+
for req in sess.opts.prints.iter() {
417+
match *req {
418+
PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
419+
PrintRequest::FileNames |
420+
PrintRequest::CrateName => {
421+
let input = match input {
422+
Some(input) => input,
423+
None => early_error("no input file provided"),
424+
};
425+
let attrs = attrs.as_ref().unwrap().as_slice();
426+
let t_outputs = driver::build_output_filenames(input,
427+
odir,
428+
ofile,
429+
attrs,
430+
sess);
431+
let id = link::find_crate_name(Some(sess), attrs.as_slice(),
432+
input);
433+
if *req == PrintRequest::CrateName {
434+
println!("{}", id);
435+
continue
436+
}
437+
let crate_types = driver::collect_crate_types(sess, attrs);
438+
let metadata = driver::collect_crate_metadata(sess, attrs);
439+
*sess.crate_metadata.borrow_mut() = metadata;
440+
for &style in crate_types.iter() {
441+
let fname = link::filename_for_input(sess, style,
442+
id.as_slice(),
443+
&t_outputs.with_extension(""));
444+
println!("{}", fname.filename_display());
445+
}
436446
}
437447
}
438-
439-
true
440-
} else {
441-
false
442448
}
449+
return true;
443450
}
444451

445452
fn parse_crate_attrs(sess: &Session, input: &Input) ->

src/librustc_trans/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ pub fn run_passes(sess: &Session,
607607
modules_config.emit_obj = true;
608608
metadata_config.emit_obj = true;
609609
},
610+
config::OutputTypeDepInfo => {}
610611
}
611612
}
612613

@@ -779,6 +780,7 @@ pub fn run_passes(sess: &Session,
779780
link_obj(&crate_output.temp_path(config::OutputTypeObject));
780781
}
781782
}
783+
config::OutputTypeDepInfo => {}
782784
}
783785
}
784786
let user_wants_bitcode = user_wants_bitcode;

src/librustdoc/lib.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,8 @@ pub fn main_args(args: &[String]) -> int {
169169
usage(args[0].as_slice());
170170
return 0;
171171
} else if matches.opt_present("version") {
172-
match rustc_driver::version("rustdoc", &matches) {
173-
Some(err) => {
174-
println!("{}", err);
175-
return 1
176-
},
177-
None => return 0
178-
}
172+
rustc_driver::version("rustdoc", &matches);
173+
return 0;
179174
}
180175

181176
if matches.opt_strs("passes") == ["list"] {

src/test/run-make/dep-info-custom/Makefile.foo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LIB := $(shell $(RUSTC) --crate-file-name --crate-type=lib lib.rs)
1+
LIB := $(shell $(RUSTC) --print file-names --crate-type=lib lib.rs)
22

33
$(TMPDIR)/$(LIB):
44
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
LIB := $(shell $(RUSTC) --crate-file-name --crate-type=lib lib.rs)
1+
LIB := $(shell $(RUSTC) --print file-names --crate-type=lib lib.rs)
22

33
$(TMPDIR)/$(LIB):
4-
$(RUSTC) --dep-info --crate-type=lib lib.rs
4+
$(RUSTC) --emit dep-info,link --crate-type=lib lib.rs
55
touch $(TMPDIR)/done
66

77
-include $(TMPDIR)/foo.d

src/test/run-make/issue-7349/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
# used in the inner functions should each appear only once in the generated IR.
77

88
all:
9-
$(RUSTC) foo.rs --emit=ir
9+
$(RUSTC) foo.rs --emit=llvm-ir
1010
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
1111
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]

src/test/run-make/libs-through-symlinks/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ifdef IS_WINDOWS
44
all:
55
else
66

7-
NAME := $(shell $(RUSTC) --crate-file-name foo.rs)
7+
NAME := $(shell $(RUSTC) --print file-names foo.rs)
88

99
all:
1010
mkdir -p $(TMPDIR)/outdir

src/test/run-make/output-type-permutations/Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all:
1212
rm $(TMPDIR)/$(call BIN,bar)
1313
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
1414

15-
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link
15+
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link
1616
rm $(TMPDIR)/bar.ll
1717
rm $(TMPDIR)/bar.bc
1818
rm $(TMPDIR)/bar.s
@@ -24,11 +24,11 @@ all:
2424
rm $(TMPDIR)/foo
2525
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
2626

27-
$(RUSTC) foo.rs --emit=bc -o $(TMPDIR)/foo
27+
$(RUSTC) foo.rs --emit=llvm-bc -o $(TMPDIR)/foo
2828
rm $(TMPDIR)/foo
2929
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
3030

31-
$(RUSTC) foo.rs --emit=ir -o $(TMPDIR)/foo
31+
$(RUSTC) foo.rs --emit=llvm-ir -o $(TMPDIR)/foo
3232
rm $(TMPDIR)/foo
3333
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
3434

@@ -56,7 +56,7 @@ all:
5656
rm $(TMPDIR)/$(call BIN,foo)
5757
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
5858

59-
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
59+
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link --crate-type=staticlib
6060
rm $(TMPDIR)/bar.ll
6161
rm $(TMPDIR)/bar.s
6262
rm $(TMPDIR)/bar.o
@@ -65,7 +65,7 @@ all:
6565
# Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later
6666
# comparison.
6767

68-
$(RUSTC) foo.rs --emit=bc,link --crate-type=rlib
68+
$(RUSTC) foo.rs --emit=llvm-bc,link --crate-type=rlib
6969
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
7070
rm $(TMPDIR)/bar.bc
7171
rm $(TMPDIR)/foo.bc

src/test/run-make/sepcomp-cci-copies/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
all:
77
$(RUSTC) cci_lib.rs
8-
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
8+
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
99
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*cci_fn)" -eq "2" ]

src/test/run-make/sepcomp-inlining/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# function should be defined in only one compilation unit.
77

88
all:
9-
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
9+
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
1010
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ i32\ .*inlined)" -eq "1" ]
1111
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ available_externally\ i32\ .*inlined)" -eq "2" ]
1212
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ i32\ .*normal)" -eq "1" ]

src/test/run-make/sepcomp-separate/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# wind up in three different compilation units.
66

77
all:
8-
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
8+
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
99
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*magic_fn)" -eq "3" ]

src/test/run-make/version/Makefile

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) -v
5-
$(RUSTC) -v verbose
6-
$(RUSTC) -v bad_arg && exit 1 || exit 0
7-
$(RUSTC) --version verbose
8-
$(RUSTC) --version bad_arg && exit 1 || exit 0
4+
$(RUSTC) -V
5+
$(RUSTC) -vV
6+
$(RUSTC) --version --verbose

src/test/run-make/volatile-intrinsics/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ all:
55
$(RUSTC) main.rs
66
$(call RUN,main)
77
# ... and the loads/stores must not be optimized out.
8-
$(RUSTC) main.rs --emit=ir
8+
$(RUSTC) main.rs --emit=llvm-ir
99
grep "load volatile" $(TMPDIR)/main.ll
1010
grep "store volatile" $(TMPDIR)/main.ll

0 commit comments

Comments
 (0)