]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/lib.rs
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
[rust.git] / src / librustc_codegen_utils / lib.rs
1 // Copyright 2017 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 //! # Note
12 //!
13 //! This API is completely unstable and subject to change.
14
15 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
16       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
17       html_root_url = "https://doc.rust-lang.org/nightly/")]
18
19 #![feature(box_patterns)]
20 #![feature(box_syntax)]
21 #![feature(custom_attribute)]
22 #![feature(nll)]
23 #![allow(unused_attributes)]
24 #![allow(dead_code)]
25 #![feature(quote)]
26 #![feature(rustc_diagnostic_macros)]
27
28 #![recursion_limit="256"]
29
30 extern crate flate2;
31 #[macro_use]
32 extern crate log;
33
34 extern crate serialize;
35 #[macro_use]
36 extern crate rustc;
37 extern crate rustc_allocator;
38 extern crate rustc_target;
39 extern crate rustc_metadata;
40 extern crate rustc_mir;
41 extern crate rustc_incremental;
42 extern crate syntax;
43 extern crate syntax_pos;
44 #[macro_use] extern crate rustc_data_structures;
45
46 use std::path::PathBuf;
47
48 use rustc::session::Session;
49 use rustc::ty::TyCtxt;
50
51 pub mod command;
52 pub mod link;
53 pub mod linker;
54 pub mod codegen_backend;
55 pub mod symbol_export;
56 pub mod symbol_names;
57 pub mod symbol_names_test;
58
59 /// check for the #[rustc_error] annotation, which forces an
60 /// error in codegen. This is used to write compile-fail tests
61 /// that actually test that compilation succeeds without
62 /// reporting an error.
63 pub fn check_for_rustc_errors_attr(tcx: TyCtxt) {
64     if let Some((id, span, _)) = *tcx.sess.entry_fn.borrow() {
65         let main_def_id = tcx.hir.local_def_id(id);
66
67         if tcx.has_attr(main_def_id, "rustc_error") {
68             tcx.sess.span_fatal(span, "compilation successful");
69         }
70     }
71 }
72
73 pub fn find_library(name: &str, search_paths: &[PathBuf], sess: &Session)
74                     -> PathBuf {
75     // On Windows, static libraries sometimes show up as libfoo.a and other
76     // times show up as foo.lib
77     let oslibname = format!("{}{}{}",
78                             sess.target.target.options.staticlib_prefix,
79                             name,
80                             sess.target.target.options.staticlib_suffix);
81     let unixlibname = format!("lib{}.a", name);
82
83     for path in search_paths {
84         debug!("looking for {} inside {:?}", name, path);
85         let test = path.join(&oslibname);
86         if test.exists() { return test }
87         if oslibname != unixlibname {
88             let test = path.join(&unixlibname);
89             if test.exists() { return test }
90         }
91     }
92     sess.fatal(&format!("could not find native static library `{}`, \
93                          perhaps an -L flag is missing?", name));
94 }
95
96 __build_diagnostic_array! { librustc_codegen_utils, DIAGNOSTICS }