Code Monkey home page Code Monkey logo

bazel_bootlin's Introduction

bazel_bootlin

Provides hermetic Bazel C/C++ toolchains based on Buildroot toolchains provided by Bootlin.

Usage

WORKSPACE

To incorporate bazel_bootlin toolchains into your project, copy the following into your WORKSPACE file.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "bazel_bootlin",
    # See release page for latest version url and sha.
)

load("@bazel_bootlin//toolchains:toolchains.bzl", "bootlin_all_toolchain_deps")

bootlin_all_toolchain_deps()

This will bring all of the available toolchains (and their associated platform definitions) into your project. The toolchains will only be downloaded when actually utilized, but if you prefer, you can only import a specific toolchain:

load("@bazel_bootlin//toolchains:toolchains.bzl", "bootlin_toolchain_deps")

bootlin_toolchain_deps(
    architecture = "x86-64-core-i7",
    cstdlib = "glibc",
    buildroot_version = "2020.08-1",
)

Available Toolchains

Currently bazel_bootlin only provides the "glibc--stable" version of the following Bootlin toolchains:

Architecture cstdlib Buildroot Version
x86-64 glibc 2022.08-1, 2021.11-5
x86-64-core-i7 glibc 2020.08-1
aarch64 glibc, musl 2021.11-1, 2020.08-1
armv7-eabihf glibc 2020.08-1

This list is easily expanded. If a toolchain of interest isn't available feel free to submit and issue, or alternatively take a look at _AVAILABLE_TOOLCHAINS in setup_toolchains.py and create a pull request. Don't forget to actually run setup_toolchains.py after adding a toolchain and before submitting a PR:

bazel run //:setup_toolchains

Platforms

bazel_bootlin defines a different platform for each toolchain that is included. The platforms specify constraint_value for the canonical @platforms//os:os and @platforms//cpu:cpu constraint_setting:

platform(
    name = "{architecture}-linux-{cstdlib}-{buildroot_version}",
    constraint_values = [
        "@platforms//cpu:{architecture}",
        "@platforms//os:linux",
        "@bazel_bootlin//platforms:{buildroot_version}",
    ],
)

Specifying one of these platforms will cause Bazel to use the corresponding toolchain during build.

Building With Toolchain

In order to enable toolchain selection via platforms, Bazel requires a special flag along with the target platform:

bazel build --incompatible_enable_cc_toolchain_resolution --platforms=@bazel_bootlin//platforms:{architecture}-linux-{cstdlib}-{buildroot_version} //...

The ergonomics can be improved by placing the flags in a .bazelrc file:

build --incompatible_enable_cc_toolchain_resolution
build --platforms=@bazel_bootlin//platforms:{architecture}-linux-{cstdlib}-{buildroot_version}

Then a simple bazel build //... will utilize the desired toolchain.

bazel_bootlin's People

Contributors

agoessling avatar matte1 avatar oliverlee 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.