Skip to content

Commit 7720cf0

Browse files
committed
Change --crate-type metadata to --emit=metadata
1 parent 4ecc85b commit 7720cf0

File tree

18 files changed

+61
-56
lines changed

18 files changed

+61
-56
lines changed

src/librustc/middle/dependency_format.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ pub fn calculate(sess: &session::Session) {
103103

104104
fn calculate_type(sess: &session::Session,
105105
ty: config::CrateType) -> DependencyList {
106+
if sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
107+
return Vec::new();
108+
}
109+
106110
match ty {
107111
// If the global prefer_dynamic switch is turned off, first attempt
108112
// static linkage (this can fail).
@@ -114,7 +118,7 @@ fn calculate_type(sess: &session::Session,
114118

115119
// No linkage happens with rlibs, we just needed the metadata (which we
116120
// got long ago), so don't bother with anything.
117-
config::CrateTypeRlib | config::CrateTypeMetadata => return Vec::new(),
121+
config::CrateTypeRlib => return Vec::new(),
118122

119123
// Staticlibs and cdylibs must have all static dependencies. If any fail
120124
// to be found, we generate some nice pretty errors.

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
139139
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
140140
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
141141
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
142-
*ty == config::CrateTypeProcMacro || *ty == config::CrateTypeMetadata
142+
*ty == config::CrateTypeProcMacro
143143
});
144144
ReachableContext {
145145
tcx: tcx,

src/librustc/middle/weak_lang_items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
7575
config::CrateTypeCdylib |
7676
config::CrateTypeExecutable |
7777
config::CrateTypeStaticlib => true,
78-
config::CrateTypeRlib |
79-
config::CrateTypeMetadata => false,
78+
config::CrateTypeRlib => false,
8079
}
8180
});
8281
if !needs_check {

src/librustc/session/config.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub enum OutputType {
7373
Bitcode,
7474
Assembly,
7575
LlvmAssembly,
76+
Metadata,
7677
Object,
7778
Exe,
7879
DepInfo,
@@ -86,7 +87,8 @@ impl OutputType {
8687
OutputType::Bitcode |
8788
OutputType::Assembly |
8889
OutputType::LlvmAssembly |
89-
OutputType::Object => false,
90+
OutputType::Object |
91+
OutputType::Metadata => false,
9092
}
9193
}
9294

@@ -96,6 +98,7 @@ impl OutputType {
9698
OutputType::Assembly => "asm",
9799
OutputType::LlvmAssembly => "llvm-ir",
98100
OutputType::Object => "obj",
101+
OutputType::Metadata => "metadata",
99102
OutputType::Exe => "link",
100103
OutputType::DepInfo => "dep-info",
101104
}
@@ -107,6 +110,7 @@ impl OutputType {
107110
OutputType::Assembly => "s",
108111
OutputType::LlvmAssembly => "ll",
109112
OutputType::Object => "o",
113+
OutputType::Metadata => "rmeta",
110114
OutputType::DepInfo => "d",
111115
OutputType::Exe => "",
112116
}
@@ -482,7 +486,6 @@ pub enum CrateType {
482486
CrateTypeStaticlib,
483487
CrateTypeCdylib,
484488
CrateTypeProcMacro,
485-
CrateTypeMetadata,
486489
}
487490

488491
#[derive(Clone, Hash)]
@@ -1159,12 +1162,12 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11591162
assumed.", "[KIND=]NAME"),
11601163
opt::multi_s("", "crate-type", "Comma separated list of types of crates
11611164
for the compiler to emit",
1162-
"[bin|lib|rlib|dylib|cdylib|staticlib|metadata]"),
1165+
"[bin|lib|rlib|dylib|cdylib|staticlib]"),
11631166
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
11641167
"NAME"),
11651168
opt::multi_s("", "emit", "Comma separated list of types of output for \
11661169
the compiler to emit",
1167-
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
1170+
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info]"),
11681171
opt::multi_s("", "print", "Comma separated list of compiler information to \
11691172
print on stdout", &print_opts.join("|")),
11701173
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
@@ -1327,6 +1330,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
13271330
"llvm-ir" => OutputType::LlvmAssembly,
13281331
"llvm-bc" => OutputType::Bitcode,
13291332
"obj" => OutputType::Object,
1333+
"metadata" => OutputType::Metadata,
13301334
"link" => OutputType::Exe,
13311335
"dep-info" => OutputType::DepInfo,
13321336
part => {
@@ -1553,7 +1557,6 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
15531557
"cdylib" => CrateTypeCdylib,
15541558
"bin" => CrateTypeExecutable,
15551559
"proc-macro" => CrateTypeProcMacro,
1556-
"metadata" => CrateTypeMetadata,
15571560
_ => {
15581561
return Err(format!("unknown crate type: `{}`",
15591562
part));
@@ -1638,7 +1641,6 @@ impl fmt::Display for CrateType {
16381641
CrateTypeStaticlib => "staticlib".fmt(f),
16391642
CrateTypeCdylib => "cdylib".fmt(f),
16401643
CrateTypeProcMacro => "proc-macro".fmt(f),
1641-
CrateTypeMetadata => "metadata".fmt(f),
16421644
}
16431645
}
16441646
}

src/librustc_driver/driver.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,6 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
11821182
Some(ref n) if *n == "rlib" => {
11831183
Some(config::CrateTypeRlib)
11841184
}
1185-
Some(ref n) if *n == "metadata" => {
1186-
Some(config::CrateTypeMetadata)
1187-
}
11881185
Some(ref n) if *n == "dylib" => {
11891186
Some(config::CrateTypeDylib)
11901187
}

src/librustc_driver/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
493493
control.after_hir_lowering.stop = Compilation::Stop;
494494
}
495495

496-
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
496+
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe ||
497+
i == OutputType::Metadata) {
497498
control.after_llvm.stop = Compilation::Stop;
498499
}
499500

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,7 @@ impl<'a> CrateLoader<'a> {
799799
config::CrateTypeProcMacro |
800800
config::CrateTypeCdylib |
801801
config::CrateTypeStaticlib => need_lib_alloc = true,
802-
config::CrateTypeRlib |
803-
config::CrateTypeMetadata => {}
802+
config::CrateTypeRlib => {}
804803
}
805804
}
806805
if !need_lib_alloc && !need_exe_alloc { return }

src/librustc_trans/back/link.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ pub fn link_binary(sess: &Session,
191191
let mut out_filenames = Vec::new();
192192
for &crate_type in sess.crate_types.borrow().iter() {
193193
// Ignore executable crates if we have -Z no-trans, as they will error.
194-
if sess.opts.debugging_opts.no_trans &&
194+
if (sess.opts.debugging_opts.no_trans ||
195+
sess.opts.output_types.contains_key(&OutputType::Metadata)) &&
195196
crate_type == config::CrateTypeExecutable {
196197
continue;
197198
}
@@ -200,15 +201,16 @@ pub fn link_binary(sess: &Session,
200201
bug!("invalid output type `{:?}` for target os `{}`",
201202
crate_type, sess.opts.target_triple);
202203
}
203-
let out_file = link_binary_output(sess, trans, crate_type, outputs,
204-
crate_name);
204+
let out_file = link_binary_output(sess, trans, crate_type, outputs, crate_name);
205205
out_filenames.push(out_file);
206206
}
207207

208208
// Remove the temporary object file and metadata if we aren't saving temps
209209
if !sess.opts.cg.save_temps {
210-
for obj in object_filenames(trans, outputs) {
211-
remove(sess, &obj);
210+
if !sess.opts.output_types.contains_key(&OutputType::Metadata) {
211+
for obj in object_filenames(trans, outputs) {
212+
remove(sess, &obj);
213+
}
212214
}
213215
remove(sess, &outputs.with_extension("metadata.o"));
214216
}
@@ -259,13 +261,15 @@ pub fn filename_for_input(sess: &Session,
259261
crate_name: &str,
260262
outputs: &OutputFilenames) -> PathBuf {
261263
let libname = format!("{}{}", crate_name, sess.opts.cg.extra_filename);
264+
265+
if outputs.outputs.contains_key(&OutputType::Metadata) {
266+
return outputs.out_directory.join(&format!("lib{}.rmeta", libname));
267+
}
268+
262269
match crate_type {
263270
config::CrateTypeRlib => {
264271
outputs.out_directory.join(&format!("lib{}.rlib", libname))
265272
}
266-
config::CrateTypeMetadata => {
267-
outputs.out_directory.join(&format!("lib{}.rmeta", libname))
268-
}
269273
config::CrateTypeCdylib |
270274
config::CrateTypeProcMacro |
271275
config::CrateTypeDylib => {
@@ -351,20 +355,21 @@ fn link_binary_output(sess: &Session,
351355
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
352356
};
353357

354-
match crate_type {
355-
config::CrateTypeRlib => {
356-
link_rlib(sess, Some(trans), &objects, &out_filename,
357-
tmpdir.path()).build();
358-
}
359-
config::CrateTypeStaticlib => {
360-
link_staticlib(sess, &objects, &out_filename, tmpdir.path());
361-
}
362-
config::CrateTypeMetadata => {
363-
emit_metadata(sess, trans, &out_filename);
364-
}
365-
_ => {
366-
link_natively(sess, crate_type, &objects, &out_filename, trans,
367-
outputs, tmpdir.path());
358+
if outputs.outputs.contains_key(&OutputType::Metadata) {
359+
emit_metadata(sess, trans, &out_filename);
360+
} else {
361+
match crate_type {
362+
config::CrateTypeRlib => {
363+
link_rlib(sess, Some(trans), &objects, &out_filename,
364+
tmpdir.path()).build();
365+
}
366+
config::CrateTypeStaticlib => {
367+
link_staticlib(sess, &objects, &out_filename, tmpdir.path());
368+
}
369+
_ => {
370+
link_natively(sess, crate_type, &objects, &out_filename, trans,
371+
outputs, tmpdir.path());
372+
}
368373
}
369374
}
370375

src/librustc_trans/back/lto.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool {
3434

3535
config::CrateTypeDylib |
3636
config::CrateTypeRlib |
37-
config::CrateTypeMetadata |
3837
config::CrateTypeProcMacro => false,
3938
}
4039
}

src/librustc_trans/back/symbol_export.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ pub fn crate_export_threshold(crate_type: config::CrateType)
149149
config::CrateTypeProcMacro |
150150
config::CrateTypeCdylib => SymbolExportLevel::C,
151151
config::CrateTypeRlib |
152-
config::CrateTypeMetadata |
153152
config::CrateTypeDylib => SymbolExportLevel::Rust,
154153
}
155154
}

0 commit comments

Comments
 (0)