cc-rs: compiling C and C++ from a Rust build script
Rust library for build scripts to compile C/C++ code into a Rust library
At a glance
- What is it?
- cc-rs is the build-time crate that turns C, C++, assembly and CUDA sources into a static archive for Cargo to link. It is glue, not a compiler, and its job is deciding which native compiler to call on every platform you ship to.
- Who is it for?
- Adopt cc-rs when your crate wraps a C or C++ library and you want the native toolchain discovered for you instead of hard-coded per platform. Do not adopt it if your native side is a full CMake or Meson project with its own install and configure steps; cc-rs compiles translation units, it does not drive a build system.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 4 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 26, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The problem cc-rs exists to solve
A Cargo build script is ordinary Rust code that runs before your crate is compiled. If your crate wraps a C library, that script has to find a compiler, pick flags that match the target triple, handle cross compilation, and emit the right link directives. Doing this by hand means a growing pile of per-platform branches, and it breaks the first time someone builds on MSVC or targets wasm. cc-rs is the crate the Rust ecosystem standardized on for that job. It is a build dependency, listed under [build-dependencies], not something your library links at runtime. The audience is crate authors who ship a native component to a wide range of targets and do not want to maintain their own toolchain detection. The README is explicit that the crate does not compile code itself: it calls out to the default compiler for the platform. That distinction matters when a build fails, because the error usually comes from the compiler cc-rs invoked, not from cc-rs.
How cc-rs picks a compiler and emits link directives
The mechanism is a builder that accumulates sources and flags and then runs the compiler per file, collecting objects into a static archive. Cargo.toml shows the runtime dependencies that make this work: find-msvc-tools for locating the Microsoft toolchain, shlex for splitting command strings, and an optional jobserver dependency that lets compilation share Cargo's job pool. The workspace also carries a libc dependency on Unix, gated behind a feature and deliberately built without default features, with a comment pointing at a long-standing Cargo resolver issue. The crate reads environment variables and the target configuration to decide between gcc, clang, cl, and other drivers, and it detects cross compilation rather than requiring you to declare it. A separate workspace member, find-msvc-tools, is published as its own crate, which is why the recent release list includes find-msvc-tools-v0.1.11 alongside cc-v1.4.4. That split is worth knowing: a problem finding MSVC can come from either crate, and the two version independently.
Installing cc-rs and compiling one C file
The README does not walk through installation. It points to docs.rs for detailed usage instructions, and the repository ships a Cargo.toml you can read for the dependency names and versions. The crate is a build-time dependency, so it belongs in the [build-dependencies] section of the crate that wraps the native code. The workspace manifest records the package name cc, version 1.4.6, edition 2021, and rust-version 1.65.0, and it depends on find-msvc-tools, shlex and an optional jobserver. Because the README gives no build.rs example to copy, the honest starting point is the docs.rs page rather than a snippet reproduced here. Once a build script is in place, cargo build runs it and links the resulting archive, and any compiler error surfaces in the build script output.
Where cc-rs stops being the right tool
cc-rs compiles a set of source files. It is not a build system generator and the README does not claim otherwise. If your native dependency has a configure step, generated headers, or hundreds of translation units with its own dependency graph, driving that through cc-rs means reimplementing the build system in Rust. The common answer is to run the upstream build system from build.rs and let it install into OUT_DIR, which sidesteps cc-rs entirely. A second limitation is visibility: because the crate infers the compiler and flags, a build that succeeds on your machine can fail on a target where the inferred driver differs, and the error message names the compiler rather than the decision that selected it. Third, the repository has no documented rollback or migration guidance in the README; the CHANGELOG.md is where version-to-version changes live, and anyone pinning an exact version should read it before upgrading. The last push was on 2026-08-21, and releases cc-v1.4.4 and cc-v1.4.3 both landed in August 2026.
cc-rs compared with cmake-rs
The closest alternative in the same ecosystem is cmake-rs, which drives an existing CMake project from a build script instead of compiling files directly. The difference in approach is where the build description lives. With cc-rs, the source list and flags live in your build.rs, in Rust, and cc-rs decides how to invoke the compiler. With cmake-rs, the description lives in CMakeLists.txt, CMake configures the project, and the Rust side mostly passes options through. That makes cmake-rs the better fit when you are vendoring an upstream C or C++ project that already ships CMake files, because you inherit its dependency handling and generated headers for free. It also means you now depend on a CMake installation on every build machine, which cc-rs does not require since it only needs a compiler. If the upstream project has no CMake files and is a handful of .c files, cc-rs is the smaller dependency and the shorter build script.
Maintenance, licensing and upgrade cost
The repository is not archived, and the last push was on 2026-08-21, so the project is current as of this writing. Releases are frequent and versioned per crate: cc-v1.4.4 on 2026-08-21, find-msvc-tools-v0.1.11 on 2026-08-14, and cc-v1.4.3 on 2026-08-14. Frequent patch releases are normal for a crate that tracks compiler and platform changes, and they are also the upgrade cost: a build dependency update can change which compiler flags are emitted, so a version bump is worth a full build on each target you support rather than a quick cargo check on the host. The licensing is dual, Apache-2.0 or MIT at your option, which matches the workspace manifest line license = "MIT OR Apache-2.0". The README adds that contributions are dual licensed the same way unless stated otherwise. That is permissive and compatible with most Rust crates, but the choice between the two licences is yours to make and worth recording in your own project; nothing here is legal advice.
Editorial conclusion
Adopt cc-rs when your crate wraps a C or C++ library and you want the native toolchain discovered for you instead of hard-coded per platform. Do not adopt it if your native side is a full CMake or Meson project with its own install and configure steps; cc-rs compiles translation units, it does not drive a build system. Before relying on it, confirm the cc version in Cargo.lock, check that the compiler it selects is the one you intend for each target, and read the docs.rs page for the exact flag names you plan to pass.
Frequently asked questions
What is cc-rs?
It is a library for Cargo build scripts that compiles C, C++, assembly and CUDA files into a static archive for Cargo to link into the crate being built. The README states that it does not compile code itself and instead calls out to the default compiler for the platform.
Can cc-rs compile Rust to C?
No. cc-rs goes the other direction: it takes C and C++ sources and produces a static archive that Rust links against from a build script. The README describes no Rust-to-C output path.
Does cc-rs work for C++ sources?
Yes. The README lists C, C++, assembly and CUDA files as the inputs it compiles into a static archive, and it selects the platform's default compiler driver for the target.
What Rust version does cc-rs require?
The workspace manifest sets edition 2021 and rust-version 1.65.0, so the crate's minimum supported Rust version is 1.65.0.
What licence is cc-rs released under?
It is dual licensed under Apache-2.0 or MIT, at your option. The workspace manifest records license = "MIT OR Apache-2.0", and the README notes that contributions are dual licensed the same way unless stated otherwise.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/rust-lang-cc-rs)