Coder Social home page Coder Social logo

bazel_llvm's Introduction

bazel_llvm: LLVM libraries and binaries for bazel

CI

Overview

Pre-built LLVM releases to use as dependencies in bazel projects:

  • @llvm//<version> provides a cc_library that can be used as dep for C++ apps in bazel that link against LLVM.
  • @llvm//<vesion>:<bin> provides pre-built LLVM binaries, e.g. @llvm//10.0.0:clang provides clang 10 binary. This can be used as a data dep of scripts.

Supported compiler / OS versions:

  • Ubuntu Linux 18.04 with clang / gcc >= 7.
  • macOS >= 10.15.

Getting Started

Add the following to your WORKSPACE file:

http_archive(
    name = "llvm",
    strip_prefix = "bazel_llvm-<stable-commit>",
    urls = ["https://github.com/ChrisCummins/bazel_llvm/archive/<stable-commit>.tar.gz"],
)

load("@llvm//tools/bzl:deps.bzl", "llvm_deps")
llvm_deps()

In your BUILD files, reference @llvm//<version>:<target>:

# Link against LLVM 10.0.0 as a regular C++ dependency:
cc_library(
    name = "my_lib",
    srcs = ["my_lib.cc"],
    copts = ["-std=c++14", "-fno-rtti"],  # required
    deps = ["@llvm//10.0.0"],
)

# Use pre-compiled opt as a data dependency:
sh_binary(
    name = "my_script",
    srcs = ["my_script.sh"],
    data = ["@llvm//10.0.0:opt"],
)

See the examples directory for further usage.

Known issues

  • This uses LLVM releases archives, which are Release builds without assertions enabled. To use a debug build, or one with assertions enabled, you would need to provide your own build archive and update the archives in tools/bzl/deps.bzl.

Work-in-progress: building from source

I have tried a couple of times to get LLVM to build from source as a cmake_external() target using rules_foreign_cc. I have yet to get it to work. There seems to be conflicts between the bazel build environment and the build environment that LLVM usually expects.

You can see my latest attempt here. I have a working Debug build on macOS, but now I get double-defined static variable errors when I link against it from a cc_library(). I don't have the patience to figure out enough about LLVM/Bazel build internals to crack it. If you want to give it a go, build:

$ bazel build @llvm//10.0.0:debug --sandbox_debug

Patches welcome! ❤️

bazel_llvm's People

Contributors

chriscummins avatar naderalawar avatar panhaolin2001 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.