Introduce initial Bazel build #1705

Merged
armandomontanez merged 38 commits from initial-bazel-build into develop 2024-06-04 18:50:33 -05:00
armandomontanez commented 2024-05-15 20:48:29 -05:00 (Migrated from github.com)

Introduces the beginnings of a Bazel build for the Raspberry Pi Pico. The vast majority of preexisting build system configuration options are missing, but the build produces working binaries when used from an external project.

Introduces the beginnings of a Bazel build for the Raspberry Pi Pico. The vast majority of preexisting build system configuration options are missing, but the build produces working binaries when used from an external project.
armandomontanez (Migrated from github.com) reviewed 2024-05-15 20:53:40 -05:00
@ -0,0 +1,71 @@
module(name = "pico-sdk", version = "1.6.0-rc1")
armandomontanez (Migrated from github.com) commented 2024-05-15 20:53:40 -05:00

I have an open commit that I need to include, so I'll be updating this shortly. If needed, I can get a full release of rules_cc cut before merging this PR.

I have an open commit that I need to include, so I'll be updating this shortly. If needed, I can get a full release of `rules_cc` cut before merging this PR.
armandomontanez commented 2024-05-15 20:59:12 -05:00 (Migrated from github.com)

@kilograham I've put together an initial PR for adding a Bazel build, I have a few minor bits of cleanup before this is fully ready to merge, but I wanted to raise it to you now so you can start sharing any feedback/questions/concerns you may have now. @tpudlik has offered to review this from the Bazel side of things.

@kilograham I've put together an initial PR for adding a Bazel build, I have a few minor bits of cleanup before this is fully ready to merge, but I wanted to raise it to you now so you can start sharing any feedback/questions/concerns you may have now. @tpudlik has offered to review this from the Bazel side of things.
tpudlik (Migrated from github.com) reviewed 2024-05-21 16:27:31 -05:00
@ -0,0 +1,137 @@
# Bazel build
tpudlik (Migrated from github.com) commented 2024-05-20 18:07:24 -05:00
```python
```suggestion ```python ```
tpudlik (Migrated from github.com) commented 2024-05-20 18:07:55 -05:00
```python
```suggestion ```python ```
@ -0,0 +57,4 @@
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
```
### Ready to build!
tpudlik (Migrated from github.com) commented 2024-05-20 18:35:05 -05:00

Should the README mention pico_config_extra_headers and pico_config_platform_headers?

Should the README mention `pico_config_extra_headers` and `pico_config_platform_headers`?
@ -0,0 +3,4 @@
# This constraint represents the dimension that guides the Pico SDK build. This
# constraint will only ever enumerate specific MCUs (and the host), and does NOT
# cover the differences from board-to-board.
constraint_setting(
tpudlik (Migrated from github.com) commented 2024-05-20 18:36:30 -05:00

The constraint_settings should really have comments explaining what they mean!

Eventually, will each header in src/boards/include/boards have a corresponding sdk_target constraint_value?

The `constraint_setting`s should really have comments explaining what they mean! Eventually, will each header in `src/boards/include/boards` have a corresponding `sdk_target` `constraint_value`?
tpudlik (Migrated from github.com) commented 2024-05-21 15:33:53 -05:00

Why introduce a variable for maybe_cond instead of just inlining it in the if statement?

Why introduce a variable for `maybe_cond` instead of just inlining it in the `if` statement?
@ -0,0 +4,4 @@
name = "rp2040",
constraint_values = [
"@pico-sdk//bazel/constraint:rp2040",
"@platforms//cpu:armv6-m", # This is just FYI.
tpudlik (Migrated from github.com) commented 2024-05-21 15:40:13 -05:00

If we don't actually refer to it, I'd remove it.

If we don't actually refer to it, I'd remove it.
@ -0,0 +1,151 @@
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
tpudlik (Migrated from github.com) commented 2024-05-21 15:39:20 -05:00

Do we have a bug to reference here?

Do we have a bug to reference here?
@ -0,0 +1,46 @@
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "OBJ_COPY_ACTION_NAME")
tpudlik (Migrated from github.com) commented 2024-05-21 15:45:26 -05:00

https://github.com/bazelbuild/bazel/pull/16158 added it in the Bazel version. Do you mean it's not in the rules_cc version? Should we create a FR?

https://github.com/bazelbuild/bazel/pull/16158 added it in the Bazel version. Do you mean it's not in the `rules_cc` version? Should we create a FR?
@ -0,0 +97,4 @@
)
alias(
name = "default",
tpudlik (Migrated from github.com) commented 2024-05-21 16:00:29 -05:00

I would maybe call this boards. That's a special target name in that @pico-sdk//src/boards:boards can be abbreviated to just @pico-sdk//src/boards in lists of deps, etc. So it's weird to reserve this "most public" name for a target that's private and intended to be burned down!

Unless we want to hide the alias behind a label_flag, to allow SDK users to provide their own board definitions.

I would maybe call this `boards`. That's a special target name in that `@pico-sdk//src/boards:boards` can be abbreviated to just `@pico-sdk//src/boards` in lists of deps, etc. So it's weird to reserve this "most public" name for a target that's private and intended to be burned down! Unless we want to hide the alias behind a `label_flag`, to allow SDK users to provide their own board definitions.
@ -0,0 +1,103 @@
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
tpudlik (Migrated from github.com) commented 2024-05-21 16:08:11 -05:00

Could the comment explain why we need to be careful? What should the maintainers be carefully watching out for?

Could the comment explain _why_ we need to be careful? What should the maintainers be carefully watching out for?
@ -0,0 +1,99 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
tpudlik (Migrated from github.com) commented 2024-05-21 16:15:07 -05:00

Shouldn't asminclude go in here instead of line 28?

Shouldn't `asminclude` go in here instead of line 28?
tpudlik (Migrated from github.com) commented 2024-05-21 16:18:52 -05:00

Consider using copy_file from Skylib, which has a simpler, cross-platform (Windows-friendly) interface: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/copy_file_doc.md

Consider using `copy_file` from Skylib, which has a simpler, cross-platform (Windows-friendly) interface: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/copy_file_doc.md
tpudlik (Migrated from github.com) commented 2024-05-21 16:20:44 -05:00

Consider using run_binary from Skylib, which doesn't rely on the shell (https://github.com/bazelbuild/bazel-skylib/blob/main/docs/run_binary_doc.md). From the docs:

Note that genrule requires a shell to interpret the command argument. It is also easy to reference arbitrary programs available on the PATH, however this makes the command non-hermetic and may not be reproducible. If you only need to run a single tool, consider using run_binary instead.

Consider using `run_binary` from Skylib, which doesn't rely on the shell (https://github.com/bazelbuild/bazel-skylib/blob/main/docs/run_binary_doc.md). From [the docs](https://bazel.build/reference/be/general#genrule): > Note that genrule requires a shell to interpret the command argument. It is also easy to reference arbitrary programs available on the PATH, however this makes the command non-hermetic and may not be reproducible. If you only need to run a single tool, consider using [run_binary](https://github.com/bazelbuild/bazel-skylib/blob/main/docs/run_binary_doc.md) instead.
@ -0,0 +16,4 @@
"include/pico/async_context_threadsafe_background.h",
],
includes = ["include"],
# Missing deps for:
tpudlik (Migrated from github.com) commented 2024-05-21 16:24:32 -05:00

Will all of these come from FreeRTOS? Another reason to upstream our FreeRTOS build file (https://pwbug.dev/326625641)!

Will all of these come from FreeRTOS? Another reason to upstream our FreeRTOS build file (https://pwbug.dev/326625641)!
@ -0,0 +1,23 @@
package(default_visibility = ["//visibility:public"])
tpudlik (Migrated from github.com) commented 2024-05-21 16:26:11 -05:00

Could you expand the TODO to mention why that's nontrivial?

Could you expand the TODO to mention why that's nontrivial?
armandomontanez (Migrated from github.com) reviewed 2024-05-22 18:34:54 -05:00
armandomontanez (Migrated from github.com) left a comment

Ready for another pass! :)

Ready for another pass! :)
@ -0,0 +57,4 @@
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
```
### Ready to build!
armandomontanez (Migrated from github.com) commented 2024-05-22 18:13:59 -05:00

Added instructions for these. They'll get totally reworked shortly, but it's good to document what's there!

Added instructions for these. They'll get totally reworked shortly, but it's good to document what's there!
@ -0,0 +3,4 @@
# This constraint represents the dimension that guides the Pico SDK build. This
# constraint will only ever enumerate specific MCUs (and the host), and does NOT
# cover the differences from board-to-board.
constraint_setting(
armandomontanez (Migrated from github.com) commented 2024-05-22 15:12:07 -05:00

No, I don't think we'll have a constraint for each board. I've added a comment to clarify. After this first PR is merged, I'll be focusing on doing a comprehensive pass over the SDK configuration and then provide better foundations for configuration options. I have some ideas here, but I'd rather build those out as a separate PR so we can review/discuss them in isolation.

No, I don't think we'll have a constraint for each board. I've added a comment to clarify. After this first PR is merged, I'll be focusing on doing a comprehensive pass over the SDK configuration and then provide better foundations for configuration options. I have some ideas here, but I'd rather build those out as a separate PR so we can review/discuss them in isolation.
armandomontanez (Migrated from github.com) commented 2024-05-22 18:16:40 -05:00

Not relevant anymore.

Not relevant anymore.
@ -0,0 +4,4 @@
name = "rp2040",
constraint_values = [
"@pico-sdk//bazel/constraint:rp2040",
"@platforms//cpu:armv6-m", # This is just FYI.
armandomontanez (Migrated from github.com) commented 2024-05-22 15:17:03 -05:00

This is a well-known constraint though. Since there's a correct value, I feel we should just configure it so people aren't left confused as to why it's unset.

This is a well-known constraint though. Since there's a correct value, I feel we should just configure it so people aren't left confused as to why it's unset.
@ -0,0 +1,151 @@
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
armandomontanez (Migrated from github.com) commented 2024-05-22 15:32:10 -05:00
Filed https://github.com/bazelbuild/rules_cc/issues/224
@ -0,0 +1,46 @@
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "OBJ_COPY_ACTION_NAME")
armandomontanez (Migrated from github.com) commented 2024-05-22 15:36:01 -05:00

Yeah, it's not yet in rules_cc: github.com/bazelbuild/rules_cc@1acf5213b6/cc/action_names.bzl

Switched to use @bazel_tools//tools/build_defs/cc:action_names.bzl for now.

Yeah, it's not yet in `rules_cc`: https://github.com/bazelbuild/rules_cc/blob/1acf5213b6170f1f0133e273cb85ede0e732048f/cc/action_names.bzl Switched to use `@bazel_tools//tools/build_defs/cc:action_names.bzl` for now.
@ -0,0 +97,4 @@
)
alias(
name = "default",
armandomontanez (Migrated from github.com) commented 2024-05-22 15:38:49 -05:00

The alias is behind a label flag: //bazel/config:pico_config_header. I renamed boards to unsupported_boards for now. I'll be taking a pass over comprehensive support for this in a follow-up.

The alias *is* behind a label flag: `//bazel/config:pico_config_header`. I renamed `boards` to `unsupported_boards` for now. I'll be taking a pass over comprehensive support for this in a follow-up.
@ -0,0 +1,103 @@
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
armandomontanez (Migrated from github.com) commented 2024-05-22 15:41:43 -05:00

Updated comment.

Updated comment.
@ -0,0 +1,99 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
armandomontanez (Migrated from github.com) commented 2024-05-22 17:23:40 -05:00

Done

Done
armandomontanez (Migrated from github.com) commented 2024-05-22 17:23:45 -05:00

Done, much cleaner now!

Done, much cleaner now!
armandomontanez (Migrated from github.com) commented 2024-05-22 18:22:07 -05:00

Yep, fixed.

Yep, fixed.
@ -0,0 +16,4 @@
"include/pico/async_context_threadsafe_background.h",
],
includes = ["include"],
# Missing deps for:
armandomontanez (Migrated from github.com) commented 2024-05-22 18:31:40 -05:00

Yeah, these are all provided by FreeRTOS. Interestingly I'm not seeing CMake configuration options for turning this on/off despite it seeming to be an optional feature. I'll mark this on my TODO list.

Yeah, these are all provided by FreeRTOS. Interestingly I'm not seeing CMake configuration options for turning this on/off despite it seeming to be an optional feature. I'll mark this on my TODO list.
@ -0,0 +1,23 @@
package(default_visibility = ["//visibility:public"])
armandomontanez (Migrated from github.com) commented 2024-05-22 15:43:18 -05:00

Updated here and elsewhere. TL;DR: we need to set up configuration patterns since it's mutually exclusive.

Updated here and elsewhere. TL;DR: we need to set up configuration patterns since it's mutually exclusive.
kilograham (Migrated from github.com) approved these changes 2024-06-04 18:50:04 -05:00
kilograham (Migrated from github.com) left a comment

I trust that this has stabilized enough for a baseline build... since it is entirely orthogonal to the CMake build, it can evolve independently.

I trust that this has stabilized enough for a baseline build... since it is entirely orthogonal to the CMake build, it can evolve independently.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!1705
No description provided.