|
|
@ -3,12 +3,32 @@ |
|
|
|
[](https://travis-ci.org/alexcrichton/gcc-rs) |
|
|
|
[](https://ci.appveyor.com/project/alexcrichton/gcc-rs) |
|
|
|
|
|
|
|
[Documentation](http://alexcrichton.com/gcc-rs/gcc/index.html) |
|
|
|
[Documentation](http://alexcrichton.com/gcc-rs) |
|
|
|
|
|
|
|
A simple library meant to be used as a build dependency with Cargo packages in |
|
|
|
order to build a set of C files into a static archive. |
|
|
|
|
|
|
|
## Using gcc-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" |
|
|
|
``` |
|
|
|
|
|
|
|
Next up, you'll want to write a build script like so: |
|
|
|
|
|
|
|
```rust,no_run |
|
|
|
// build.rs |
|
|
|
|
|
|
|
extern crate gcc; |
|
|
|
|
|
|
|
fn main() { |
|
|
@ -16,7 +36,25 @@ fn main() { |
|
|
|
} |
|
|
|
``` |
|
|
|
|
|
|
|
# External configuration via environment variables |
|
|
|
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: |
|
|
|
|
|
|
|
``` |
|
|
|
extern { |
|
|
|
fn foo_function(); |
|
|
|
fn bar_function(); |
|
|
|
} |
|
|
|
|
|
|
|
pub fn call() { |
|
|
|
unsafe { |
|
|
|
foo_function(); |
|
|
|
bar_function(); |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
|
|
|
|
## External configuration via environment variables |
|
|
|
|
|
|
|
To control the programs and flags used for building, the builder can set a |
|
|
|
number of different environment variables. |
|
|
@ -49,7 +87,7 @@ and `HOST` variables. |
|
|
|
|
|
|
|
[cargo]: http://doc.crates.io/build-script.html#inputs-to-the-build-script |
|
|
|
|
|
|
|
# Compile-time Requirements |
|
|
|
## Compile-time Requirements |
|
|
|
|
|
|
|
To work properly this crate needs access to a C compiler when the build script |
|
|
|
is being run. This crate does not ship a C compiler with it. The compiler |
|
|
@ -73,7 +111,7 @@ required varies per platform, but there are three broad categories: |
|
|
|
|
|
|
|
[msys2-help]: http://github.com/rust-lang/rust#building-on-windows |
|
|
|
|
|
|
|
# C++ support |
|
|
|
## C++ support |
|
|
|
|
|
|
|
`gcc-rs` supports C++ libraries compilation by using the `cpp` method on |
|
|
|
`Config`: |
|
|
@ -93,7 +131,7 @@ When using C++ library compilation switch, the `CXX` and `CXXFLAGS` env |
|
|
|
variables are used instead of `CC` and `CFLAGS` and the C++ standard library is |
|
|
|
linked to the crate target. |
|
|
|
|
|
|
|
# License |
|
|
|
## License |
|
|
|
|
|
|
|
`gcc-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 |
|
|
|