Add Argus library for ride height sensor#98
Conversation
Summary of ChangesHello @dhairs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the Broadcom AFBR-S50 API library into the project's build system. This integration allows other firmware projects to easily incorporate ride height sensor functionalities by declaring a simple Bazel dependency. The changes involve configuring Bazel to retrieve the external library and defining a dedicated build target for its components, streamlining its adoption across the codebase. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds the Broadcom AFBR-S50 library as a dependency using Bazel's git_repository rule. The overall approach is sound, but there are a few areas for improvement. My review includes feedback on making the dependency declaration more consistent with the existing Bzlmod patterns in your project for better maintainability. I've also identified a critical issue in the new cc_library definition where it incorrectly includes precompiled libraries for all architectures, which would cause linker errors. I have provided a detailed suggestion on how to fix this using select() to correctly choose the library based on the target platform. Additionally, I've made a suggestion regarding Bazel's conventional file naming to improve project structure clarity.
| cc_library( | ||
| name = "afbr_s50_lib", | ||
|
|
||
| srcs = glob( | ||
| ["AFBR-S50/Lib/**/*.a"], | ||
| allow_empty = True | ||
| ), | ||
|
|
||
| hdrs = glob( | ||
| ["AFBR-S50/Include/**/*.h"], | ||
| allow_empty = True | ||
| ), | ||
|
|
||
| includes = ["AFBR-S50/Include"], | ||
| visibility = ["//visibility:public"], | ||
| ) No newline at end of file |
There was a problem hiding this comment.
This cc_library definition has a critical issue and a few areas for improvement:
-
[Critical] Incorrect
srcs: Theglobforsrcsis too broad and will match all pre-compiled static libraries for every architecture (e.g., Cortex-M0, Cortex-M4F). This will cause linker errors due to duplicate symbol definitions. You should useselect()to pick the correct library based on the target architecture. -
Unnecessary
allow_empty: Thehdrsglob probably shouldn't haveallow_empty = True. If the headers are missing, the library is unusable, and the build should fail. -
Missing newline: The file is missing a newline at the end.
Here is a suggested replacement that addresses these points:
cc_library(
name = "afbr_s50_lib",
hdrs = glob(["AFBR-S50/Include/**/*.h"]),
srcs = select({
# TODO: Verify these platform constraints match your project's configuration.
"@toolchains_arm_gnu//constraints:cortex_m4_fpu": glob(["AFBR-S50/Lib/GCC/ARM-Cortex-M4F/*.a"]),
"@toolchains_arm_gnu//constraints:cortex_m0": glob(["AFBR-S50/Lib/GCC/ARM-Cortex-M0/*.a"]),
"//conditions:default": [],
}),
includes = ["AFBR-S50/Include"],
visibility = ["//visibility:public"],
)
| # AFBR-S50 API Library | ||
| git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
|
||
| git_repository( | ||
| name = "afbr_s50_lib", | ||
| remote = "https://github.com/Broadcom/AFBR-S50-API.git", | ||
| commit = "68b16693bedae0704b49edcfa2a79e82e5520ae3", | ||
| shallow_since = "2024-01-01", | ||
| build_file = "//drivers:afbr-s50/afbr-s50.BUILD", | ||
| ) |
There was a problem hiding this comment.
For consistency with how other external dependencies like openocd and dfu are managed, consider moving this git_repository definition into a module extension (.bzl file) and using use_extension and use_repo here. This improves maintainability by centralizing dependency logic and keeping MODULE.bazel cleaner.
| remote = "https://github.com/Broadcom/AFBR-S50-API.git", | ||
| commit = "68b16693bedae0704b49edcfa2a79e82e5520ae3", | ||
| shallow_since = "2024-01-01", | ||
| build_file = "//drivers:afbr-s50/afbr-s50.BUILD", |
There was a problem hiding this comment.
The filename afbr-s50.BUILD and its location are unconventional. Standard Bazel practice is to name build files BUILD or BUILD.bazel and place them in the directory that represents the package. I'd suggest renaming drivers/afbr-s50/afbr-s50.BUILD to drivers/afbr-s50/BUILD.bazel and updating this build_file attribute to //drivers/afbr-s50:BUILD.bazel. This will make the project structure more intuitive and align with Bazel conventions.
alicedimauro
left a comment
There was a problem hiding this comment.
add this as issue for Arav?
|
No, preferably new members don't have to worry about build system internals. I'll be the one setting up and validating this one |
closes #97
The library can be used by adding:
to a
firmware_project_g4target.