Browse Source

Merge remote-tracking branch 'upstream/master' into remove_compile_library

cmd
Ottavio Hartman 8 years ago
parent
commit
5c5d692aec
  1. 7
      README.md
  2. 33
      src/lib.rs

7
README.md

@ -37,13 +37,14 @@ extern crate gcc;
fn main() {
gcc::Config::new()
.files(["foo.c", "bar.c"])
.compile("libfoo.a");
.compile("foo");
}
```
And that's it! Running `cargo build` should take care of the rest and your Rust
application will now have the C files `foo.c` and `bar.c` compiled into it. You
can call the functions in Rust by declaring functions in your Rust code like so:
application will now have the C files `foo.c` and `bar.c` compiled into a file
named libfoo.a. You can call the functions in Rust by declaring functions in
your Rust code like so:
```
extern {

33
src/lib.rs

@ -15,6 +15,8 @@
//! This crate will automatically detect situations such as cross compilation or
//! other environment variables set by Cargo and will build code appropriately.
//!
//! [`Config`]: struct.Config.html
//!
//! # Examples
//!
//! Use the `Config` builder to compile `src/foo.c`:
@ -27,7 +29,7 @@
//! .file("src/foo.c")
//! .define("FOO", Some("bar"))
//! .include("src")
//! .compile("libfoo.a");
//! .compile("foo");
//! }
//! ```
@ -157,7 +159,7 @@ impl ToolFamily {
/// # Example
///
/// ```no_run
/// gcc::compile_library("libfoo.a", &["foo.c", "bar.c"]);
/// gcc::compile_library("foo", &["foo.c", "bar.c"]);
/// ```
#[deprecated]
#[doc(hidden)]
@ -172,7 +174,9 @@ pub fn compile_library(output: &str, files: &[&str]) {
impl Config {
/// Construct a new instance of a blank set of configuration.
///
/// This builder is finished with the `compile` function.
/// This builder is finished with the [`compile`] function.
///
/// [`compile`]: struct.Config.html#method.compile
pub fn new() -> Config {
Config {
include_directories: Vec::new(),
@ -212,7 +216,7 @@ impl Config {
/// .file("src/foo.c")
/// .include(library_path)
/// .include("src")
/// .compile("libfoo.a");
/// .compile("foo");
/// ```
pub fn include<P: AsRef<Path>>(&mut self, dir: P) -> &mut Config {
self.include_directories.push(dir.as_ref().to_path_buf());
@ -228,7 +232,7 @@ impl Config {
/// .file("src/foo.c")
/// .define("FOO", Some("BAR"))
/// .define("BAZ", None)
/// .compile("libfoo.a");
/// .compile("foo");
/// ```
pub fn define(&mut self, var: &str, val: Option<&str>) -> &mut Config {
self.definitions.push((var.to_string(), val.map(|s| s.to_string())));
@ -249,7 +253,7 @@ impl Config {
/// gcc::Config::new()
/// .file("src/foo.c")
/// .flag("-ffunction-sections")
/// .compile("libfoo.a");
/// .compile("foo");
/// ```
pub fn flag(&mut self, flag: &str) -> &mut Config {
self.flags.push(flag.to_string());
@ -287,7 +291,7 @@ impl Config {
/// .file("src/foo.c")
/// .shared_flag(true)
/// .static_flag(true)
/// .compile("libfoo.so");
/// .compile("foo");
/// ```
pub fn static_flag(&mut self, static_flag: bool) -> &mut Config {
self.static_flag = Some(static_flag);
@ -372,7 +376,7 @@ impl Config {
/// gcc::Config::new()
/// .file("src/foo.c")
/// .target("aarch64-linux-android")
/// .compile("libfoo.so");
/// .compile("foo");
/// ```
pub fn target(&mut self, target: &str) -> &mut Config {
self.target = Some(target.to_string());
@ -390,7 +394,7 @@ impl Config {
/// gcc::Config::new()
/// .file("src/foo.c")
/// .host("arm-linux-gnueabihf")
/// .compile("libfoo.so");
/// .compile("foo");
/// ```
pub fn host(&mut self, host: &str) -> &mut Config {
self.host = Some(host.to_string());
@ -491,11 +495,14 @@ impl Config {
/// Run the compiler, generating the file `output`
///
/// The name `output` must begin with `lib` and end with `.a`
/// The name `output` should be the name of the library. For backwards compatibility,
/// the `output` may start with `lib` and end with `.a`. The Rust compilier will create
/// the assembly with the lib prefix and .a extension. MSVC will create a file without prefix,
/// ending with `.lib`.
pub fn compile(&self, output: &str) {
assert!(output.starts_with("lib"));
assert!(output.ends_with(".a"));
let lib_name = &output[3..output.len() - 2];
let name_start = if output.starts_with("lib") { 3 } else { 0 };
let name_end = if output.ends_with(".a") { output.len() - 2 } else { output.len() };
let lib_name = &output[name_start..name_end];
let dst = self.get_out_dir();
let mut objects = Vec::new();

Loading…
Cancel
Save