Giter Club home page Giter Club logo

compiler-rt.rs's Introduction

Status

This project has been deprecated. You might be interested in its spiritual successor: rustc-builtins.

The stuff in this repository is being upstreamed (or already landed) in rust-lang/rust#35021 as part of our effort of making the std crate easily compilable with Cargo. That PR doesn't include support for Cortex-M targets though. If you need compiler-rt intrinsics for those targets, check out the rustc-builtins project where we are porting compiler-rt intrinsics to Rust. I believe that, at the time of writing this notice, rustc-builtins already supports most of the intrinsics needed by Cortex-M targets.

-- @japaric, 2016-08-23


Build Status

compiler-rt.rs

Build compiler-rt using build.rs but without relying on its CMake build system.

WARNING Barely tested, use this at your own risk!

Why?

Rust uses LLVM for code generation and LLVM may sometimes "lower" some Rust code to "intrinsics" which are provided by the limcompiler-rt.a library. For "built-in" targets (the ones in rustc --print target-list) there are official binaries of the libcompiler-rt.a library, but for "custom" targets (the ones that need a .json specification file) one has to manually cross compile the library.

Cross compiling compiler-rt is annoying in the cases where it actually works as it requires cmake and llvm-config to be installed. But for custom targets it usually doesn't work because compiler-rt's CMake build system doesn't work with triples like thumbv7m-none-eabi even though they are valid LLVM targets.

This repository is an experiment about building compiler-rt without using the CMake build system it ships, with the goal of making it easy to cross compile compiler-rt to custom Rust targets. If this experiments succeed, I'll use this crate or the ideas developed here in my Xargo project as it's currently lacking a way to cross compile compiler-rt for custom targets.

Usage

  • This crate must appear somewhere in your crate dependency graph. (*)
  • You do not need to add extern crate compiler_rt anywhere.
  • For custom targets, make sure that the no-compiler-rt field is set to false, which is the default. If the field is missing from your specification file, that's OK.
  • The linker field must be set to $prefix-gcc or the variables CC_${TARGET//-/_} and AR_${TARGET//-/_} must be set to $prefix-gcc and $prefix-ar respectively. If both are set, the env variables take precedence.

(*) It's unclear to me what happens if two different versions of this crate appear in your dependency graph. Cargo will probably raise an error at link time.

Example for the custom target thumbv7m-none-eabi

$ tail -n2 Cargo.toml
[dependencies.compiler-rt]
git = "https://github.com/japaric/compiler-rt.rs"

# `no-compiler-rt` is not set
$ grep no-compiler-rt cortex-m3.json

$ grep linker cortex-m3.json
    "linker": "arm-none-eabi-gcc"
    
$ cargo build --target cortex-m3
(..)
   Compiling compiler-rt v0.1.0
(..)
   
$ find -name '*.a'
./target/cortex-m3/debug/build/compiler-rt-d33efb9ff92c364e/out/libcompiler-rt.a

Caveats

  • Doesn't work with all the built-in targets. No real blocker for this; it just has to be implemented and tested.
  • Requires git to be in your $PATH. This requirement will be lifted in the future.
  • Requires a nightly rustc because this crate is no_core, but it may make sense to make this crate no_std to make it usable with other channels.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

compiler-rt.rs's People

Contributors

homunkulus avatar thejpster avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

compiler-rt.rs's Issues

Requires mman.h?

Trying to build compiler-rt.rs with xargo I get quite far, then it fails with this error. The Fedora packages for arm-none-eabi-gcc and arm-none-eabi-newlib don't include mman.h, which seems reasonable as it looks like a POSIX memory mapping API.

$ AR_lm4f120=arm-none-eabi-gcc CC_lm4f120=arm-none-eabi-gcc xargo build --target=lm4f120 -v
       Fresh itoa v0.1.1
       Fresh serde v0.7.15
       Fresh gcc v0.3.32
       Fresh libc v0.2.15
       Fresh spin v0.4.3
       Fresh rlibc v1.0.0
       Fresh rand v0.3.14
       Fresh lazy_static v0.2.1
       Fresh num-traits v0.1.34
       Fresh tempdir v0.3.5
       Fresh serde_json v0.7.4
   Compiling compiler-rt v0.1.0 (https://github.com/japaric/compiler-rt.rs#cafbcc36)
     Running `/home/jonathan/Documents/programming/rust/bare-metal-arm-rust/target/debug/build/compiler-rt-e5e01a4239060006/build-script-build`
error: failed to run custom build command for `compiler-rt v0.1.0 (https://github.com/japaric/compiler-rt.rs#cafbcc36)`
process didn't exit successfully: `/home/jonathan/Documents/programming/rust/bare-metal-arm-rust/target/debug/build/compiler-rt-e5e01a4239060006/build-script-build` (signal: 6, SIGABRT: process abort signal)
--- stdout
TARGET = Some("lm4f120")
...
running: "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fPIC" "-o" "/home/jonathan/Documents/programming/rust/bare-metal-arm-rust/target/lm4f120/debug/build/compiler-rt-e5e01a4239060006/out/divxc3.o" "-c" "/tmp/compiler-rt.D1OKjKwA08DC/lib/builtins/divxc3.c"
ExitStatus(ExitStatus(0))
TARGET = Some("lm4f120")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("lm4f120")
debug=true opt-level=0
TARGET = Some("lm4f120")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_lm4f120 = None
CFLAGS_lm4f120 = None
TARGET_CFLAGS = None
CFLAGS = None
running: "arm-none-eabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fPIC" "-o" "/home/jonathan/Documents/programming/rust/bare-metal-arm-rust/target/lm4f120/debug/build/compiler-rt-e5e01a4239060006/out/enable_execute_stack.o" "-c" "/tmp/compiler-rt.D1OKjKwA08DC/lib/builtins/enable_execute_stack.c"
ExitStatus(ExitStatus(256))


command did not execute successfully, got: exit code: 1



--- stderr
Cloning into '/tmp/compiler-rt.D1OKjKwA08DC'...
/tmp/compiler-rt.D1OKjKwA08DC/lib/builtins/enable_execute_stack.c:14:22: fatal error: sys/mman.h: No such file or directory
compilation terminated.
thread 'main' panicked at 'explicit panic', /home/jonathan/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.32/src/lib.rs:848
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: `cargo` process didn't exit successfully

(try to) read the target specification file

Let's bite the bullet and just read the target specification file. This lets us:

  • Get the value of llvm-target which lets us lift the restriction that the target name must match llvm-target.
  • We can read the linker field and if it has the form $prefix-gcc we can use that as our CC and $prefix-ar as our AR. This would render both env variables optional, though one can still use them to override the values from the target spec file.

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.