Get example 01 console to work
This requires renaming the example directories so that they don't
contain hyphens, because py_proto_library doesn't support generating
code for protos in directories with hyphens in their names. See
https://github.com/bazelbuild/rules_python/blob/da10ac49efee1b02cbfa3b22a39e68bf3fe5bbe2/python/private/proto/py_proto_library.bzl#L60
Also a few small fixes needed to get it all to work:
* Add a dep on arm_none_eabi_gcc_support to the binary to silence some
warnings.
* Upgrade protobuf version to match upstream.
* Add bazel CIPD package to environment.
Test: bazel build //...
Test: bazel run //examples/01-blinky:console
Bug: 307825072
Change-Id: I1c1bdafe4059bae78ed3e5ea5f7d5cadb43e43d5
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/examples/+/195128
Commit-Queue: Ted Pudlik <tpudlik@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
diff --git a/.bazelrc b/.bazelrc
index 9b75307..0b14a95 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -27,5 +27,16 @@
common --per_file_copt=external/.*@-w
common --host_per_file_copt=external/.*@-w
+common --@freertos//:freertos_config=@pigweed//third_party/freertos:freertos_config
+
# Required for new toolchain resolution API.
build --incompatible_enable_cc_toolchain_resolution
+
+# Don't automatically create __init__.py files.
+#
+# This prevents spurious package name collisions at import time, and should be
+# the default (https://github.com/bazelbuild/bazel/issues/7386). It's
+# particularly helpful for Pigweed, because we have many potential package name
+# collisions due to a profusion of stuttering paths like
+# pw_transfer/py/pw_transfer.
+common --incompatible_default_to_explicit_init_py
diff --git a/BUILD.gn b/BUILD.gn
index 10e8257..65f7275 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -128,24 +128,24 @@
# STMicroelectronics STM32F429I-DISC1 examples.
deps += [
- "//examples/01-blinky:blinky(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
- "//examples/02-unit-testing:test_runner_app(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
- "//examples/03-rpc:rpc_main(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
+ "//examples/01_blinky:blinky(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
+ "//examples/02_unit_testing:test_runner_app(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
+ "//examples/03_rpc:rpc_main(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
]
# TODO: https://pwbug.dev/325649415 - Replace broken bare metal rp2040
# examples with pw_system based targets.
#
# deps += [
- # "//examples/01-blinky:blinky(//targets/rp2040:rp2040.size_optimized)",
- # "//examples/02-unit-testing:test_runner_app(//targets/rp2040:rp2040.size_optimized)",
+ # "//examples/01_blinky:blinky(//targets/rp2040:rp2040.size_optimized)",
+ # "//examples/02_unit_testing:test_runner_app(//targets/rp2040:rp2040.size_optimized)",
# ]
# Host examples.
deps += [
- "//examples/01-blinky:blinky(//targets/host:host_device_simulator.speed_optimized)",
- "//examples/02-unit-testing:test_runner_app(//targets/host:host_device_simulator.speed_optimized)",
- "//examples/03-rpc:rpc_main(//targets/host:host_device_simulator.speed_optimized)",
+ "//examples/01_blinky:blinky(//targets/host:host_device_simulator.speed_optimized)",
+ "//examples/02_unit_testing:test_runner_app(//targets/host:host_device_simulator.speed_optimized)",
+ "//examples/03_rpc:rpc_main(//targets/host:host_device_simulator.speed_optimized)",
]
}
@@ -157,7 +157,7 @@
pw_test_group("tests") {
group_deps = [
# Uncomment this to automatically run the example unit test.
- # "//examples/02-unit-testing:tests",
+ # "//examples/02_unit_testing:tests",
]
}
diff --git a/WORKSPACE b/WORKSPACE
index 358c3f6..0b65072 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -55,9 +55,9 @@
http_archive(
name = "com_google_protobuf",
- sha256 = "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
- strip_prefix = "protobuf-3.17.3",
- url = "https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz",
+ sha256 = "616bb3536ac1fff3fb1a141450fa28b875e985712170ea7f1bfe5e5fc41e2cd8",
+ strip_prefix = "protobuf-24.4",
+ url = "https://github.com/protocolbuffers/protobuf/releases/download/v24.4/protobuf-24.4.tar.gz",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
@@ -112,15 +112,25 @@
# Set up the Python interpreter we'll need.
python_register_toolchains(
- name = "python3_10",
- python_version = "3.10",
-)
-
-python_register_toolchains(
name = "python3",
python_version = "3.11",
)
+load("@python3//:defs.bzl", "interpreter")
+load("@rules_python//python:pip.bzl", "pip_parse")
+
+pip_parse(
+ name = "python_packages",
+ python_interpreter_target = interpreter,
+ requirements_darwin = "@pigweed//pw_env_setup/py/pw_env_setup/virtualenv_setup:upstream_requirements_darwin_lock.txt",
+ requirements_linux = "@pigweed//pw_env_setup/py/pw_env_setup/virtualenv_setup:upstream_requirements_linux_lock.txt",
+ requirements_windows = "@pigweed//pw_env_setup/py/pw_env_setup/virtualenv_setup:upstream_requirements_windows_lock.txt",
+)
+
+load("@python_packages//:requirements.bzl", "install_deps")
+
+install_deps()
+
http_archive(
name = "freertos",
build_file = "@pigweed//third_party/freertos:freertos.BUILD.bazel",
diff --git a/docs/BUILD.gn b/docs/BUILD.gn
index 539f38c..0a6226f 100644
--- a/docs/BUILD.gn
+++ b/docs/BUILD.gn
@@ -35,9 +35,9 @@
deps = [
":static_assets",
"//examples:docs",
- "//examples/01-blinky:docs",
- "//examples/02-unit-testing:docs",
- "//examples/03-rpc:docs",
+ "//examples/01_blinky:docs",
+ "//examples/02_unit_testing:docs",
+ "//examples/03_rpc:docs",
]
# Required to set the PYTHONPATH so automodule, autoclass or autofunction RST
diff --git a/examples/01-blinky/BUILD.bazel b/examples/01_blinky/BUILD.bazel
similarity index 84%
rename from examples/01-blinky/BUILD.bazel
rename to examples/01_blinky/BUILD.bazel
index 8c735e2..5fb6cac 100644
--- a/examples/01-blinky/BUILD.bazel
+++ b/examples/01_blinky/BUILD.bazel
@@ -38,6 +38,7 @@
"@platforms//cpu:armv7e-m": [
"//targets/stm32f429i_disc1_stm32cube:linker_script",
"@pigweed//pw_tokenizer:linker_script",
+ "@pigweed//pw_toolchain/arm_gcc:arm_none_eabi_gcc_support",
"@pigweed//targets/stm32f429i_disc1_stm32cube:pre_init",
],
"//conditions:default": [
@@ -65,7 +66,22 @@
args = [
"--device",
"STM32-Discovery",
- "$(rootpath //examples/01-blinky:blinky.elf)",
+ "$(rootpath //examples/01_blinky:blinky.elf)",
+ ],
+ data = [":blinky.elf"],
+)
+
+native_binary(
+ name = "console",
+ src = "//tools:console",
+ out = "console.exe",
+ args = [
+ "-d",
+ "/dev/ttyACM0",
+ "-b",
+ "115200",
+ "--token-databases",
+ "$(rootpath //examples/01_blinky:blinky.elf)",
],
data = [":blinky.elf"],
)
diff --git a/examples/01-blinky/BUILD.gn b/examples/01_blinky/BUILD.gn
similarity index 100%
rename from examples/01-blinky/BUILD.gn
rename to examples/01_blinky/BUILD.gn
diff --git a/examples/01-blinky/docs.rst b/examples/01_blinky/docs.rst
similarity index 92%
rename from examples/01-blinky/docs.rst
rename to examples/01_blinky/docs.rst
index 5a262f3..1ca8ff3 100644
--- a/examples/01-blinky/docs.rst
+++ b/examples/01_blinky/docs.rst
@@ -22,7 +22,7 @@
.. code-block:: sh
- pw flash --device STM32-Discovery out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/01-blinky/bin/blinky.elf
+ pw flash --device STM32-Discovery out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/01_blinky/bin/blinky.elf
.. note::
@@ -47,7 +47,7 @@
.. code-block:: sh
- pw console -d /dev/ttyACM0 -b 115200 --token-databases out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/01-blinky/bin/blinky.elf
+ pw console -d /dev/ttyACM0 -b 115200 --token-databases out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/01_blinky/bin/blinky.elf
.. tip::
@@ -78,7 +78,7 @@
.. code-block::
- pw device-sim ./out/gn/host_device_simulator.speed_optimized/obj/examples/01-blinky/bin/blinky
+ pw device-sim ./out/gn/host_device_simulator.speed_optimized/obj/examples/01_blinky/bin/blinky
#. When you're finished, you can type ``quit`` in the ``Python Repl`` pane to
exit.
@@ -92,7 +92,7 @@
.. code-block:: sh
- bazel run //examples/01-blinky:flash_stm32
+ bazel run //examples/01_blinky:flash_stm32
Bazel knows that the flasher depends on the firmware, and will build the
firmware image before flashing it. It will also track any changes to the
@@ -102,4 +102,4 @@
.. code-block:: sh
- bazel build //examples/01-blinky:blinky.elf
+ bazel build //examples/01_blinky:blinky.elf
diff --git a/examples/01-blinky/main.cc b/examples/01_blinky/main.cc
similarity index 100%
rename from examples/01-blinky/main.cc
rename to examples/01_blinky/main.cc
diff --git a/examples/01-blinky/tokenizer_database.csv b/examples/01_blinky/tokenizer_database.csv
similarity index 100%
rename from examples/01-blinky/tokenizer_database.csv
rename to examples/01_blinky/tokenizer_database.csv
diff --git a/examples/02-unit-testing/BUILD.gn b/examples/02_unit_testing/BUILD.gn
similarity index 100%
rename from examples/02-unit-testing/BUILD.gn
rename to examples/02_unit_testing/BUILD.gn
diff --git a/examples/02-unit-testing/bitops.cc b/examples/02_unit_testing/bitops.cc
similarity index 100%
rename from examples/02-unit-testing/bitops.cc
rename to examples/02_unit_testing/bitops.cc
diff --git a/examples/02-unit-testing/bitops_test.cc b/examples/02_unit_testing/bitops_test.cc
similarity index 100%
rename from examples/02-unit-testing/bitops_test.cc
rename to examples/02_unit_testing/bitops_test.cc
diff --git a/examples/02-unit-testing/docs.rst b/examples/02_unit_testing/docs.rst
similarity index 91%
rename from examples/02-unit-testing/docs.rst
rename to examples/02_unit_testing/docs.rst
index c2a0ce1..5ac8b62 100644
--- a/examples/02-unit-testing/docs.rst
+++ b/examples/02_unit_testing/docs.rst
@@ -21,7 +21,7 @@
.. code-block:: sh
- pw flash --device STM32-Discovery out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/02-unit-testing/bin/test_runner_app.elf
+ pw flash --device STM32-Discovery out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/02_unit_testing/bin/test_runner_app.elf
.. note::
@@ -34,7 +34,7 @@
.. code-block:: sh
- pw console -d /dev/ttyACM0 -b 115200 --token-databases out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/02-unit-testing/bin/test_runner_app.elf
+ pw console -d /dev/ttyACM0 -b 115200 --token-databases out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/02_unit_testing/bin/test_runner_app.elf
.. tip::
@@ -60,7 +60,7 @@
.. code-block::
- pw device-sim ./out/gn/host_device_simulator.speed_optimized/obj/examples/02-unit-testing/bin/test_runner_app
+ pw device-sim ./out/gn/host_device_simulator.speed_optimized/obj/examples/02_unit_testing/bin/test_runner_app
#. In the ``Python Repl`` pane, run the tests.
@@ -82,7 +82,7 @@
# All the tests that should run as part of the build.
pw_test_group("tests") {
group_deps = [
- "//examples/02-unit-testing:tests",
+ "//examples/02_unit_testing:tests",
# ...
]
}
@@ -110,8 +110,8 @@
16:38:01 INF [1/1] Run ==> ninja -C out/gn default
16:38:02 INF
16:38:02 INF ninja: Entering directory `out/gn'
- 16:38:04 ERR FAILED: host_debug_tests/gen/examples/02-unit-testing/bitops_test._run.pw_pystamp
- 16:38:04 INF python ../../third_party/pigweed/pw_build/py/pw_build/python_runner.py --gn-root ../../ --current-path ../../examples/02-unit-testing --default-toolchain=//third_party/pigweed/pw_toolchain/default:default --current-toolchain=//targets/host:host_debug_tests --touch host_debug_tests/gen/examples/02-unit-testing/bitops_test._run.pw_pystamp --capture-output --module pw_unit_test.test_runner --python-virtualenv-config python/gen/sample_project_build_venv/venv_metadata.json --python-dep-list-files host_debug_tests/gen/examples/02-unit-testing/bitops_test._run_metadata_path_list.txt -- --runner ../../third_party/pigweed/targets/host/run_test --test \<TARGET_FILE\(:bitops_test\)\>
+ 16:38:04 ERR FAILED: host_debug_tests/gen/examples/02_unit_testing/bitops_test._run.pw_pystamp
+ 16:38:04 INF python ../../third_party/pigweed/pw_build/py/pw_build/python_runner.py --gn-root ../../ --current-path ../../examples/02_unit_testing --default-toolchain=//third_party/pigweed/pw_toolchain/default:default --current-toolchain=//targets/host:host_debug_tests --touch host_debug_tests/gen/examples/02_unit_testing/bitops_test._run.pw_pystamp --capture-output --module pw_unit_test.test_runner --python-virtualenv-config python/gen/sample_project_build_venv/venv_metadata.json --python-dep-list-files host_debug_tests/gen/examples/02_unit_testing/bitops_test._run_metadata_path_list.txt -- --runner ../../third_party/pigweed/targets/host/run_test --test \<TARGET_FILE\(:bitops_test\)\>
16:38:04 INF ERR ../../third_party/pigweed/targets/host/run_test exited with status 1
16:38:04 INF OUT [Pid: 16631]
16:38:04 INF INF [==========] Running all tests.
@@ -120,7 +120,7 @@
16:38:04 INF INF [ RUN ] Bitops.MoreOnes
16:38:04 INF INF [ OK ] Bitops.MoreOnes
16:38:04 INF INF [ RUN ] Bitops.EvenMoreOnes
- 16:38:04 INF ERR examples/02-unit-testing/bitops_test.cc:26: Failure
+ 16:38:04 INF ERR examples/02_unit_testing/bitops_test.cc:26: Failure
16:38:04 INF ERR Expected: CountOnes(0b11100101) == 5
16:38:04 INF ERR Actual: 2 == 5
16:38:04 INF ERR [ FAILED ] Bitops.EvenMoreOnes
diff --git a/examples/02-unit-testing/main.cc b/examples/02_unit_testing/main.cc
similarity index 100%
rename from examples/02-unit-testing/main.cc
rename to examples/02_unit_testing/main.cc
diff --git a/examples/02-unit-testing/public/bitops.h b/examples/02_unit_testing/public/bitops.h
similarity index 100%
rename from examples/02-unit-testing/public/bitops.h
rename to examples/02_unit_testing/public/bitops.h
diff --git a/examples/03_rpc/BUILD.bazel b/examples/03_rpc/BUILD.bazel
new file mode 100644
index 0000000..356e98c
--- /dev/null
+++ b/examples/03_rpc/BUILD.bazel
@@ -0,0 +1,40 @@
+# Copyright 2024 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+load(
+ "@pigweed//pw_protobuf_compiler:pw_proto_library.bzl",
+ "pw_proto_filegroup",
+)
+load("@rules_python//python:proto.bzl", "py_proto_library")
+
+package(default_visibility = ["//visibility:public"])
+
+pw_proto_filegroup(
+ name = "rpc_example_protos_filegroup",
+ srcs = ["rpc_example_protos/rpc_example_service.proto"],
+ options_files = ["rpc_example_protos/rpc_example_service.options"],
+)
+
+proto_library(
+ name = "rpc_example_protos",
+ srcs = ["rpc_example_protos_filegroup"],
+ strip_import_prefix = "/examples/03_rpc",
+ deps = ["@pigweed//pw_protobuf:common_proto"],
+)
+
+py_proto_library(
+ name = "rpc_example_protos_py_pb2",
+ tags = ["manual"],
+ deps = [":rpc_example_protos"],
+)
diff --git a/examples/03-rpc/BUILD.gn b/examples/03_rpc/BUILD.gn
similarity index 100%
rename from examples/03-rpc/BUILD.gn
rename to examples/03_rpc/BUILD.gn
diff --git a/examples/03-rpc/docs.rst b/examples/03_rpc/docs.rst
similarity index 93%
rename from examples/03-rpc/docs.rst
rename to examples/03_rpc/docs.rst
index d552965..ab9d9aa 100644
--- a/examples/03-rpc/docs.rst
+++ b/examples/03_rpc/docs.rst
@@ -21,7 +21,7 @@
.. code-block:: sh
- pw flash --device STM32-Discovery out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/03-rpc/bin/rpc_main.elf
+ pw flash --device STM32-Discovery out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/03_rpc/bin/rpc_main.elf
.. note::
@@ -32,7 +32,7 @@
.. code-block:: sh
- pw console -d /dev/ttyACM0 -b 115200 --token-databases out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/03-rpc/bin/rpc_main.elf
+ pw console -d /dev/ttyACM0 -b 115200 --token-databases out/gn/stm32f429i_disc1_stm32cube.size_optimized/obj/examples/03_rpc/bin/rpc_main.elf
.. tip::
@@ -46,7 +46,7 @@
.. code-block:: sh
- pw device-sim ./out/gn/host_device_simulator.speed_optimized/obj/examples/03-rpc/bin/rpc_main
+ pw device-sim ./out/gn/host_device_simulator.speed_optimized/obj/examples/03_rpc/bin/rpc_main
#. In the ``Python Repl`` pane, use an RPC to request the device's UUID.
diff --git a/examples/03-rpc/main.cc b/examples/03_rpc/main.cc
similarity index 100%
rename from examples/03-rpc/main.cc
rename to examples/03_rpc/main.cc
diff --git a/examples/03-rpc/public/rpc_example/rpc_example_service_nanopb.h b/examples/03_rpc/public/rpc_example/rpc_example_service_nanopb.h
similarity index 100%
rename from examples/03-rpc/public/rpc_example/rpc_example_service_nanopb.h
rename to examples/03_rpc/public/rpc_example/rpc_example_service_nanopb.h
diff --git a/examples/03-rpc/rpc_example_protos/rpc_example_service.options b/examples/03_rpc/rpc_example_protos/rpc_example_service.options
similarity index 100%
rename from examples/03-rpc/rpc_example_protos/rpc_example_service.options
rename to examples/03_rpc/rpc_example_protos/rpc_example_service.options
diff --git a/examples/03-rpc/rpc_example_protos/rpc_example_service.proto b/examples/03_rpc/rpc_example_protos/rpc_example_service.proto
similarity index 100%
rename from examples/03-rpc/rpc_example_protos/rpc_example_service.proto
rename to examples/03_rpc/rpc_example_protos/rpc_example_service.proto
diff --git a/examples/03-rpc/rpc_example_service_nanopb.cc b/examples/03_rpc/rpc_example_service_nanopb.cc
similarity index 100%
rename from examples/03-rpc/rpc_example_service_nanopb.cc
rename to examples/03_rpc/rpc_example_service_nanopb.cc
diff --git a/pigweed.json b/pigweed.json
index 4491c88..a558cb2 100644
--- a/pigweed.json
+++ b/pigweed.json
@@ -52,6 +52,7 @@
"root_variable": "SAMPLE_PROJECT_ROOT",
"relative_pigweed_root": "third_party/pigweed",
"cipd_package_files": [
+ "third_party/pigweed/pw_env_setup/py/pw_env_setup/cipd_setup/bazel.json",
"third_party/pigweed/pw_env_setup/py/pw_env_setup/cipd_setup/cmake.json",
"third_party/pigweed/pw_env_setup/py/pw_env_setup/cipd_setup/default.json",
"third_party/pigweed/pw_env_setup/py/pw_env_setup/cipd_setup/kythe.json"
diff --git a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel
index da46758..e538e2d 100644
--- a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel
+++ b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel
@@ -24,6 +24,7 @@
"@freertos//:disable_task_statics",
"@pigweed//pw_build/constraints/rtos:freertos",
"@pigweed//pw_interrupt_cortex_m:backend",
+ "@pigweed//pw_malloc_freelist:backend",
"@pigweed//pw_sys_io_stm32cube:backend",
"@pigweed//targets/stm32f429i_disc1_stm32cube:freertos_config_cv",
# For toolchain selection.
diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel
index 3f90505..9e12b57 100644
--- a/tools/BUILD.bazel
+++ b/tools/BUILD.bazel
@@ -20,3 +20,13 @@
name = "flash_device",
srcs = ["sample_project_tools/flash_device.py"],
)
+
+py_binary(
+ name = "console",
+ srcs = ["sample_project_tools/console.py"],
+ deps = [
+ "//examples/03_rpc:rpc_example_protos_py_pb2",
+ "@pigweed//pw_protobuf:common_py_pb2",
+ "@pigweed//pw_system/py:pw_system_lib",
+ ],
+)
diff --git a/tools/BUILD.gn b/tools/BUILD.gn
index 50e54da..c3b0ca4 100644
--- a/tools/BUILD.gn
+++ b/tools/BUILD.gn
@@ -35,7 +35,7 @@
"$dir_pw_presubmit/py",
"$dir_pw_protobuf:common_protos.python",
"$dir_pw_system/py",
- "//examples/03-rpc:rpc_example_protos.python",
+ "//examples/03_rpc:rpc_example_protos.python",
]
pylintrc = "$dir_pigweed/.pylintrc"
}