Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hexdae/toolchains_arm_gnu

ARM embedded toolchains for Bazel
https://github.com/hexdae/toolchains_arm_gnu

arm bazel embedded gcc toolchain

Last synced: 3 months ago
JSON representation

ARM embedded toolchains for Bazel

Awesome Lists containing this project

README

        


GitHub license


GitHub stars


GitHub issues


CI

The goal of the project is to make arm cross compilation toolchains readily
available (and customizable) for bazel developers.

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

You might also like another, similar, toolchain project for `bazel`
[RISCV toolchains](https://github.com/hexdae/bazel-riscv-none-elf)

## Features

- [MODULE support](#bzlmod)
- [WORKSPACE support](#workspace)
- [Direct access to gcc tools](#direct-access-to-gcc-tools)
- [Custom toolchain support](#custom-toolchain)
- [Use a specific GCC version](./examples/gcc_version)
- [Link Map Generation](./examples/linkmap)
- [Examples](./examples)
- Remote execution support
- Linux, MacOS, Windows

## Use the toolchain from this repo

## .bazelrc

And this to your `.bazelrc`

```bash
# .bazelrc

# Build using platforms by default
build --incompatible_enable_cc_toolchain_resolution
```

## Bzlmod

```python
bazel_dep(name = "toolchains_arm_gnu", version = "")

arm_toolchain = use_extension("@toolchains_arm_gnu//:extensions.bzl", "arm_toolchain")

arm_toolchain.arm_none_eabi()
use_repo(arm_toolchain, "arm_none_eabi")
register_toolchains("@arm_none_eabi//toolchain:all")

arm_toolchain.arm_none_linux_gnueabihf()
use_repo(arm_toolchain, "arm_none_linux_gnueabihf")
register_toolchains("@arm_none_linux_gnueabihf//toolchain:all")

arm_toolchain.aarch64_none_elf()
use_repo(arm_toolchain, "aarch64_none_elf")
register_toolchains("@aarch64_none_elf//toolchain:all")

arm_toolchain.aarch64_none_linux_gnu()
use_repo(arm_toolchain, "aarch64_none_linux_gnu")
register_toolchains("@aarch64_none_linux_gnu//toolchain:all")
```

## WORKSPACE

Add this git repository to your WORKSPACE to use the compiler (NOTE: WORSKPACE
setups will become obsolete soon, do not use for new projects)

WORKSPACE

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

git_repository(
name = "rules_cc",
remote = "https://github.com/bazelbuild/rules_cc",
branch = "main",
)

git_repository(
name = "arm_none_eabi",
remote = "https://github.com/hexdae/toolchains_arm_gnu",
branch = "master",
)

load("@toolchains_arm_gnu//:deps.bzl", "arm_none_eabi_deps")
arm_none_eabi_deps()
register_toolchains("@arm_none_eabi//toolchain:all")

load("@toolchains_arm_gnu//:deps.bzl", "arm_none_linux_gnueabihf_deps")
arm_none_linux_gnueabihf_deps()
register_toolchains("@arm_none_linux_gnueabihf//toolchain:all")

load("@toolchains_arm_gnu//:deps.bzl", "aarch64_none_elf_deps")
aarch64_none_elf_deps()
register_toolchains("@aarch64_none_elf//toolchain:all")

load("@toolchains_arm_gnu//:deps.bzl", "aarch64_none_linux_gnu_deps")
aarch64_none_linux_gnu_deps()
register_toolchains("@aarch64_none_linux_gnu//toolchain:all")
```

## Custom toolchain

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

In a BUILD file:

```python
# 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 = [
"",
],
copts = [
"",
],
linkopts = [
"",
],
)
```

And in your WORKSPACE / MODULE file:

```python
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//:`. For example, the following `genrules` could be used to produce `.bin` and `.hex` artifacts from a generic `.out` target.

```python

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"],
)
```

### Build linkermap file

If you want to build a linkermap file, starting from bazel 7.2.0 it can be enabled through the `generate_linkmap` and accessed though the `linkmap` output group.

```python

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

filegroup(
name = "target.out.map",
srcs = [":target.out"],
output_group = "linkmap",
)
```

## Remote execution

This toolchain is compatible with remote execution

## Building with the ARM Linux toolchain on Windows

The Windows maximum path length limitation may cause build failures with the
`arm-none-linux-gnueabihf` toolchain. In some cases, it's enough to avoid this
by setting a shorter output directory. Add this to your `.bazelrc` file:

```
startup --output_user_root=C:/tmp
```

See [avoid long path issues][1] for more information.

[1]: https://bazel.build/configure/windows#long-path-issues