Add hello_dts sample

This sample simply reads a few properties from devicetree and prints
them. It is based on the Pigweed echo sample.

BUG=b/346596832

Change-Id: I8f6a2e18e9fafc52822edd3e948bc318bef6837c
Reviewed-on: https://pigweed-review.googlesource.com/c/zephyr/zephyr-bazel/+/219712
Commit-Queue: Yuval Peress <peress@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Pigweed-Auto-Submit: Yuval Peress <peress@google.com>
Reviewed-by: Sergio Soares <sergiosoares@google.com>
9 files changed
tree: 43646540e8a15d8301c82a1e54b93522f47363df
  1. boards/
  2. dts/
  3. examples/
  4. include/
  5. scripts/
  6. AUTHORS
  7. BUILD.bazel
  8. CONTRIBUTING.md
  9. defs.bzl
  10. LICENSE
  11. MODULE.bazel
  12. MODULE.bazel.lock
  13. OWNERS
  14. README.md
  15. WORKSPACE
README.md

Zephyr-Bazel

This repository contains the logic required to build Zephyr with Bazel. To get started, add the repo to your git submodules or West manifest via https://pigweed.googlesource.com/zephyr/zephyr-bazel/. For the purpose of this doc, we'll assume you have everything checked out under third_party/:

  • third_party/zephyr/ - contains your checkout of Zephyr upstream.
  • third_party/zephyr-bazel/ - contains this repo.

In your root WORKSPACE file, add the following:

# Zephyr
new_local_repository(
    name = "zephyr",
    path = "third_party/zephyr",
    build_file_content = """
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
package(default_visibility = ["//visibility:public"])

exports_files(glob(["**"]))

directory(
    name = "root",
    srcs = glob(["**"], exclude = ["BUILD"])
)
"""
)

# Zephyr-bazel
local_repository(
    name = "zephyr-bazel",
    path = "third_party/zephyr-bazel",
)

Note that the above requires skylib 1.7.1 or greater! If you don't have it, you can use:

http_archive(
    name = "bazel_skylib",
    sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
    ],
)

Next, you‘ll need to make sure all the Python requirements from Zephyr are also loaded. If you haven’t already added pip_parse to your WORKSPACE, that load command is included in the following:

load("@rules_python//python:pip.bzl", "pip_parse")

# Load the Zephyr pip requirements
pip_parse(
    name = "py_deps",
    python_interpreter_target = interpreter,
    requirements_lock = "@@zephyr-bazel//scripts:requirements-base-lock.txt",
)

# Load the generated install command
load("@py_deps//:requirements.bzl", zephyr_install_deps = "install_deps")

# Run the installer
zephyr_install_deps()

Application

In your main application, you can now use the Zephyr utilities for building your app.

load("@zephyr-bazel//:defs.bzl", "dts_cc_library")

dts_cc_library(
    name = "app_native_sim_dts",
    dts_lib = "@zephyr-bazel//boards/native/native_sim:native_sim",
)

cc_binary(
    ...
    deps = [
        ...
        "@zephyr-bazel//:zephyr",
    ] + select({
        "@platform//host": [
            ":app_native_sim_dts",
            "@zephyr-bazel//:posix",
        ],
    }),
    copts = select({
        "@platform//host": [
            "-DCONFIG_ARCH_POSIX=1",
        ],
    }),
)