Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 20 days ago
JSON representation
ARM embedded toolchains for Bazel
- Host: GitHub
- URL: https://github.com/hexdae/toolchains_arm_gnu
- Owner: hexdae
- License: mit
- Created: 2020-05-23T18:43:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-30T17:35:39.000Z (5 months ago)
- Last Synced: 2024-10-02T08:04:55.666Z (2 months ago)
- Topics: arm, bazel, embedded, gcc, toolchain
- Language: Starlark
- Homepage: https://asnaghi.me/post/embedded-bazel/
- Size: 365 KB
- Stars: 101
- Watchers: 6
- Forks: 35
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-bazel - hexdae/bazel-arm-none-eabi - embedded ARM toolchain (Tooling / Toolchains)
README
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/BUILDload("@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