• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H03-May-2022-3,1362,244

tests/H03-May-2022-502425

.cargo-checksum.jsonH A D03-May-202289 11

.gitignoreH A D08-Oct-201830 54

.travis.ymlH A D08-Oct-20181.3 KiB4946

Cargo.tomlH A D01-Jan-19701.3 KiB3733

Cargo.toml.orig-cargoH A D08-Oct-2018774 3225

LICENSE-APACHEH A D01-Nov-201410.6 KiB202169

LICENSE-MITH A D01-Nov-20141 KiB2622

README.mdH A D08-Oct-20185.8 KiB171129

appveyor.ymlH A D08-Oct-20182.4 KiB5651

README.md

1# gcc-rs
2
3> **NOTE**: This crate has been deprecated and is renamed to `cc`. It's
4> recommended to not use this crate and instead use `cc`
5
6A library to compile C/C++ code into a Rust library/application.
7
8[![Build Status](https://travis-ci.org/alexcrichton/gcc-rs.svg?branch=master)](https://travis-ci.org/alexcrichton/gcc-rs)
9[![Build status](https://ci.appveyor.com/api/projects/status/onu270iw98h81nwv?svg=true)](https://ci.appveyor.com/project/alexcrichton/gcc-rs)
10
11[Documentation](https://docs.rs/gcc)
12
13A simple library meant to be used as a build dependency with Cargo packages in
14order to build a set of C/C++ files into a static archive. Note that while this
15crate is called "gcc", it actually calls out to the most relevant compile for
16a platform, for example using `cl` on MSVC. That is, this crate does indeed work
17on MSVC!
18
19## Using gcc-rs
20
21First, you'll want to both add a build script for your crate (`build.rs`) and
22also add this crate to your `Cargo.toml` via:
23
24```toml
25[package]
26# ...
27build = "build.rs"
28
29[build-dependencies]
30gcc = "0.3"
31```
32
33Next up, you'll want to write a build script like so:
34
35```rust,no_run
36// build.rs
37
38extern crate gcc;
39
40fn main() {
41    gcc::Build::new()
42        .file("foo.c")
43        .file("bar.c")
44        .compile("foo");
45}
46```
47
48And that's it! Running `cargo build` should take care of the rest and your Rust
49application will now have the C files `foo.c` and `bar.c` compiled into a file
50named libfoo.a. You can call the functions in Rust by declaring functions in
51your Rust code like so:
52
53```
54extern {
55    fn foo_function();
56    fn bar_function();
57}
58
59pub fn call() {
60    unsafe {
61        foo_function();
62        bar_function();
63    }
64}
65
66fn main() {
67    // ...
68}
69```
70
71## External configuration via environment variables
72
73To control the programs and flags used for building, the builder can set a
74number of different environment variables.
75
76* `CFLAGS` - a series of space separated flags passed to "gcc". Note that
77             individual flags cannot currently contain spaces, so doing
78             something like: "-L=foo\ bar" is not possible.
79* `CC` - the actual C compiler used. Note that this is used as an exact
80         executable name, so (for example) no extra flags can be passed inside
81         this variable, and the builder must ensure that there aren't any
82         trailing spaces. This compiler must understand the `-c` flag. For
83         certain `TARGET`s, it also is assumed to know about other flags (most
84         common is `-fPIC`).
85* `AR` - the `ar` (archiver) executable to use to build the static library.
86
87Each of these variables can also be supplied with certain prefixes and suffixes,
88in the following prioritized order:
89
901. `<var>_<target>` - for example, `CC_x86_64-unknown-linux-gnu`
912. `<var>_<target_with_underscores>` - for example, `CC_x86_64_unknown_linux_gnu`
923. `<build-kind>_<var>` - for example, `HOST_CC` or `TARGET_CFLAGS`
934. `<var>` - a plain `CC`, `AR` as above.
94
95If none of these variables exist, gcc-rs uses built-in defaults
96
97In addition to the the above optional environment variables, `gcc-rs` has some
98functions with hard requirements on some variables supplied by [cargo's
99build-script driver][cargo] that it has the `TARGET`, `OUT_DIR`, `OPT_LEVEL`,
100and `HOST` variables.
101
102[cargo]: http://doc.crates.io/build-script.html#inputs-to-the-build-script
103
104## Optional features
105
106Currently gcc-rs supports parallel compilation (think `make -jN`) but this
107feature is turned off by default. To enable gcc-rs to compile C/C++ in parallel,
108you can change your dependency to:
109
110```toml
111[build-dependencies]
112gcc = { version = "0.3", features = ["parallel"] }
113```
114
115By default gcc-rs will limit parallelism to `$NUM_JOBS`, or if not present it
116will limit it to the number of cpus on the machine. If you are using cargo,
117use `-jN` option of `build`, `test` and `run` commands as `$NUM_JOBS`
118is supplied by cargo.
119
120## Compile-time Requirements
121
122To work properly this crate needs access to a C compiler when the build script
123is being run. This crate does not ship a C compiler with it. The compiler
124required varies per platform, but there are three broad categories:
125
126* Unix platforms require `cc` to be the C compiler. This can be found by
127  installing gcc/clang on Linux distributions and Xcode on OSX, for example.
128* Windows platforms targeting MSVC (e.g. your target triple ends in `-msvc`)
129  require `cl.exe` to be available and in `PATH`. This is typically found in
130  standard Visual Studio installations and the `PATH` can be set up by running
131  the appropriate developer tools shell.
132* Windows platforms targeting MinGW (e.g. your target triple ends in `-gnu`)
133  require `gcc` to be available in `PATH`. We recommend the
134  [MinGW-w64](http://mingw-w64.org) distribution, which is using the
135  [Win-builds](http://win-builds.org) installation system.
136  You may also acquire it via
137  [MSYS2](http://msys2.github.io), as explained [here][msys2-help].  Make sure
138  to install the appropriate architecture corresponding to your installation of
139  rustc. GCC from older [MinGW](http://www.mingw.org) project is compatible
140  only with 32-bit rust compiler.
141
142[msys2-help]: http://github.com/rust-lang/rust#building-on-windows
143
144## C++ support
145
146`gcc-rs` supports C++ libraries compilation by using the `cpp` method on
147`Build`:
148
149```rust,no_run
150extern crate gcc;
151
152fn main() {
153    gcc::Build::new()
154        .cpp(true) // Switch to C++ library compilation.
155        .file("foo.cpp")
156        .compile("libfoo.a");
157}
158```
159
160When using C++ library compilation switch, the `CXX` and `CXXFLAGS` env
161variables are used instead of `CC` and `CFLAGS` and the C++ standard library is
162linked to the crate target.
163
164## License
165
166`gcc-rs` is primarily distributed under the terms of both the MIT license and
167the Apache License (Version 2.0), with portions covered by various BSD-like
168licenses.
169
170See LICENSE-APACHE, and LICENSE-MIT for details.
171