]> git.proxmox.com Git - rustc.git/blob - src/librustc_back/target/windows_msvc_base.rs
Imported Upstream version 1.2.0+dfsg1
[rustc.git] / src / librustc_back / target / windows_msvc_base.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use target::TargetOptions;
12 use std::default::Default;
13
14 pub fn opts() -> TargetOptions {
15 TargetOptions {
16 function_sections: true,
17 linker: "link.exe".to_string(),
18 // When taking a look at the value of this `ar` field, one might expect
19 // `lib.exe` to be the value here! The `lib.exe` program is the default
20 // tool for managing `.lib` archives on Windows, but unfortunately the
21 // compiler cannot use it.
22 //
23 // To recap, we use `ar` here to manage rlibs (which are just archives).
24 // LLVM does not expose bindings for modifying archives so we have to
25 // invoke this utility for write operations (e.g. deleting files, adding
26 // files, etc). Normally archives only have object files within them,
27 // but the compiler also uses archives for storing metadata and
28 // compressed bytecode, so we don't exactly fall within "normal use
29 // cases".
30 //
31 // MSVC's `lib.exe` tool by default will choke when adding a non-object
32 // file to an archive, which we do on a regular basis, making it
33 // inoperable for us. Luckily, however, LLVM has already rewritten `ar`
34 // in the form of `llvm-ar` which is built by default when we build
35 // LLVM. This tool, unlike `lib.exe`, works just fine with non-object
36 // files, so we use it instead.
37 //
38 // Note that there's a few caveats associated with this:
39 //
40 // * This still requires that the *linker* (the consumer of rlibs) will
41 // ignore non-object files. Thankfully `link.exe` on Windows does
42 // indeed ignore non-object files in archives.
43 // * This requires `llvm-ar.exe` to be distributed with the compiler
44 // itself, but we already make sure of this elsewhere.
45 //
46 // Perhaps one day we won't even need this tool at all and we'll just be
47 // able to make library calls into LLVM!
48 ar: "llvm-ar.exe".to_string(),
49 dynamic_linking: true,
50 executables: true,
51 dll_prefix: "".to_string(),
52 dll_suffix: ".dll".to_string(),
53 exe_suffix: ".exe".to_string(),
54 staticlib_prefix: "".to_string(),
55 staticlib_suffix: ".lib".to_string(),
56 morestack: false,
57 is_like_windows: true,
58 is_like_msvc: true,
59 pre_link_args: vec![
60 "/NOLOGO".to_string(),
61 "/NXCOMPAT".to_string(),
62 ],
63
64 .. Default::default()
65 }
66 }