Coder Social home page Coder Social logo

gcc-rs's Introduction

gcc-rs

Build Status Build status

Documentation

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 certain TARGETs, it also is assumed to know about other flags (most common is -fPIC).
  • AR - the ar (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:

  1. <var>_<target> - for example, CC_x86_64-unknown-linux-gnu
  2. <var>_<target_with_underscores> - for example, CC_x86_64_unknown_linux_gnu
  3. <build-kind>_<var> - for example, HOST_CC or TARGET_CFLAGS
  4. <var> - a plain CC, 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

Windows notes

Currently use of this crate means that Windows users will require gcc to be installed at compile-time. 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.

Once gcc is installed, it also requires that the directory containing gcc is in the PATH environment variable.

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.

gcc-rs's People

Contributors

alexcrichton avatar kokakiwi avatar vhbit avatar tomaka avatar sfackler avatar vadimcn avatar abonander avatar codyps avatar gw3583 avatar johnpmayer avatar o01eg avatar octplane avatar diamondlovesyou avatar serholiu avatar bvssvni avatar timnn avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.