#cargo-build #llvm #asm #ll #bc #build-script

llvm_build_utils

Ever wanted to build “native” assembly stuff in your cargo build scripts… something gcc crate cannot quite handle yet? Welcome to llvm_build_utils which provides a convenient API to pack your .ll or .bc files into a ready to use archive full of machine code! It doesn’t even need an installation of LLVM*!

3 releases (breaking)

Uses old Rust 2015

0.3.0 Jul 4, 2016
0.2.0 Jul 1, 2016
0.1.0 Jul 1, 2016

#2112 in Development tools

ISC/Apache-2.0

24KB
375 lines

Ever wanted to build “native” assemblyish stuff in your cargo build scripts… something gcc crate cannot quite handle yet? Welcome to llvm_build_utils which provides a convenient API to pack your LLVM-IR or LLVM bytecode files into a ready to use archive full of machine code! It doesn’t even need LLVM installation and works on stable Rust¹!

No MSVC windows support yet, though

Documentation

¹: May break between versions or be incompatible with some versions of Rust, though. We’ll try to document such breakages in the table below.

Compatibility table

Rustc version This Library
1.8-1.11 0.1-0.2

Using llvm_build_utils

First, you’ll want to both add a build script for your crate (build.rs) and also add this crate to your Cargo.toml via:

[package]
# ...
build = "build.rs"

[build-dependencies]
llvm_build_utils = "0.3"

Then write your build.rs like this:

extern crate llvm_build_utils;
use llvm_build_utils::*;

fn main() {
    build_archive("libyourthing.a", &[
        ("input.ll", BuildOptions {
            ..BuildOptions::default() // customise how the file is built
        })
    ]).expect("error happened").print();
}

Running a cargo build should produce libyourthing.a which then may be linked to your Rust executable/library.

License

llvm_build_utils is distributed under ISC (MIT-like) or Apache (version 2.0) license at your choice.

Dependencies

~2.5MB
~48K SLoC