rust/src/librustc/driver/session.rs

422 lines
14 KiB
Rust
Raw Normal View History

// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use back::link;
use back::target_strs;
use back;
use driver::driver::host_triple;
use metadata::filesearch;
use metadata;
use middle::lint;
use syntax::ast::NodeId;
use syntax::ast::{int_ty, uint_ty};
use syntax::codemap::Span;
use syntax::diagnostic;
use syntax::parse::ParseSess;
use syntax::{ast, codemap};
use syntax::abi;
2013-05-14 19:27:27 -05:00
use syntax::parse::token;
use syntax;
use std::hashmap::{HashMap,HashSet};
pub struct config {
os: abi::Os,
arch: abi::Architecture,
target_strs: target_strs::t,
int_type: int_ty,
uint_type: uint_ty,
}
pub static verbose: uint = 1 << 0;
pub static time_passes: uint = 1 << 1;
pub static count_llvm_insns: uint = 1 << 2;
pub static time_llvm_passes: uint = 1 << 3;
pub static trans_stats: uint = 1 << 4;
pub static asm_comments: uint = 1 << 5;
pub static no_verify: uint = 1 << 6;
pub static coherence: uint = 1 << 7;
pub static borrowck_stats: uint = 1 << 8;
pub static borrowck_note_pure: uint = 1 << 9;
pub static borrowck_note_loan: uint = 1 << 10;
pub static no_landing_pads: uint = 1 << 11;
pub static debug_llvm: uint = 1 << 12;
pub static count_type_sizes: uint = 1 << 13;
pub static meta_stats: uint = 1 << 14;
pub static no_opt: uint = 1 << 15;
pub static gc: uint = 1 << 16;
pub static debug_info: uint = 1 << 17;
pub static extra_debug_info: uint = 1 << 18;
pub static print_link_args: uint = 1 << 19;
pub static no_debug_borrows: uint = 1 << 20;
pub static lint_llvm: uint = 1 << 21;
pub static print_llvm_passes: uint = 1 << 22;
pub static no_vectorize_loops: uint = 1 << 23;
pub static no_vectorize_slp: uint = 1 << 24;
pub static no_prepopulate_passes: uint = 1 << 25;
pub static use_softfp: uint = 1 << 26;
pub static gen_crate_map: uint = 1 << 27;
pub static prefer_dynamic: uint = 1 << 28;
pub static no_integrated_as: uint = 1 << 29;
pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
~[("verbose", "in general, enable more debug printouts", verbose),
("time-passes", "measure time of each rustc pass", time_passes),
("count-llvm-insns", "count where LLVM \
instrs originate", count_llvm_insns),
("time-llvm-passes", "measure time of each LLVM pass",
time_llvm_passes),
("trans-stats", "gather trans statistics", trans_stats),
("asm-comments", "generate comments into the assembly (may change behavior)", asm_comments),
("no-verify", "skip LLVM verification", no_verify),
("coherence", "perform coherence checking", coherence),
("borrowck-stats", "gather borrowck statistics", borrowck_stats),
("borrowck-note-pure", "note where purity is req'd",
borrowck_note_pure),
("borrowck-note-loan", "note where loans are req'd",
borrowck_note_loan),
("no-landing-pads", "omit landing pads for unwinding",
no_landing_pads),
("debug-llvm", "enable debug output from LLVM", debug_llvm),
("count-type-sizes", "count the sizes of aggregate types",
2012-08-27 18:53:54 -05:00
count_type_sizes),
("meta-stats", "gather metadata statistics", meta_stats),
("no-opt", "do not optimize, even if -O is passed", no_opt),
("print-link-args", "Print the arguments passed to the linker", print_link_args),
("gc", "Garbage collect shared data (experimental)", gc),
("extra-debug-info", "Extra debugging info (experimental)",
extra_debug_info),
("debug-info", "Produce debug info (experimental)", debug_info),
("no-debug-borrows",
"do not show where borrow checks fail",
no_debug_borrows),
("lint-llvm",
"Run the LLVM lint pass on the pre-optimization IR",
lint_llvm),
("print-llvm-passes",
"Prints the llvm optimization passes being run",
2013-08-22 22:58:42 -05:00
print_llvm_passes),
("no-prepopulate-passes",
"Don't pre-populate the pass managers with a list of passes, only use \
the passes from --passes",
no_prepopulate_passes),
("no-vectorize-loops",
"Don't run the loop vectorization optimization passes",
2013-08-22 22:58:42 -05:00
no_vectorize_loops),
("no-vectorize-slp",
"Don't run LLVM's SLP vectorization passes",
2013-08-22 22:58:42 -05:00
no_vectorize_slp),
("soft-float", "Generate software floating point library calls", use_softfp),
("gen-crate-map", "Force generation of a toplevel crate map", gen_crate_map),
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
("prefer-dynamic", "Prefer dynamic linking to static linking", prefer_dynamic),
("no-integrated-as",
"Use external assembler rather than LLVM's integrated one", no_integrated_as),
]
}
2013-07-02 14:47:32 -05:00
#[deriving(Clone, Eq)]
pub enum OptLevel {
2012-08-21 19:22:45 -05:00
No, // -O0
Less, // -O1
Default, // -O2
Aggressive // -O3
}
2013-07-02 14:47:32 -05:00
#[deriving(Clone)]
pub struct options {
2011-07-27 07:19:39 -05:00
// The crate config requested for the session, which may be combined
// with additional crate configurations during the compile process
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
outputs: ~[OutputStyle],
gc: bool,
optimize: OptLevel,
custom_passes: ~[~str],
llvm_args: ~[~str],
debuginfo: bool,
extra_debuginfo: bool,
lint_opts: ~[(lint::lint, lint::level)],
save_temps: bool,
output_type: back::link::output_type,
addl_lib_search_paths: @mut HashSet<Path>, // This is mutable for rustpkg, which
// updates search paths based on the
// parsed code
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
ar: Option<~str>,
linker: Option<~str>,
linker_args: ~[~str],
maybe_sysroot: Option<@Path>,
target_triple: ~str,
target_cpu: ~str,
2013-04-22 06:54:12 -05:00
target_feature: ~str,
// User-specified cfg meta items. The compiler itself will add additional
// items to the crate config, and during parsing the entire crate config
// will be added to the crate AST node. This should not be used for
// anything except building the full crate config prior to parsing.
cfg: ast::CrateConfig,
binary: @str,
test: bool,
parse_only: bool,
no_trans: bool,
debugging_opts: uint,
android_cross_path: Option<~str>,
}
pub struct crate_metadata {
name: ~str,
data: ~[u8]
}
// The type of entry function, so
// users can have their own entry
// functions that don't start a
// scheduler
#[deriving(Eq)]
pub enum EntryFnType {
EntryMain,
EntryStart,
EntryNone,
}
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
#[deriving(Eq, Clone)]
pub enum OutputStyle {
OutputExecutable,
OutputDylib,
OutputRlib,
OutputStaticlib,
}
pub struct Session_ {
targ_cfg: @config,
opts: @options,
cstore: @mut metadata::cstore::CStore,
parse_sess: @mut ParseSess,
codemap: @codemap::CodeMap,
// For a library crate, this is always none
entry_fn: @mut Option<(NodeId, codemap::Span)>,
entry_type: @mut Option<EntryFnType>,
span_diagnostic: @mut diagnostic::span_handler,
filesearch: @filesearch::FileSearch,
building_library: @mut bool,
working_dir: Path,
lints: @mut HashMap<ast::NodeId, ~[(lint::lint, codemap::Span, ~str)]>,
node_id: @mut ast::NodeId,
}
pub type Session = @Session_;
impl Session_ {
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
self.span_diagnostic.span_fatal(sp, msg)
}
pub fn fatal(&self, msg: &str) -> ! {
self.span_diagnostic.handler().fatal(msg)
}
pub fn span_err(&self, sp: Span, msg: &str) {
self.span_diagnostic.span_err(sp, msg)
}
pub fn err(&self, msg: &str) {
self.span_diagnostic.handler().err(msg)
}
pub fn err_count(&self) -> uint {
self.span_diagnostic.handler().err_count()
}
pub fn has_errors(&self) -> bool {
self.span_diagnostic.handler().has_errors()
}
pub fn abort_if_errors(&self) {
self.span_diagnostic.handler().abort_if_errors()
}
pub fn span_warn(&self, sp: Span, msg: &str) {
self.span_diagnostic.span_warn(sp, msg)
}
pub fn warn(&self, msg: &str) {
self.span_diagnostic.handler().warn(msg)
}
pub fn span_note(&self, sp: Span, msg: &str) {
self.span_diagnostic.span_note(sp, msg)
}
pub fn note(&self, msg: &str) {
self.span_diagnostic.handler().note(msg)
}
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
self.span_diagnostic.span_bug(sp, msg)
}
pub fn bug(&self, msg: &str) -> ! {
self.span_diagnostic.handler().bug(msg)
}
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
self.span_diagnostic.span_unimpl(sp, msg)
}
pub fn unimpl(&self, msg: &str) -> ! {
self.span_diagnostic.handler().unimpl(msg)
}
pub fn add_lint(&self,
lint: lint::lint,
id: ast::NodeId,
sp: Span,
msg: ~str) {
match self.lints.find_mut(&id) {
Some(arr) => { arr.push((lint, sp, msg)); return; }
None => {}
}
self.lints.insert(id, ~[(lint, sp, msg)]);
}
pub fn next_node_id(&self) -> ast::NodeId {
self.reserve_node_ids(1)
}
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
let v = *self.node_id;
match v.checked_add(&count) {
Some(next) => { *self.node_id = next; }
None => self.bug("Input too large, ran out of node ids!")
}
v
}
pub fn diagnostic(&self) -> @mut diagnostic::span_handler {
self.span_diagnostic
}
pub fn debugging_opt(&self, opt: uint) -> bool {
(self.opts.debugging_opts & opt) != 0u
}
2012-08-21 19:22:45 -05:00
// This exists to help with refactoring to eliminate impossible
// cases later on
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
2013-09-28 00:38:08 -05:00
self.span_bug(sp, format!("Impossible case reached: {}", msg));
2012-08-21 19:22:45 -05:00
}
pub fn verbose(&self) -> bool { self.debugging_opt(verbose) }
pub fn time_passes(&self) -> bool { self.debugging_opt(time_passes) }
pub fn count_llvm_insns(&self) -> bool {
2013-02-22 00:41:37 -06:00
self.debugging_opt(count_llvm_insns)
}
pub fn count_type_sizes(&self) -> bool {
2013-02-22 00:41:37 -06:00
self.debugging_opt(count_type_sizes)
}
pub fn time_llvm_passes(&self) -> bool {
2013-02-22 00:41:37 -06:00
self.debugging_opt(time_llvm_passes)
}
pub fn trans_stats(&self) -> bool { self.debugging_opt(trans_stats) }
pub fn meta_stats(&self) -> bool { self.debugging_opt(meta_stats) }
pub fn asm_comments(&self) -> bool { self.debugging_opt(asm_comments) }
pub fn no_verify(&self) -> bool { self.debugging_opt(no_verify) }
pub fn lint_llvm(&self) -> bool { self.debugging_opt(lint_llvm) }
pub fn coherence(&self) -> bool { self.debugging_opt(coherence) }
pub fn borrowck_stats(&self) -> bool { self.debugging_opt(borrowck_stats) }
pub fn borrowck_note_pure(&self) -> bool {
2013-02-22 00:41:37 -06:00
self.debugging_opt(borrowck_note_pure)
}
pub fn borrowck_note_loan(&self) -> bool {
2013-02-22 00:41:37 -06:00
self.debugging_opt(borrowck_note_loan)
}
pub fn debug_borrows(&self) -> bool {
self.opts.optimize == No && !self.debugging_opt(no_debug_borrows)
}
pub fn print_llvm_passes(&self) -> bool {
2013-08-22 22:58:42 -05:00
self.debugging_opt(print_llvm_passes)
}
pub fn no_prepopulate_passes(&self) -> bool {
self.debugging_opt(no_prepopulate_passes)
}
pub fn no_vectorize_loops(&self) -> bool {
2013-08-22 22:58:42 -05:00
self.debugging_opt(no_vectorize_loops)
}
pub fn no_vectorize_slp(&self) -> bool {
2013-08-22 22:58:42 -05:00
self.debugging_opt(no_vectorize_slp)
}
pub fn gen_crate_map(&self) -> bool {
self.debugging_opt(gen_crate_map)
}
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
pub fn prefer_dynamic(&self) -> bool {
self.debugging_opt(prefer_dynamic)
}
pub fn no_integrated_as(&self) -> bool {
self.debugging_opt(no_integrated_as)
}
2012-07-18 18:18:02 -05:00
// pointless function, now...
pub fn str_of(&self, id: ast::Ident) -> @str {
token::ident_to_str(&id)
2012-07-18 18:18:02 -05:00
}
// pointless function, now...
pub fn ident_of(&self, st: &str) -> ast::Ident {
token::str_to_ident(st)
2012-07-18 18:18:02 -05:00
}
// pointless function, now...
pub fn intr(&self) -> @syntax::parse::token::ident_interner {
2013-05-14 19:27:27 -05:00
token::get_ident_interner()
2012-07-18 18:18:02 -05:00
}
}
/// Some reasonable defaults
pub fn basic_options() -> @options {
@options {
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
outputs: ~[],
2012-06-26 16:27:09 -05:00
gc: false,
2012-08-21 19:22:45 -05:00
optimize: No,
custom_passes: ~[],
llvm_args: ~[],
debuginfo: false,
extra_debuginfo: false,
lint_opts: ~[],
save_temps: false,
output_type: link::output_type_exe,
addl_lib_search_paths: @mut HashSet::new(),
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
ar: None,
linker: None,
linker_args: ~[],
2012-08-20 14:23:37 -05:00
maybe_sysroot: None,
target_triple: host_triple(),
target_cpu: ~"generic",
2013-04-22 06:54:12 -05:00
target_feature: ~"",
cfg: ~[],
binary: @"rustc",
test: false,
parse_only: false,
no_trans: false,
2013-03-04 22:12:23 -06:00
debugging_opts: 0u,
android_cross_path: None,
}
}
// Seems out of place, but it uses session, so I'm putting it here
pub fn expect<T:Clone>(sess: Session, opt: Option<T>, msg: || -> ~str) -> T {
2012-05-22 16:55:39 -05:00
diagnostic::expect(sess.diagnostic(), opt, msg)
}
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
pub fn building_library(options: &options, crate: &ast::Crate) -> bool {
for output in options.outputs.iter() {
match *output {
OutputExecutable => {}
OutputStaticlib | OutputDylib | OutputRlib => return true
}
Add generation of static libraries to rustc This commit implements the support necessary for generating both intermediate and result static rust libraries. This is an implementation of my thoughts in https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html. When compiling a library, we still retain the "lib" option, although now there are "rlib", "staticlib", and "dylib" as options for crate_type (and these are stackable). The idea of "lib" is to generate the "compiler default" instead of having too choose (although all are interchangeable). For now I have left the "complier default" to be a dynamic library for size reasons. Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a dynamic object. I chose this for size reasons, but also because you're probably not going to be embedding the rustc compiler anywhere any time soon. Other than the options outlined above, there are a few defaults/preferences that are now opinionated in the compiler: * If both a .dylib and .rlib are found for a rust library, the compiler will prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option * If generating a "lib", the compiler will generate a dynamic library. This is overridable by explicitly saying what flavor you'd like (rlib, staticlib, dylib). * If no options are passed to the command line, and no crate_type is found in the destination crate, then an executable is generated With this change, you can successfully build a rust program with 0 dynamic dependencies on rust libraries. There is still a dynamic dependency on librustrt, but I plan on removing that in a subsequent commit. This change includes no tests just yet. Our current testing infrastructure/harnesses aren't very amenable to doing flavorful things with linking, so I'm planning on adding a new mode of testing which I believe belongs as a separate commit. Closes #552
2013-11-15 16:03:29 -06:00
}
if options.test { return false }
match syntax::attr::first_attr_value_str_by_name(crate.attrs, "crate_type") {
Some(s) => "lib" == s || "rlib" == s || "dylib" == s || "staticlib" == s,
_ => false
}
}
pub fn sess_os_to_meta_os(os: abi::Os) -> metadata::loader::Os {
use metadata::loader;
2012-08-06 14:34:08 -05:00
match os {
abi::OsWin32 => loader::OsWin32,
abi::OsLinux => loader::OsLinux,
abi::OsAndroid => loader::OsAndroid,
abi::OsMacos => loader::OsMacos,
abi::OsFreebsd => loader::OsFreebsd
}
}