]> git.lizzy.rs Git - rust.git/blob - src/librustc_back/target/windows_msvc_base.rs
c07321e418e64eb5ebf3a4b07f556533591357f8
[rust.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 LinkerFlavor;
12 use target::{LinkArgs, TargetOptions};
13 use std::default::Default;
14
15 pub fn opts() -> TargetOptions {
16     let mut args = LinkArgs::new();
17     args.insert(LinkerFlavor::Msvc,
18                 vec!["/NOLOGO".to_string(),
19                      "/NXCOMPAT".to_string()]);
20
21     TargetOptions {
22         function_sections: true,
23         linker: "link.exe".to_string(),
24         // When taking a look at the value of this `ar` field, one might expect
25         // `lib.exe` to be the value here! The `lib.exe` program is the default
26         // tool for managing `.lib` archives on Windows, but unfortunately the
27         // compiler cannot use it.
28         //
29         // To recap, we use `ar` here to manage rlibs (which are just archives).
30         // LLVM does not expose bindings for modifying archives so we have to
31         // invoke this utility for write operations (e.g. deleting files, adding
32         // files, etc). Normally archives only have object files within them,
33         // but the compiler also uses archives for storing metadata and
34         // compressed bytecode, so we don't exactly fall within "normal use
35         // cases".
36         //
37         // MSVC's `lib.exe` tool by default will choke when adding a non-object
38         // file to an archive, which we do on a regular basis, making it
39         // inoperable for us. Luckily, however, LLVM has already rewritten `ar`
40         // in the form of `llvm-ar` which is built by default when we build
41         // LLVM. This tool, unlike `lib.exe`, works just fine with non-object
42         // files, so we use it instead.
43         //
44         // Note that there's a few caveats associated with this:
45         //
46         // * This still requires that the *linker* (the consumer of rlibs) will
47         //   ignore non-object files. Thankfully `link.exe` on Windows does
48         //   indeed ignore non-object files in archives.
49         // * This requires `llvm-ar.exe` to be distributed with the compiler
50         //   itself, but we already make sure of this elsewhere.
51         //
52         // Perhaps one day we won't even need this tool at all and we'll just be
53         // able to make library calls into LLVM!
54         ar: "llvm-ar.exe".to_string(),
55         dynamic_linking: true,
56         executables: true,
57         dll_prefix: "".to_string(),
58         dll_suffix: ".dll".to_string(),
59         exe_suffix: ".exe".to_string(),
60         staticlib_prefix: "".to_string(),
61         staticlib_suffix: ".lib".to_string(),
62         target_family: Some("windows".to_string()),
63         is_like_windows: true,
64         is_like_msvc: true,
65         pre_link_args: args,
66
67         .. Default::default()
68     }
69 }