Browse Source

Rename the crate to `cc`

Closes #186
cl-test
Alex Crichton 7 years ago
parent
commit
410992fcf9
  1. 6
      Cargo.toml
  2. 54
      README.md
  3. 165
      src/lib.rs

6
Cargo.toml

@ -1,11 +1,11 @@
[package]
name = "gcc"
name = "cc"
version = "0.3.54"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/alexcrichton/gcc-rs"
documentation = "https://docs.rs/gcc"
repository = "https://github.com/alexcrichton/cc-rs"
documentation = "https://docs.rs/cc"
description = """
A build-time dependency for Cargo build scripts to assist in invoking the native
C compiler to compile native C code into a static archive to be linked into Rust

54
README.md

@ -1,30 +1,24 @@
# gcc-rs
# cc-rs
A library to compile C/C++ code into a Rust library/application.
A library to compile C/C++/assembly into a Rust library/application.
[![Build Status](https://travis-ci.org/alexcrichton/gcc-rs.svg?branch=master)](https://travis-ci.org/alexcrichton/gcc-rs)
[![Build status](https://ci.appveyor.com/api/projects/status/onu270iw98h81nwv?svg=true)](https://ci.appveyor.com/project/alexcrichton/gcc-rs)
[![Build Status](https://travis-ci.org/alexcrichton/cc-rs.svg?branch=master)](https://travis-ci.org/alexcrichton/cc-rs)
[![Build status](https://ci.appveyor.com/api/projects/status/onu270iw98h81nwv?svg=true)](https://ci.appveyor.com/project/alexcrichton/cc-rs)
[Documentation](https://docs.rs/gcc)
[Documentation](https://docs.rs/cc)
A simple library meant to be used as a build dependency with Cargo packages in
order to build a set of C/C++ files into a static archive. Note that while this
crate is called "gcc", it actually calls out to the most relevant compile for
a platform, for example using `cl` on MSVC. That is, this crate does indeed work
on MSVC!
order to build a set of C/C++ files into a static archive. This crate calls out
to the most relevant compiler for a platform, for example using `cl` on MSVC.
## Using gcc-rs
## Using cc-rs
First, you'll want to both add a build script for your crate (`build.rs`) and
also add this crate to your `Cargo.toml` via:
```toml
[package]
# ...
build = "build.rs"
[build-dependencies]
gcc = "0.3"
cc = "0.3"
```
Next up, you'll want to write a build script like so:
@ -32,10 +26,10 @@ Next up, you'll want to write a build script like so:
```rust,no_run
// build.rs
extern crate gcc;
extern crate cc;
fn main() {
gcc::Build::new()
cc::Build::new()
.file("foo.c")
.file("bar.c")
.compile("foo");
@ -70,7 +64,7 @@ fn main() {
To control the programs and flags used for building, the builder can set a
number of different environment variables.
* `CFLAGS` - a series of space separated flags passed to "gcc". Note that
* `CFLAGS` - a series of space separated flags passed to compilers. Note that
individual flags cannot currently contain spaces, so doing
something like: "-L=foo\ bar" is not possible.
* `CC` - the actual C compiler used. Note that this is used as an exact
@ -89,9 +83,9 @@ in the following prioritized order:
3. `<build-kind>_<var>` - for example, `HOST_CC` or `TARGET_CFLAGS`
4. `<var>` - a plain `CC`, `AR` as above.
If none of these variables exist, gcc-rs uses built-in defaults
If none of these variables exist, cc-rs uses built-in defaults
In addition to the the above optional environment variables, `gcc-rs` has some
In addition to the the above optional environment variables, `cc-rs` has some
functions with hard requirements on some variables supplied by [cargo's
build-script driver][cargo] that it has the `TARGET`, `OUT_DIR`, `OPT_LEVEL`,
and `HOST` variables.
@ -100,16 +94,16 @@ and `HOST` variables.
## Optional features
Currently gcc-rs supports parallel compilation (think `make -jN`) but this
feature is turned off by default. To enable gcc-rs to compile C/C++ in parallel,
Currently cc-rs supports parallel compilation (think `make -jN`) but this
feature is turned off by default. To enable cc-rs to compile C/C++ in parallel,
you can change your dependency to:
```toml
[build-dependencies]
gcc = { version = "0.3", features = ["parallel"] }
cc = { version = "0.3", features = ["parallel"] }
```
By default gcc-rs will limit parallelism to `$NUM_JOBS`, or if not present it
By default cc-rs will limit parallelism to `$NUM_JOBS`, or if not present it
will limit it to the number of cpus on the machine. If you are using cargo,
use `-jN` option of `build`, `test` and `run` commands as `$NUM_JOBS`
is supplied by cargo.
@ -121,13 +115,13 @@ is being run. This crate does not ship a C compiler with it. The compiler
required varies per platform, but there are three broad categories:
* Unix platforms require `cc` to be the C compiler. This can be found by
installing gcc/clang on Linux distributions and Xcode on OSX, for example.
installing cc/clang on Linux distributions and Xcode on OSX, for example.
* Windows platforms targeting MSVC (e.g. your target triple ends in `-msvc`)
require `cl.exe` to be available and in `PATH`. This is typically found in
standard Visual Studio installations and the `PATH` can be set up by running
the appropriate developer tools shell.
* Windows platforms targeting MinGW (e.g. your target triple ends in `-gnu`)
require `gcc` to be available in `PATH`. We recommend the
require `cc` to be available in `PATH`. We recommend the
[MinGW-w64](http://mingw-w64.org) distribution, which is using the
[Win-builds](http://win-builds.org) installation system.
You may also acquire it via
@ -140,14 +134,14 @@ required varies per platform, but there are three broad categories:
## C++ support
`gcc-rs` supports C++ libraries compilation by using the `cpp` method on
`cc-rs` supports C++ libraries compilation by using the `cpp` method on
`Build`:
```rust,no_run
extern crate gcc;
extern crate cc;
fn main() {
gcc::Build::new()
cc::Build::new()
.cpp(true) // Switch to C++ library compilation.
.file("foo.cpp")
.compile("libfoo.a");
@ -160,7 +154,7 @@ linked to the crate target.
## License
`gcc-rs` is primarily distributed under the terms of both the MIT license and
`cc-rs` is primarily distributed under the terms of both the MIT license and
the Apache License (Version 2.0), with portions covered by various BSD-like
licenses.

165
src/lib.rs

@ -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 {
""

Loading…
Cancel
Save