diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-11-15 14:03:29 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-29 18:36:13 -0800 |
| commit | e338a4154b134fc1d4628496d4ccf85b7af7c443 (patch) | |
| tree | 2df88fca04ee3b42530df237eb1bce9101e5d90e /src/librustpkg | |
| parent | 80991bb578329ca921fdc910d9b6b064e8f521d2 (diff) | |
| download | rust-e338a4154b134fc1d4628496d4ccf85b7af7c443.tar.gz rust-e338a4154b134fc1d4628496d4ccf85b7af7c443.zip | |
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
Diffstat (limited to 'src/librustpkg')
| -rw-r--r-- | src/librustpkg/lib.rs | 5 | ||||
| -rw-r--r-- | src/librustpkg/tests.rs | 4 | ||||
| -rw-r--r-- | src/librustpkg/util.rs | 7 |
3 files changed, 9 insertions, 7 deletions
diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index b87bd0c5824..157d8ba0105 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -17,7 +17,8 @@ url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")]; #[license = "MIT/ASL2"]; -#[crate_type = "lib"]; +#[crate_type = "lib"]; // NOTE: remove after stage0 snapshot +#[crate_type = "dylib"]; #[feature(globs, managed_boxes)]; @@ -114,7 +115,7 @@ impl<'self> PkgScript<'self> { let options = @session::options { binary: binary, maybe_sysroot: Some(@sysroot), - crate_type: session::bin_crate, + outputs: ~[session::OutputExecutable], .. (*session::basic_options()).clone() }; let input = driver::file_input(script.clone()); diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 5e867951b54..3b177b449d9 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -36,6 +36,7 @@ use path_util::{target_executable_in_workspace, target_test_in_workspace, chmod_read_only, platform_library_name}; use rustc::back::link::get_cc_prog; use rustc::metadata::filesearch::rust_path; +use rustc::driver::session; use rustc::driver::driver::{build_session, build_session_options, host_triple, optgroups}; use syntax::diagnostic; use target::*; @@ -1829,10 +1830,11 @@ fn test_linker_build() { @diagnostic::Emitter); let test_sys = test_sysroot(); // FIXME (#9639): This needs to handle non-utf8 paths + let cc = get_cc_prog(sess); command_line_test([test_sys.as_str().unwrap().to_owned(), ~"install", ~"--linker", - get_cc_prog(sess), + cc, ~"foo"], workspace); assert_executable_exists(workspace, "foo"); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index f21357d0271..a8dbf145e53 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -25,7 +25,6 @@ use syntax::visit::Visitor; use syntax::util::small_vector::SmallVector; use rustc::back::link::output_type_exe; use rustc::back::link; -use rustc::driver::session::{lib_crate, bin_crate}; use context::{in_target, StopBefore, Link, Assemble, BuildContext}; use package_id::PkgId; use package_source::PkgSrc; @@ -195,8 +194,8 @@ pub fn compile_input(context: &BuildContext, debug!("compile_input's sysroot = {}", csysroot.display()); let crate_type = match what { - Lib => lib_crate, - Test | Bench | Main => bin_crate + Lib => session::OutputDylib, + Test | Bench | Main => session::OutputExecutable, }; let matches = getopts(debug_flags() + match what { @@ -239,7 +238,7 @@ pub fn compile_input(context: &BuildContext, debug!("Output type = {:?}", output_type); let options = @session::options { - crate_type: crate_type, + outputs: ~[crate_type], optimize: opt, test: what == Test || what == Bench, maybe_sysroot: Some(sysroot_to_use), |
