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).
// 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.
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,
config::CrateTypeCdylib |
config::CrateTypeExecutable |
config::CrateTypeStaticlib => true,
- config::CrateTypeRlib |
- config::CrateTypeMetadata => false,
+ config::CrateTypeRlib => false,
}
});
if !needs_check {
Bitcode,
Assembly,
LlvmAssembly,
+ Metadata,
Object,
Exe,
DepInfo,
OutputType::Bitcode |
OutputType::Assembly |
OutputType::LlvmAssembly |
- OutputType::Object => false,
+ OutputType::Object |
+ OutputType::Metadata => false,
}
}
OutputType::Assembly => "asm",
OutputType::LlvmAssembly => "llvm-ir",
OutputType::Object => "obj",
+ OutputType::Metadata => "metadata",
OutputType::Exe => "link",
OutputType::DepInfo => "dep-info",
}
OutputType::Assembly => "s",
OutputType::LlvmAssembly => "ll",
OutputType::Object => "o",
+ OutputType::Metadata => "rmeta",
OutputType::DepInfo => "d",
OutputType::Exe => "",
}
CrateTypeStaticlib,
CrateTypeCdylib,
CrateTypeProcMacro,
- CrateTypeMetadata,
}
#[derive(Clone, Hash)]
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"),
"llvm-ir" => OutputType::LlvmAssembly,
"llvm-bc" => OutputType::Bitcode,
"obj" => OutputType::Object,
+ "metadata" => OutputType::Metadata,
"link" => OutputType::Exe,
"dep-info" => OutputType::DepInfo,
part => {
"cdylib" => CrateTypeCdylib,
"bin" => CrateTypeExecutable,
"proc-macro" => CrateTypeProcMacro,
- "metadata" => CrateTypeMetadata,
_ => {
return Err(format!("unknown crate type: `{}`",
part));
CrateTypeStaticlib => "staticlib".fmt(f),
CrateTypeCdylib => "cdylib".fmt(f),
CrateTypeProcMacro => "proc-macro".fmt(f),
- CrateTypeMetadata => "metadata".fmt(f),
}
}
}
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)
}
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;
}
config::CrateTypeProcMacro |
config::CrateTypeCdylib |
config::CrateTypeStaticlib => need_lib_alloc = true,
- config::CrateTypeRlib |
- config::CrateTypeMetadata => {}
+ config::CrateTypeRlib => {}
}
}
if !need_lib_alloc && !need_exe_alloc { return }
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;
}
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"));
}
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 => {
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());
+ }
}
}
config::CrateTypeDylib |
config::CrateTypeRlib |
- config::CrateTypeMetadata |
config::CrateTypeProcMacro => false,
}
}
config::CrateTypeProcMacro |
config::CrateTypeCdylib => SymbolExportLevel::C,
config::CrateTypeRlib |
- config::CrateTypeMetadata |
config::CrateTypeDylib => SymbolExportLevel::Rust,
}
}
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
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;
user_wants_objects = true;
copy_if_one_unit(OutputType::Object, true);
}
+ OutputType::Metadata |
OutputType::Exe |
OutputType::DepInfo => {}
}
config::CrateTypeStaticlib |
config::CrateTypeCdylib => MetadataKind::None,
- config::CrateTypeRlib |
- config::CrateTypeMetadata => MetadataKind::Uncompressed,
+ config::CrateTypeRlib => MetadataKind::Uncompressed,
config::CrateTypeDylib |
config::CrateTypeProcMacro => MetadataKind::Compressed,
// 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,
// except according to those terms.
// no-prefer-dynamic
+// compile-flags: --emit=metadata
-#![crate_type="metadata"]
+#![crate_type="rlib"]
pub struct Foo {
pub field: i32,
// 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
// 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;
// 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
// crate.
// This is a cfail test since there is no executable to run.
-#![crate_type="metadata"]
-
extern crate rmeta_meta;
use rmeta_meta::Foo;
// 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`
}
// 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;
// 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 {