Skip to content

bazelembedded/rules_freertos

Repository files navigation

CI

rules_freertos

A set of Bazel build rules for FreeRTOS.

Getting started

Add the following to your workspace. This will fetch and setup the main FreeRTOS repository 'com_github_freertos_freertos_kernel`.

git_repository(
    name = "rules_freertos",
    remote = "https://github.com/silvergasp/rules_freertos.git",
    # Replace commit with latest.
    commit = "<TODO>",
)

load("@rules_freertos//:freertos_deps.bzl", "freertos_deps")

freertos_deps()

In the 'com_github_freertos_freertos_kernel' repository there are three targets of interest.

  • @com_github_freertos_freertos_kernel//:freertos: The main kernel. This target depends on the two configurable targets below.
  • @com_github_freertos_freertos_kernel//:port: An overridable label_flag1 for the 'port' cc_library target. i.e. this should contain your port macro's. This target defaults to selecting the 'Posix' or 'CM4F' ports based on your platforms. PR's for a more complete set of defaults welcome!!
  • @com_github_freertos_freertos_kernel//:config: An overridable label_flag1 that references a cc_library exporting a FreeRTOSConfig.h.

To configure the FreeRTOS kernel, retarget the label_flags using your .bazelrc e.g.

# Optionally override the port. Prefer upstreaming the ports and build files if
# possible.
build --@com_github_freertos_freertos_kernel//:port=//my_project:freertos_port

# Optionally (though strongly recommended) override the config.
build --@com_github_freertos_freertos_kernel//:config=//my_project:freertos_config

If you have multiple projects in your workspace it may be useful to configure backends using select statements. e.g.

# //my_project:BUILD.bazel

# This target acts as a user configurable 'Multiplexer' for the port. 
cc_library(
    name = "freertos_port",
    deps = select({
        "@platforms//os:linux": [":my_linux_port"],
        "@platforms//cpu:armv7-m": [":my_cortex_m3_port"],
    }),
    visibility = ["//visibility:public"],
)

# This target acts as a user configurable 'Multiplexer' for the config. 
cc_library(
    name = "freertos_config",
    deps = select({
        "@platforms//os:linux": [":my_linux_config"],
        "@platforms//cpu:armv7-m": [":my_cortex_m3_config"],
    }),
)

cc_library(
    name = "my_cortex_m3_config",
    hdrs = ["cortex_m3/FreeRTOSConfig.h"],
    includes = ["cortex_m3"],
)

# ...

Footnotes

  1. User defined build settings 2

About

A set of Bazel build rules for FreeRTOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published