提交 7720cf02 编写于 作者: N Nick Cameron

Change --crate-type metadata to --emit=metadata

上级 4ecc85be
......@@ -103,6 +103,10 @@ pub fn calculate(sess: &session::Session) {
fn calculate_type(sess: &session::Session,
ty: config::CrateType) -> DependencyList {
if sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
return Vec::new();
}
match ty {
// If the global prefer_dynamic switch is turned off, first attempt
// static linkage (this can fail).
......@@ -114,7 +118,7 @@ fn calculate_type(sess: &session::Session,
// No linkage happens with rlibs, we just needed the metadata (which we
// got long ago), so don't bother with anything.
config::CrateTypeRlib | config::CrateTypeMetadata => return Vec::new(),
config::CrateTypeRlib => return Vec::new(),
// Staticlibs and cdylibs must have all static dependencies. If any fail
// to be found, we generate some nice pretty errors.
......
......@@ -139,7 +139,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
*ty == config::CrateTypeProcMacro || *ty == config::CrateTypeMetadata
*ty == config::CrateTypeProcMacro
});
ReachableContext {
tcx: tcx,
......
......@@ -75,8 +75,7 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
config::CrateTypeCdylib |
config::CrateTypeExecutable |
config::CrateTypeStaticlib => true,
config::CrateTypeRlib |
config::CrateTypeMetadata => false,
config::CrateTypeRlib => false,
}
});
if !needs_check {
......
......@@ -73,6 +73,7 @@ pub enum OutputType {
Bitcode,
Assembly,
LlvmAssembly,
Metadata,
Object,
Exe,
DepInfo,
......@@ -86,7 +87,8 @@ fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
OutputType::Bitcode |
OutputType::Assembly |
OutputType::LlvmAssembly |
OutputType::Object => false,
OutputType::Object |
OutputType::Metadata => false,
}
}
......@@ -96,6 +98,7 @@ fn shorthand(&self) -> &'static str {
OutputType::Assembly => "asm",
OutputType::LlvmAssembly => "llvm-ir",
OutputType::Object => "obj",
OutputType::Metadata => "metadata",
OutputType::Exe => "link",
OutputType::DepInfo => "dep-info",
}
......@@ -107,6 +110,7 @@ pub fn extension(&self) -> &'static str {
OutputType::Assembly => "s",
OutputType::LlvmAssembly => "ll",
OutputType::Object => "o",
OutputType::Metadata => "rmeta",
OutputType::DepInfo => "d",
OutputType::Exe => "",
}
......@@ -482,7 +486,6 @@ pub enum CrateType {
CrateTypeStaticlib,
CrateTypeCdylib,
CrateTypeProcMacro,
CrateTypeMetadata,
}
#[derive(Clone, Hash)]
......@@ -1159,12 +1162,12 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
assumed.", "[KIND=]NAME"),
opt::multi_s("", "crate-type", "Comma separated list of types of crates
for the compiler to emit",
"[bin|lib|rlib|dylib|cdylib|staticlib|metadata]"),
"[bin|lib|rlib|dylib|cdylib|staticlib]"),
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
"NAME"),
opt::multi_s("", "emit", "Comma separated list of types of output for \
the compiler to emit",
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info]"),
opt::multi_s("", "print", "Comma separated list of compiler information to \
print on stdout", &print_opts.join("|")),
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
......@@ -1327,6 +1330,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
"llvm-ir" => OutputType::LlvmAssembly,
"llvm-bc" => OutputType::Bitcode,
"obj" => OutputType::Object,
"metadata" => OutputType::Metadata,
"link" => OutputType::Exe,
"dep-info" => OutputType::DepInfo,
part => {
......@@ -1553,7 +1557,6 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
"cdylib" => CrateTypeCdylib,
"bin" => CrateTypeExecutable,
"proc-macro" => CrateTypeProcMacro,
"metadata" => CrateTypeMetadata,
_ => {
return Err(format!("unknown crate type: `{}`",
part));
......@@ -1638,7 +1641,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
CrateTypeStaticlib => "staticlib".fmt(f),
CrateTypeCdylib => "cdylib".fmt(f),
CrateTypeProcMacro => "proc-macro".fmt(f),
CrateTypeMetadata => "metadata".fmt(f),
}
}
}
......
......@@ -1182,9 +1182,6 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
Some(ref n) if *n == "rlib" => {
Some(config::CrateTypeRlib)
}
Some(ref n) if *n == "metadata" => {
Some(config::CrateTypeMetadata)
}
Some(ref n) if *n == "dylib" => {
Some(config::CrateTypeDylib)
}
......
......@@ -493,7 +493,8 @@ fn build_controller(&mut self,
control.after_hir_lowering.stop = Compilation::Stop;
}
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe ||
i == OutputType::Metadata) {
control.after_llvm.stop = Compilation::Stop;
}
......
......@@ -799,8 +799,7 @@ fn inject_allocator_crate(&mut self) {
config::CrateTypeProcMacro |
config::CrateTypeCdylib |
config::CrateTypeStaticlib => need_lib_alloc = true,
config::CrateTypeRlib |
config::CrateTypeMetadata => {}
config::CrateTypeRlib => {}
}
}
if !need_lib_alloc && !need_exe_alloc { return }
......
......@@ -191,7 +191,8 @@ pub fn link_binary(sess: &Session,
let mut out_filenames = Vec::new();
for &crate_type in sess.crate_types.borrow().iter() {
// Ignore executable crates if we have -Z no-trans, as they will error.
if sess.opts.debugging_opts.no_trans &&
if (sess.opts.debugging_opts.no_trans ||
sess.opts.output_types.contains_key(&OutputType::Metadata)) &&
crate_type == config::CrateTypeExecutable {
continue;
}
......@@ -200,15 +201,16 @@ pub fn link_binary(sess: &Session,
bug!("invalid output type `{:?}` for target os `{}`",
crate_type, sess.opts.target_triple);
}
let out_file = link_binary_output(sess, trans, crate_type, outputs,
crate_name);
let out_file = link_binary_output(sess, trans, crate_type, outputs, crate_name);
out_filenames.push(out_file);
}
// Remove the temporary object file and metadata if we aren't saving temps
if !sess.opts.cg.save_temps {
for obj in object_filenames(trans, outputs) {
remove(sess, &obj);
if !sess.opts.output_types.contains_key(&OutputType::Metadata) {
for obj in object_filenames(trans, outputs) {
remove(sess, &obj);
}
}
remove(sess, &outputs.with_extension("metadata.o"));
}
......@@ -259,13 +261,15 @@ pub fn filename_for_input(sess: &Session,
crate_name: &str,
outputs: &OutputFilenames) -> PathBuf {
let libname = format!("{}{}", crate_name, sess.opts.cg.extra_filename);
if outputs.outputs.contains_key(&OutputType::Metadata) {
return outputs.out_directory.join(&format!("lib{}.rmeta", libname));
}
match crate_type {
config::CrateTypeRlib => {
outputs.out_directory.join(&format!("lib{}.rlib", libname))
}
config::CrateTypeMetadata => {
outputs.out_directory.join(&format!("lib{}.rmeta", libname))
}
config::CrateTypeCdylib |
config::CrateTypeProcMacro |
config::CrateTypeDylib => {
......@@ -351,20 +355,21 @@ fn link_binary_output(sess: &Session,
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
};
match crate_type {
config::CrateTypeRlib => {
link_rlib(sess, Some(trans), &objects, &out_filename,
tmpdir.path()).build();
}
config::CrateTypeStaticlib => {
link_staticlib(sess, &objects, &out_filename, tmpdir.path());
}
config::CrateTypeMetadata => {
emit_metadata(sess, trans, &out_filename);
}
_ => {
link_natively(sess, crate_type, &objects, &out_filename, trans,
outputs, tmpdir.path());
if outputs.outputs.contains_key(&OutputType::Metadata) {
emit_metadata(sess, trans, &out_filename);
} else {
match crate_type {
config::CrateTypeRlib => {
link_rlib(sess, Some(trans), &objects, &out_filename,
tmpdir.path()).build();
}
config::CrateTypeStaticlib => {
link_staticlib(sess, &objects, &out_filename, tmpdir.path());
}
_ => {
link_natively(sess, crate_type, &objects, &out_filename, trans,
outputs, tmpdir.path());
}
}
}
......
......@@ -34,7 +34,6 @@ pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool {
config::CrateTypeDylib |
config::CrateTypeRlib |
config::CrateTypeMetadata |
config::CrateTypeProcMacro => false,
}
}
......
......@@ -149,7 +149,6 @@ pub fn crate_export_threshold(crate_type: config::CrateType)
config::CrateTypeProcMacro |
config::CrateTypeCdylib => SymbolExportLevel::C,
config::CrateTypeRlib |
config::CrateTypeMetadata |
config::CrateTypeDylib => SymbolExportLevel::Rust,
}
}
......
......@@ -701,8 +701,8 @@ pub fn run_passes(sess: &Session,
for output_type in output_types.keys() {
match *output_type {
OutputType::Bitcode => { modules_config.emit_bc = true; },
OutputType::LlvmAssembly => { modules_config.emit_ir = true; },
OutputType::Bitcode => { modules_config.emit_bc = true; }
OutputType::LlvmAssembly => { modules_config.emit_ir = true; }
OutputType::Assembly => {
modules_config.emit_asm = true;
// If we're not using the LLVM assembler, this function
......@@ -711,8 +711,9 @@ pub fn run_passes(sess: &Session,
if !sess.opts.output_types.contains_key(&OutputType::Assembly) {
metadata_config.emit_obj = true;
}
},
OutputType::Object => { modules_config.emit_obj = true; },
}
OutputType::Object => { modules_config.emit_obj = true; }
OutputType::Metadata => { metadata_config.emit_obj = true; }
OutputType::Exe => {
modules_config.emit_obj = true;
metadata_config.emit_obj = true;
......@@ -853,6 +854,7 @@ pub fn run_passes(sess: &Session,
user_wants_objects = true;
copy_if_one_unit(OutputType::Object, true);
}
OutputType::Metadata |
OutputType::Exe |
OutputType::DepInfo => {}
}
......
......@@ -807,8 +807,7 @@ enum MetadataKind {
config::CrateTypeStaticlib |
config::CrateTypeCdylib => MetadataKind::None,
config::CrateTypeRlib |
config::CrateTypeMetadata => MetadataKind::Uncompressed,
config::CrateTypeRlib => MetadataKind::Uncompressed,
config::CrateTypeDylib |
config::CrateTypeProcMacro => MetadataKind::Compressed,
......@@ -1191,7 +1190,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Skip crate items and just output metadata in -Z no-trans mode.
if tcx.sess.opts.debugging_opts.no_trans ||
tcx.sess.crate_types.borrow().iter().all(|ct| ct == &config::CrateTypeMetadata) {
tcx.sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
let linker_info = LinkerInfo::new(&shared_ccx, &ExportedSymbols::empty());
return CrateTranslation {
modules: modules,
......
......@@ -9,8 +9,9 @@
// except according to those terms.
// no-prefer-dynamic
// compile-flags: --emit=metadata
#![crate_type="metadata"]
#![crate_type="rlib"]
pub struct Foo {
pub field: i32,
......
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: --emit=metadata
// aux-build:rmeta_rlib.rs
// no-prefer-dynamic
// must-compile-successfully
......@@ -15,8 +16,6 @@
// Check that building a metadata crate works with a dependent, rlib crate.
// This is a cfail test since there is no executable to run.
#![crate_type="metadata"]
extern crate rmeta_rlib;
use rmeta_rlib::Foo;
......
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: --emit=metadata
// aux-build:rmeta_meta.rs
// no-prefer-dynamic
// must-compile-successfully
......@@ -16,8 +17,6 @@
// crate.
// This is a cfail test since there is no executable to run.
#![crate_type="metadata"]
extern crate rmeta_meta;
use rmeta_meta::Foo;
......
......@@ -9,11 +9,10 @@
// except according to those terms.
// no-prefer-dynamic
// compile-flags: --emit=metadata
// Check that building a metadata crate finds an error.
#![crate_type="metadata"]
fn main() {
let _ = Foo; //~ ERROR unresolved value `Foo`
}
......@@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: --emit=metadata
// aux-build:rmeta_meta.rs
// no-prefer-dynamic
// Check that building a metadata crate finds an error with a dependent,
// metadata-only crate.
#![crate_type="metadata"]
extern crate rmeta_meta;
use rmeta_meta::Foo;
......
......@@ -9,8 +9,9 @@
// except according to those terms.
// no-prefer-dynamic
// compile-flags: --emit=metadata
#![crate_type="metadata"]
#![crate_type="rlib"]
#![crate_name="rmeta_aux"]
pub struct Foo {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册