Giter Site home page Giter Site logo

brainhivenl / bazel-arm-none-eabi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hexdae/bazel-arm-none-eabi

1.0 0.0 0.0 151 KB

ARM none eabi gcc embedded toolchain for Bazel

Home Page: https://asnaghi.me/post/embedded-bazel/

License: MIT License

Starlark 100.00%

bazel-arm-none-eabi's Introduction

GitHub license GitHub stars GitHub issues Linux macOS Widnows

The goal of the project is to illustrate how to use a custom arm-none-eabi embedded toolchain with Bazel.

If this project was useful to you, give it a ⭐️ and I'll keep improving it!

You can follow the post Bazel for ARM embedded toolchains to get more details about this code.

Features

Use the toolchain from this repo

.bazelrc

And this to your .bazelrc

# .bazelrc

# Build using platforms by default
build --incompatible_enable_cc_toolchain_resolution
build --platforms=@arm_none_eabi//platforms:arm_none_generic

WORKSPACE

Add this git repository to your WORKSPACE to use the compiler

# WORKSPACE.bazel

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "arm_none_eabi",
    commit = "<commit>",
    remote = "https://github.com/hexdae/bazel-arm-none-eabi",
    shallow_since = "<value>",
)

load("@arm_none_eabi//:deps.bzl", "arm_none_eabi_deps", "register_default_arm_none_eabi_toolchains")

arm_none_eabi_deps()

register_default_arm_none_eabi_toolchains()

Bzlmod

Bazel mod support is experimental, add this to your module to use the compiler. Eventually this module will be released to BCR, but for now it requires a `git_override``

# MODULE.bazel

git_override(
    module_name = "arm_none_eabi",
    remote = "https://github.com/hexdae/bazel-arm-none-eabi",
    commit = "<commit>",
)

bazel_dep(name = "arm_none_eabi", version = "1.0.0")

arm_none_eabi_gcc = use_extension("@arm_none_eabi//:extensions.bzl", "arm_none_eabi")
arm_none_eabi_gcc.toolchain(version = "9.2.1")
use_repo(
    arm_none_eabi_gcc,
    "arm_none_eabi_darwin_x86_64",
    "arm_none_eabi_linux_aarch64",
    "arm_none_eabi_linux_x86_64",
    "arm_none_eabi_windows_x86_64",
)

register_toolchains("@arm_none_eabi//toolchain:all")

Now Bazel will automatically use arm-none-eabi-gcc as a compiler.

Custom toolchain

If you want to bake certain compiler flags in to your toolchain, you can define a custom arm-none-eabi toolchain in your repo.

In a BUILD file:

# path/to/toolchains/BUILD

load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain")
arm_none_eabi_toolchain(
    name = "custom_toolchain",
    target_compatible_with = [
        "<your additional constraints>",
    ],
    copts = [
        "<your additional copts>",
    ],
    linkopts = [
        "<your additional linkopts>",
    ],
)

And in your WORKSPACE:

register_toolchains("@//path/to/toolchains:all")

Be careful about registering the default toolchains when using a custom one

Direct access to gcc tools

If you need direct access to gcc tools, they are available as @arm_none_eabi//:<tool>. For example, the following genrules could be used to produce .bin and .hex artifacts from a generic .out target.

cc_binary(
    name = "target.out"
    srcs = [...],
    deps = [...],
    copts = [...],
    ...
)

genrule(
    name = "bin",
    srcs = [":target.out"],
    outs = ["target.bin"],
    cmd = "$(execpath @arm_none_eabi//:objcopy) -O binary $< $@",
    tools = ["@arm_none_eabi//:objcopy"],
)

genrule(
    name = "hex",
    srcs = [":target.out"],
    outs = ["target.hex"],
    cmd = "$(execpath @arm_none_eabi//:objcopy) -O ihex $< $@",
    tools = ["@arm_none_eabi//:objcopy"],
)

Remote execution

This toolchain is compatible with remote execution, see remote.yml

bazel-arm-none-eabi's People

Contributors

hexdae avatar lk avatar kruemelmann avatar

Stargazers

 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.