GithubHelp home page GithubHelp logo

agoessling / bazel_arm_toolchains Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 36 KB

Hermetic ARM toolchains for Bazel

License: MIT License

Starlark 48.18% Shell 38.65% Python 12.85% C 0.19% C++ 0.12%
arm bazel toolchain hermetic

bazel_arm_toolchains's Introduction

bazel_arm_toolchains

Provides hermetic Bazel C/C++ toolchains from ARM.

Usage

WORKSPACE

To incorporate bazel_arm_toolchains 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_arm_toolchains",
    # See release page for latest version url and sha.
)

load("@bazel_arm_toolchains//toolchains:toolchains.bzl", "all_toolchain_deps")

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_arm_toolchains//toolchains:toolchains.bzl", "toolchain_deps")

toolchain_deps(
    host_arch = "x86_64",
    host_os = "linux",
    target = "arm-none-eabi",
    version = "12.3.rel1",
)

host_arch, host_os, target, and version should match the naming convention of the ARM pre-built toolchains.

NOTE: The linux host OS is omitted from the ARM toolchain name.

Available Toolchains and CPUs

Currently bazel_arm_toolchains provides the following toolchains:

Host Architecture Host OS Target Version
x86_64 linux arm-none-eabi 12.3.rel1

and the following CPUs:

CPU
cortex-m0
cortex-m0plus
cortex-m1
cortex-m3
cortex-m4
cortex-m7
cortex-m7+nofp.dp
cortex-a8
cortex-a9

Available options match the -mpu= GCC flags.

These lists are easily expanded. If a toolchain or CPU 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_arm_toolchains defines a different platform for each toolchain, CPU combo:

native.platform(
    name = {cpu}-{target_os}-{version},
    constraint_values = [
        "//platforms/cpu:{cpu}",
        "@platforms//os:{target_os}",
        "//platforms/toolchain_version:{version}",
    ],
    visibility = ["//visibility:public"],
)

To see all available platforms run:

bazel query @bazel_arm_toolchains//platforms:*

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_arm_toolchains//platforms:{cpu}-{target_os}-{version} //...

The host architecture and OS will be derived automatically and the correct toolchain used.

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

build --incompatible_enable_cc_toolchain_resolution
build --platforms=@bazel_arm_toolchains//platforms:{cpu}-{target_os}-{version}

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

Direct Tool Access

Direct access to the various tools (gdb, objdump, readelf, etc.) can be achieved through the various wrapper targets in toolchains/tool_wrappers. For example:

bazel run @bazel_arm_toolchains//toolchains/tool_wrappers/x86_64/linux/arm-none-eabi/12.3.rel1:readelf

Creating alias targets in your project may aid ergonomics:

alias(
    name = "objdump",
    actual = "@bazel_arm_toolchains//toolchains/tool_wrappers/x86_64/linux/arm-none-eabi/12.3.rel1:objdump",
)

These tools can also be utilized indirectly via genrules:

genrule(
    name = "objdump_output",
    srcs = [":binary"],
    outs = ["objdump_output.txt"],
    cmd = "$(location :objdump) -x $< > $@",
    tools = [":objdump"],
)

bazel_arm_toolchains's People

Contributors

agoessling avatar matte1 avatar

Watchers

 avatar  avatar

Forkers

matte1

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.