|
|
@ -5,7 +5,7 @@ |
|
|
|
//!
|
|
|
|
//! ```toml
|
|
|
|
//! [build-dependencies]
|
|
|
|
//! gcc = "0.3"
|
|
|
|
//! cc = "0.3"
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! The purpose of this crate is to provide the utility functions necessary to
|
|
|
@ -26,18 +26,18 @@ |
|
|
|
//! Use the `Build` struct to compile `src/foo.c`:
|
|
|
|
//!
|
|
|
|
//! ```no_run
|
|
|
|
//! extern crate gcc;
|
|
|
|
//! extern crate cc;
|
|
|
|
//!
|
|
|
|
//! fn main() {
|
|
|
|
//! gcc::Build::new()
|
|
|
|
//! .file("src/foo.c")
|
|
|
|
//! .define("FOO", Some("bar"))
|
|
|
|
//! .include("src")
|
|
|
|
//! .compile("foo");
|
|
|
|
//! cc::Build::new()
|
|
|
|
//! .file("src/foo.c")
|
|
|
|
//! .define("FOO", Some("bar"))
|
|
|
|
//! .include("src")
|
|
|
|
//! .compile("foo");
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
#![doc(html_root_url = "https://docs.rs/gcc/0.3")] |
|
|
|
#![doc(html_root_url = "https://docs.rs/cc/0.3")] |
|
|
|
#![cfg_attr(test, deny(warnings))] |
|
|
|
#![deny(missing_docs)] |
|
|
|
|
|
|
@ -52,10 +52,6 @@ use std::process::{Command, Stdio, Child}; |
|
|
|
use std::io::{self, BufReader, BufRead, Read, Write}; |
|
|
|
use std::thread::{self, JoinHandle}; |
|
|
|
|
|
|
|
#[doc(hidden)] |
|
|
|
#[deprecated(since="0.3.51", note="gcc::Config has been renamed to gcc::Build")] |
|
|
|
pub type Config = Build; |
|
|
|
|
|
|
|
#[cfg(feature = "parallel")] |
|
|
|
use std::sync::Mutex; |
|
|
|
|
|
|
@ -73,7 +69,11 @@ mod setup_config; |
|
|
|
|
|
|
|
pub mod windows_registry; |
|
|
|
|
|
|
|
/// Extra configuration to pass to gcc.
|
|
|
|
/// A builder for compilation of a native static library.
|
|
|
|
///
|
|
|
|
/// A `Build` is the main type of the `cc` crate and is used to control all the
|
|
|
|
/// various configuration options and such of a compile. You'll find more
|
|
|
|
/// documentation on each method itself.
|
|
|
|
#[derive(Clone, Debug)] |
|
|
|
pub struct Build { |
|
|
|
include_directories: Vec<PathBuf>, |
|
|
@ -102,7 +102,7 @@ pub struct Build { |
|
|
|
warnings: bool, |
|
|
|
} |
|
|
|
|
|
|
|
/// Represents the types of errors that may occur while using gcc-rs.
|
|
|
|
/// Represents the types of errors that may occur while using cc-rs.
|
|
|
|
#[derive(Clone, Debug)] |
|
|
|
enum ErrorKind { |
|
|
|
/// Error occurred while performing I/O.
|
|
|
@ -219,29 +219,6 @@ impl ToolFamily { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// Compile a library from the given set of input C files.
|
|
|
|
///
|
|
|
|
/// This will simply compile all files into object files and then assemble them
|
|
|
|
/// into the output. This will read the standard environment variables to detect
|
|
|
|
/// cross compilations and such.
|
|
|
|
///
|
|
|
|
/// This function will also print all metadata on standard output for Cargo.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::compile_library("foo", &["foo.c", "bar.c"]);
|
|
|
|
/// ```
|
|
|
|
#[deprecated] |
|
|
|
#[doc(hidden)] |
|
|
|
pub fn compile_library(output: &str, files: &[&str]) { |
|
|
|
let mut c = Build::new(); |
|
|
|
for f in files.iter() { |
|
|
|
c.file(*f); |
|
|
|
} |
|
|
|
c.compile(output); |
|
|
|
} |
|
|
|
|
|
|
|
impl Build { |
|
|
|
/// Construct a new instance of a blank set of configuration.
|
|
|
|
///
|
|
|
@ -286,11 +263,11 @@ impl Build { |
|
|
|
///
|
|
|
|
/// let library_path = Path::new("/path/to/library");
|
|
|
|
///
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .include(library_path)
|
|
|
|
/// .include("src")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .include(library_path)
|
|
|
|
/// .include("src")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn include<P: AsRef<Path>>(&mut self, dir: P) -> &mut Build { |
|
|
|
self.include_directories.push(dir.as_ref().to_path_buf()); |
|
|
@ -302,11 +279,11 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .define("FOO", "BAR")
|
|
|
|
/// .define("BAZ", None)
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .define("FOO", "BAR")
|
|
|
|
/// .define("BAZ", None)
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn define<'a, V: Into<Option<&'a str>>>(&mut self, var: &str, val: V) -> &mut Build { |
|
|
|
self.definitions.push((var.to_string(), val.into().map(|s| s.to_string()))); |
|
|
@ -324,10 +301,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .flag("-ffunction-sections")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .flag("-ffunction-sections")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn flag(&mut self, flag: &str) -> &mut Build { |
|
|
|
self.flags.push(flag.to_string()); |
|
|
@ -376,11 +353,11 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .flag_if_supported("-Wlogical-op") // only supported by GCC
|
|
|
|
/// .flag_if_supported("-Wunreachable-code") // only supported by clang
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .flag_if_supported("-Wlogical-op") // only supported by GCC
|
|
|
|
/// .flag_if_supported("-Wunreachable-code") // only supported by clang
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn flag_if_supported(&mut self, flag: &str) -> &mut Build { |
|
|
|
self.flags_supported.push(flag.to_string()); |
|
|
@ -395,10 +372,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .shared_flag(true)
|
|
|
|
/// .compile("libfoo.so");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .shared_flag(true)
|
|
|
|
/// .compile("libfoo.so");
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn shared_flag(&mut self, shared_flag: bool) -> &mut Build { |
|
|
@ -414,11 +391,11 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .shared_flag(true)
|
|
|
|
/// .static_flag(true)
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .shared_flag(true)
|
|
|
|
/// .static_flag(true)
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn static_flag(&mut self, static_flag: bool) -> &mut Build { |
|
|
|
self.static_flag = Some(static_flag); |
|
|
@ -455,7 +432,7 @@ impl Build { |
|
|
|
/// Disabled by default.
|
|
|
|
///
|
|
|
|
/// Warning: turning warnings into errors only make sense
|
|
|
|
/// if you are a developer of the crate using gcc-rs.
|
|
|
|
/// if you are a developer of the crate using cc-rs.
|
|
|
|
/// Some warnings only appear on some architecture or
|
|
|
|
/// specific version of the compiler. Any user of this crate,
|
|
|
|
/// or any other crate depending on it, could fail during
|
|
|
@ -464,10 +441,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .warnings_into_errors(true)
|
|
|
|
/// .compile("libfoo.a");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .warnings_into_errors(true)
|
|
|
|
/// .compile("libfoo.a");
|
|
|
|
/// ```
|
|
|
|
pub fn warnings_into_errors(&mut self, warnings_into_errors: bool) -> &mut Build { |
|
|
|
self.warnings_into_errors = warnings_into_errors; |
|
|
@ -485,10 +462,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .warnings(false)
|
|
|
|
/// .compile("libfoo.a");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .warnings(false)
|
|
|
|
/// .compile("libfoo.a");
|
|
|
|
/// ```
|
|
|
|
pub fn warnings(&mut self, warnings: bool) -> &mut Build { |
|
|
|
self.warnings = warnings; |
|
|
@ -514,11 +491,11 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .shared_flag(true)
|
|
|
|
/// .cpp_link_stdlib("stdc++")
|
|
|
|
/// .compile("libfoo.so");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .shared_flag(true)
|
|
|
|
/// .cpp_link_stdlib("stdc++")
|
|
|
|
/// .compile("libfoo.so");
|
|
|
|
/// ```
|
|
|
|
pub fn cpp_link_stdlib<'a, V: Into<Option<&'a str>>>(&mut self, cpp_link_stdlib: V) -> &mut Build { |
|
|
|
self.cpp_link_stdlib = Some(cpp_link_stdlib.into().map(|s| s.into())); |
|
|
@ -553,10 +530,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .cpp_set_stdlib("c++")
|
|
|
|
/// .compile("libfoo.a");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .cpp_set_stdlib("c++")
|
|
|
|
/// .compile("libfoo.a");
|
|
|
|
/// ```
|
|
|
|
pub fn cpp_set_stdlib<'a, V: Into<Option<&'a str>>>(&mut self, cpp_set_stdlib: V) -> &mut Build { |
|
|
|
let cpp_set_stdlib = cpp_set_stdlib.into(); |
|
|
@ -573,10 +550,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .target("aarch64-linux-android")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .target("aarch64-linux-android")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn target(&mut self, target: &str) -> &mut Build { |
|
|
|
self.target = Some(target.to_string()); |
|
|
@ -591,10 +568,10 @@ impl Build { |
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .host("arm-linux-gnueabihf")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// cc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .host("arm-linux-gnueabihf")
|
|
|
|
/// .compile("foo");
|
|
|
|
/// ```
|
|
|
|
pub fn host(&mut self, host: &str) -> &mut Build { |
|
|
|
self.host = Some(host.to_string()); |
|
|
@ -880,9 +857,7 @@ impl Build { |
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```no_run
|
|
|
|
/// let out = gcc::Build::new()
|
|
|
|
/// .file("src/foo.c")
|
|
|
|
/// .expand();
|
|
|
|
/// let out = cc::Build::new().file("src/foo.c").expand();
|
|
|
|
/// ```
|
|
|
|
pub fn expand(&self) -> Vec<u8> { |
|
|
|
match self.try_expand() { |
|
|
@ -1655,7 +1630,7 @@ fn spawn(cmd: &mut Command, program: &str) -> Result<(Child, JoinHandle<()>), Er |
|
|
|
} |
|
|
|
Err(ref e) if e.kind() == io::ErrorKind::NotFound => { |
|
|
|
let extra = if cfg!(windows) { |
|
|
|
" (see https://github.com/alexcrichton/gcc-rs#compile-time-requirements \
|
|
|
|
" (see https://github.com/alexcrichton/cc-rs#compile-time-requirements \
|
|
|
|
for help)" |
|
|
|
} else { |
|
|
|
"" |
|
|
|