| commit | 55a0ffe5a7708c002e4db9b79facf7678ea0ab71 | [log] [tgz] |
|---|---|---|
| author | Yuval Peress <peress@google.com> | Wed Jul 03 17:03:19 2024 +0000 |
| committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Wed Jul 03 17:03:19 2024 +0000 |
| tree | 43646540e8a15d8301c82a1e54b93522f47363df | |
| parent | e1e0fb4ef07a66f9c585b37a69f1cc30dc25f1b2 [diff] |
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>
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()
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",
],
}),
)