Status Update
Comments
tp...@google.com <tp...@google.com> #2
We should probably use the same approach that we use for facades, i.e.
tp...@google.com <tp...@google.com> #3
Draft implementation:
This involves some changes to the source files. Unfortunately this is unavoidable, because Bazel doesn't support a "viral compiler flags" mechanism like gn's public_configs
, so there's no ergonomic way to provide the -include
flag to both a library and all libraries that depend on it.
tp...@google.com <tp...@google.com> #4
I'm coming back to this after a long break. Let me summarize where we are:
-
My first draft implementation was simple (
https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/137053/4 ), but was not suitable for upstream because it only worked in Bazel. (It relied on build system sandboxing to ensure the compiler would be handed the correct header.) -
My second implementation was much more complex, and required changes to the other build systems (
https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/137053/12 ). Those changes are not finished. -
So, I decided to go back to basics and do something simple: only support setting module configuration in Bazel through compiler defines. In practice, this means that you put the text of your module configuration in the BUILD file rather than a header file. GN and CMake support this, too (in addition to the header-based configuration). I made a new CL for it,
https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/181032 .This is very simple, but also less powerful than providing the configuration through headers. In particular, you can't define the configuration options based on constants coming from other headers.
But maybe (3) is good enough for upstream? Note that if a downstream project that builds with Bazel wants to implement their own configurable modules, they can safely use the pattern of (1).
tp...@google.com <tp...@google.com> #5
Approach (3) can be buttressed with some unit tests that verify the two constants (from another header and from the module configuration) are equal. On the whole maybe that's more ergonomic than some very complex implementation that lets you pull in headers.
tp...@google.com <tp...@google.com> #6
Discussed this with Wyatt offline. We agreed to start with the simple approach (
A couple open questions for followup work:
- How to support module configuration in Soong? Like Bazel, Soong can't virally propagate
-include
flags. But unlike Bazel, Soong can't propagatedefines
, either. There's also no clear analog tolabel_flag
s or GN vars. This will require a separate effort to figure out. - Should we refactor the module configuration mechanism to only support global (not per module) config? The per-module config requires a facade per module, with a different default for each; a global-only config would have just one facade with just one default. Projects could still compose the global config out of multiple
#include
'd headers if they wish.
ap...@google.com <ap...@google.com> #7
Branch: main
commit a40f262a595caff2093df22304d42dbb1a8cfe48
Author: Ted Pudlik <tpudlik@google.com>
Date: Thu Nov 30 20:43:12 2023
bazel: Add simple module configuration mechanism
Add a module configuration mechanism for Bazel that only supports
setting the configuration options through `defines`.
Bug:
Change-Id: I97ddbb661789cf0881e043e3db68b22f21b741b0
Reviewed-on:
Commit-Queue: Ted Pudlik <tpudlik@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
M docs/module_structure.rst
M pw_build/BUILD.bazel
M pw_build/BUILD.gn
A pw_build/module_config_test.cc
M pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
M pw_thread_freertos/BUILD.bazel
tp...@google.com <tp...@google.com> #8
tp...@google.com <tp...@google.com> #9
Created a spreadsheet tracking the instances of the config pattern:
ap...@google.com <ap...@google.com> #10
Branch: main
commit e4224c5161e81d6550a1a4eaa15d17602cd660b1
Author: Ted Pudlik <tpudlik@google.com>
Date: Mon Jan 08 21:33:53 2024
bazel: Add module configuration support
This CL adds label_flags allowing the injection of module configuration
for all Pigweed modules. It's a followup to
which introduced and documented this pattern, but implemented it for
only one module (pw_thread_freertos).
Fixes:
Change-Id: I8f05f7636e96a5009e3a6eb6fe7b2af89dcb9811
Reviewed-on:
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Pigweed-Auto-Submit: Ted Pudlik <tpudlik@google.com>
M pw_assert/BUILD.bazel
M pw_checksum/BUILD.bazel
M pw_chrono_embos/BUILD.bazel
M pw_chrono_freertos/BUILD.bazel
M pw_chrono_threadx/BUILD.bazel
M pw_cpu_exception_cortex_m/BUILD.bazel
M pw_function/BUILD.bazel
M pw_kvs/BUILD.bazel
M pw_log/BUILD.bazel
M pw_log_basic/BUILD.bazel
M pw_log_rpc/BUILD.bazel
M pw_log_string/BUILD.bazel
M pw_log_tokenized/BUILD.bazel
M pw_multisink/BUILD.bazel
M pw_preprocessor/BUILD.bazel
M pw_protobuf/BUILD.bazel
M pw_rpc/BUILD.bazel
M pw_software_update/BUILD.bazel
M pw_status/BUILD.bazel
M pw_string/BUILD.bazel
M pw_sync_freertos/BUILD.bazel
M pw_sys_io_emcraft_sf2/BUILD.bazel
M pw_sys_io_stm32cube/BUILD.bazel
M pw_system/BUILD.bazel
M pw_thread/BUILD.bazel
M pw_thread_embos/BUILD.bazel
M pw_thread_threadx/BUILD.bazel
M pw_tokenizer/BUILD.bazel
M pw_transfer/BUILD.bazel
M pw_unit_test/BUILD.bazel
tp...@google.com <tp...@google.com>
tp...@google.com <tp...@google.com> #11
Discussed this with Ewout offline a week ago. The simple approach of
tp...@google.com <tp...@google.com> #12
From in-person discussions with Wyatt: some module configuration options affect the API exposed by the module, in ways that may make the module incompatible with some uses (e.g., target_compatible_with
only some configuration option choices. This suggests setting the options themselves through something like Skylib flags rather than C++ headers, to allow detecting their values via config_setting
s (similar to
See also
cr...@google.com <cr...@google.com>
tp...@google.com <tp...@google.com> #13
Following up on
Description
Specific example: we should support settinghttps://pigweed.dev/pw_rpc/?highlight=pw_rpc_use_global_mutex#c.PW_RPC_USE_GLOBAL_MUTEX in the bazel build. Probably using https://bazel.build/docs/configurable-attributes#custom-flags .
The PW_RPC_USE_GLOBAL_MUTEX is now enabled by default (as it really always should be), but the general problem of making module configuration accessible from bazel still stands.
Forked fromhttps://bugs.chromium.org/p/pigweed/issues/detail?id=673 (but there's nothing more there).