Skip to content

Commit b286a2f

Browse files
committed
Add --crate-type metadata
With the same semantics as -Zno-trans
1 parent 8f8944e commit b286a2f

File tree

11 files changed

+43
-26
lines changed

11 files changed

+43
-26
lines changed

src/librustc/middle/dependency_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn calculate_type(sess: &session::Session,
114114

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

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

src/librustc/middle/reachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
140140
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
141141
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
142142
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
143-
*ty == config::CrateTypeProcMacro
143+
*ty == config::CrateTypeProcMacro || *ty == config::CrateTypeMetadata
144144
});
145145
ReachableContext {
146146
tcx: tcx,

src/librustc/middle/weak_lang_items.rs

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

src/librustc/session/config.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ pub enum OutputType {
7878
DepInfo,
7979
}
8080

81-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
82-
pub enum ErrorOutputType {
83-
HumanReadable(ColorConfig),
84-
Json,
85-
}
86-
87-
impl Default for ErrorOutputType {
88-
fn default() -> ErrorOutputType {
89-
ErrorOutputType::HumanReadable(ColorConfig::Auto)
90-
}
91-
}
92-
9381
impl OutputType {
9482
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
9583
match *self {
@@ -125,6 +113,18 @@ impl OutputType {
125113
}
126114
}
127115

116+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
117+
pub enum ErrorOutputType {
118+
HumanReadable(ColorConfig),
119+
Json,
120+
}
121+
122+
impl Default for ErrorOutputType {
123+
fn default() -> ErrorOutputType {
124+
ErrorOutputType::HumanReadable(ColorConfig::Auto)
125+
}
126+
}
127+
128128
// Use tree-based collections to cheaply get a deterministic Hash implementation.
129129
// DO NOT switch BTreeMap out for an unsorted container type! That would break
130130
// dependency tracking for commandline arguments.
@@ -483,6 +483,7 @@ pub enum CrateType {
483483
CrateTypeStaticlib,
484484
CrateTypeCdylib,
485485
CrateTypeProcMacro,
486+
CrateTypeMetadata,
486487
}
487488

488489
#[derive(Clone, Hash)]
@@ -1159,7 +1160,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11591160
assumed.", "[KIND=]NAME"),
11601161
opt::multi_s("", "crate-type", "Comma separated list of types of crates
11611162
for the compiler to emit",
1162-
"[bin|lib|rlib|dylib|cdylib|staticlib]"),
1163+
"[bin|lib|rlib|dylib|cdylib|staticlib|metadata]"),
11631164
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
11641165
"NAME"),
11651166
opt::multi_s("", "emit", "Comma separated list of types of output for \
@@ -1548,6 +1549,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
15481549
"cdylib" => CrateTypeCdylib,
15491550
"bin" => CrateTypeExecutable,
15501551
"proc-macro" => CrateTypeProcMacro,
1552+
"metadata" => CrateTypeMetadata,
15511553
_ => {
15521554
return Err(format!("unknown crate type: `{}`",
15531555
part));
@@ -1632,6 +1634,7 @@ impl fmt::Display for CrateType {
16321634
CrateTypeStaticlib => "staticlib".fmt(f),
16331635
CrateTypeCdylib => "cdylib".fmt(f),
16341636
CrateTypeProcMacro => "proc-macro".fmt(f),
1637+
CrateTypeMetadata => "rmeta".fmt(f),
16351638
}
16361639
}
16371640
}

src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
10931093
"serialize work products",
10941094
move || rustc_incremental::save_work_products(sess));
10951095

1096+
println!("finish phase 5: {}", sess.err_count());
10961097
if sess.err_count() > 0 {
10971098
Err(sess.err_count())
10981099
} else {

src/librustc_metadata/creader.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ impl<'a> CrateLoader<'a> {
767767
config::CrateTypeProcMacro |
768768
config::CrateTypeCdylib |
769769
config::CrateTypeStaticlib => need_lib_alloc = true,
770-
config::CrateTypeRlib => {}
770+
config::CrateTypeRlib |
771+
config::CrateTypeMetadata => {}
771772
}
772773
}
773774
if !need_lib_alloc && !need_exe_alloc { return }

src/librustc_trans/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a> ArchiveBuilder<'a> {
231231
}
232232

233233
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
234-
let kind = &self.config.sess.target.target.options.archive_format[..];
234+
let kind = &*self.config.sess.target.target.options.archive_format;
235235
kind.parse().map_err(|_| kind)
236236
}
237237

src/librustc_trans/back/link.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ 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+
// TODO do we need to check for CrateTypeMetadata here?
194195
if sess.opts.debugging_opts.no_trans &&
195196
crate_type == config::CrateTypeExecutable {
196197
continue;
@@ -263,6 +264,9 @@ pub fn filename_for_input(sess: &Session,
263264
config::CrateTypeRlib => {
264265
outputs.out_directory.join(&format!("lib{}.rlib", libname))
265266
}
267+
config::CrateTypeMetadata => {
268+
outputs.out_directory.join(&format!("lib{}.rmeta", libname))
269+
}
266270
config::CrateTypeCdylib |
267271
config::CrateTypeProcMacro |
268272
config::CrateTypeDylib => {
@@ -322,6 +326,7 @@ fn link_binary_output(sess: &Session,
322326
outputs: &OutputFilenames,
323327
crate_name: &str) -> PathBuf {
324328
let objects = object_filenames(trans, outputs);
329+
println!("objects: {:?}", objects);
325330
let default_filename = filename_for_input(sess, crate_type, crate_name,
326331
outputs);
327332
let out_filename = outputs.outputs.get(&OutputType::Exe)
@@ -345,7 +350,7 @@ fn link_binary_output(sess: &Session,
345350
};
346351

347352
match crate_type {
348-
config::CrateTypeRlib => {
353+
config::CrateTypeRlib | config::CrateTypeMetadata => {
349354
link_rlib(sess, Some(trans), &objects, &out_filename,
350355
tmpdir.path()).build();
351356
}
@@ -403,6 +408,7 @@ fn link_rlib<'a>(sess: &'a Session,
403408
tmpdir: &Path) -> ArchiveBuilder<'a> {
404409
info!("preparing rlib from {:?} to {:?}", objects, out_filename);
405410
let mut ab = ArchiveBuilder::new(archive_config(sess, out_filename, None));
411+
406412
for obj in objects {
407413
ab.add_file(obj);
408414
}

src/librustc_trans/back/write.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,12 @@ pub fn run_passes(sess: &Session,
691691
// Whenever an rlib is created, the bitcode is inserted into the
692692
// archive in order to allow LTO against it.
693693
let needs_crate_bitcode =
694-
sess.crate_types.borrow().contains(&config::CrateTypeRlib) &&
695-
sess.opts.output_types.contains_key(&OutputType::Exe);
694+
(sess.crate_types.borrow().contains(&config::CrateTypeRlib) &&
695+
sess.opts.output_types.contains_key(&OutputType::Exe)) ||
696+
sess.crate_types.borrow().contains(&config::CrateTypeMetadata);
696697
let needs_crate_object =
697-
sess.opts.output_types.contains_key(&OutputType::Exe);
698+
sess.opts.output_types.contains_key(&OutputType::Exe) ||
699+
sess.crate_types.borrow().contains(&config::CrateTypeMetadata);
698700
if needs_crate_bitcode {
699701
modules_config.emit_bc = true;
700702
}

src/librustc_trans/base.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use rustc::ty::adjustment::CustomCoerceUnsized;
4545
use rustc::dep_graph::{DepNode, WorkProduct};
4646
use rustc::hir::map as hir_map;
4747
use rustc::util::common::time;
48-
use session::config::{self, NoDebugInfo};
48+
use session::config::{self, NoDebugInfo, OutputType};
4949
use rustc_incremental::IncrementalHashesMap;
5050
use session::Session;
5151
use abi::{self, Abi, FnType};
@@ -1260,7 +1260,8 @@ fn write_metadata(cx: &SharedCrateContext,
12601260
config::CrateTypeStaticlib |
12611261
config::CrateTypeCdylib => MetadataKind::None,
12621262

1263-
config::CrateTypeRlib => MetadataKind::Uncompressed,
1263+
config::CrateTypeRlib |
1264+
config::CrateTypeMetadata => MetadataKind::Uncompressed,
12641265

12651266
config::CrateTypeDylib |
12661267
config::CrateTypeProcMacro => MetadataKind::Compressed,
@@ -1600,7 +1601,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
16001601
assert_module_sources::assert_module_sources(tcx, &modules);
16011602

16021603
// Skip crate items and just output metadata in -Z no-trans mode.
1603-
if tcx.sess.opts.debugging_opts.no_trans {
1604+
if tcx.sess.opts.debugging_opts.no_trans ||
1605+
tcx.sess.crate_types.borrow().iter().all(|ct| ct == &config::CrateTypeMetadata) {
16041606
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
16051607
return CrateTranslation {
16061608
modules: modules,

src/tools/compiletest/src/runtest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ actual:\n\
396396

397397
// FIXME (#9639): This needs to handle non-utf8 paths
398398
let mut args = vec!["-".to_owned(),
399-
"-Zno-trans".to_owned(),
399+
"--emit".to_owned(),
400+
"metadata".to_owned(),
400401
"--out-dir".to_owned(),
401402
out_dir.to_str().unwrap().to_owned(),
402403
format!("--target={}", target),

0 commit comments

Comments
 (0)