Konstantin Welke
c3479fbc1a
|
9 years ago | |
---|---|---|
gcc-test | 9 years ago | |
src | 9 years ago | |
tests | 9 years ago | |
.gitignore | 10 years ago | |
.travis.yml | 9 years ago | |
Cargo.toml | 9 years ago | |
LICENSE-APACHE | 10 years ago | |
LICENSE-MIT | 10 years ago | |
README.md | 9 years ago | |
appveyor.yml | 10 years ago |
README.md
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.
extern crate gcc;
fn main() {
gcc::compile_library("libfoo.a", &["foo.c", "bar.c"]);
}
External configuration via environment variables
To control the programs and flags used for building, the builder can set a number of different environment variables.
CFLAGS
- a series of space seperated flags passed to "gcc". 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 executable name, so (for example) no extra flags can be passed inside this variable, and the builder must ensure that there aren't any trailing spaces. This compiler must understand the-c
flag. For certainTARGET
s, it also is assumed to know about other flags (most common is-fPIC
).AR
- thear
(archiver) executable to use to build the static library.
Each of these variables can also be supplied with certain prefixes and suffixes, in the following prioritized order:
<var>_<target>
- for example,CC_x86_64-unknown-linux-gnu
<var>_<target_with_underscores>
- for example,CC_x86_64_unknown_linux_gnu
<build-kind>_<var>
- for example,HOST_CC
orTARGET_CFLAGS
<var>
- a plainCC
,AR
as above.
If none of these varaibles exist, gcc-rs uses built-in defaults
In addition to the the above optional environment variables, gcc-rs
has some
functions with hard requirements on some variables supplied by cargo's
build-script driver that it has the TARGET
, OUT_DIR
, OPT_LEVEL
,
and HOST
variables.
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 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. - Windows platforms targeting MSVC (e.g. your target triple ends in
-msvc
) requirecl.exe
to be available and inPATH
. This is typically found in standard Visual Studio installations and thePATH
can be set up by running the appropriate developer tools shell. - Windows platforms targeting MinGW (e.g. your target triple ends in
-gnu
) requiregcc
to be available inPATH
. We recommend the MinGW-w64 distribution (direct link to the installer). You may also acquite it via MSYS2, as explained here. Make sure to install the appropriate architecture corresponding to your installation of rustc. GCC from older MinGW project is compatible only with 32-bit rust compiler.
C++ support
gcc-rs
supports C++ libraries compilation by using the cpp
method on
Config
:
extern crate gcc;
fn main() {
gcc::Config::new()
.cpp(true) // Switch to C++ library compilation.
.file("foo.cpp")
.compile("libfoo.a");
}
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
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
licenses.
See LICENSE-APACHE, and LICENSE-MIT for details.