Skip to content

Commit

Permalink
Fix Bazel build breakages (#1908)
Browse files Browse the repository at this point in the history
* Fix Bazel build breakages

* Adds support for new PICO_DEFAULT_UART_BAUD_RATE option.
* Fixes issues related to Picotool and boot_picoboot_headers.
* Adds pico_float RISC-V pieces to the Bazel build (not yet fully
  tested).
* Adds the missing adafruit board header to the Bazel build.

* Exclude hazard3 float test in Bazel validation script

* Restore missing dependency in hardware_boot_lock
  • Loading branch information
armandomontanez authored Sep 10, 2024
1 parent 3a79149 commit b49d4ec
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 20 deletions.
8 changes: 7 additions & 1 deletion bazel/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ bool_flag(
build_setting_default = True,
)

# PICO_BAZEL_CONFIG: PICO_DEFAULT_UART_BAUD_RATE, Define the default UART baudrate, type=int, max=921600, default=115200, group=hardware_uart
int_flag(
name = "PICO_DEFAULT_UART_BAUD_RATE",
build_setting_default = 115200,
)

# PICO_BAZEL_CONFIG: PICO_STDIO_USB, Option to globally enable stdio USB for all targets by default, type=bool, default=0, group=pico_stdlib
bool_flag(
name = "PICO_STDIO_USB",
Expand Down Expand Up @@ -151,7 +157,7 @@ bool_flag(
build_setting_default = True,
)

# PICO_BAZEL_CONFIG: PICO_CMSIS_PATH, Label of a cc_ibrary providing CMSIS core, default="included stub CORE only impl", group=build
# PICO_BAZEL_CONFIG: PICO_CMSIS_PATH, Label of a cc_ibrary providing CMSIS core, type=string, default="included stub CORE only impl", group=build
label_flag(
name = "PICO_CMSIS_PATH",
build_setting_default = "//src/rp2_common/cmsis:cmsis_core",
Expand Down
5 changes: 5 additions & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ alias(
"//src/common/hardware_claim:__pkg__",
"//src/common/pico_base_headers:__pkg__",
"//src/common/pico_binary_info:__pkg__",
# These libraries sometimes need the host version even though they live
# in rp2_common.
"//src/rp2_common/boot_bootrom_headers:__pkg__",
"//src/rp2_common/hardware_boot_lock:__pkg__",
"//src/rp2_common/pico_flash:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions src/boards/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BOARD_CHOICES = [
"0xcb_helios",
"adafruit_feather_rp2040_usb_host",
"adafruit_feather_rp2040",
"adafruit_feather_rp2350",
"adafruit_itsybitsy_rp2040",
"adafruit_kb2040",
"adafruit_macropad_rp2040",
Expand Down
2 changes: 2 additions & 0 deletions src/common/boot_picoboot_headers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package(default_visibility = ["//visibility:public"])

# This needs to remain compatible with the host build since it's used by
# Picotool.
cc_library(
name = "boot_picoboot_headers",
hdrs = [
Expand Down
10 changes: 5 additions & 5 deletions src/rp2040/boot_stage2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ cc_binary(
copts = ["-fPIC"],
# Incompatible with section garbage collection.
features = ["-gc_sections"],
# Platforms will commonly depend on bootloader components in every
# binary via `link_extra_libs`, so we must drop these deps when
# building the bootloader binaries themselves in order to avoid a
# circular dependency.
link_extra_lib = "//bazel:empty_cc_lib",
linkopts = [
"-Wl,--no-gc-sections",
"-nostartfiles",
"-Wl,--entry=_stage2_boot",
"-T$(location boot_stage2.ld)",
],
# Platforms will commonly depend on bootloader components in every
# binary via `link_extra_libs`, so we must drop these deps when
# building the bootloader binaries themselves in order to avoid a
# circular dependency.
link_extra_lib = "//bazel:empty_cc_lib",
# this does nothing if someone passes --custom_malloc, so the
# rp2040_bootloader_binary transition forcibly clobbers --custom_malloc.
malloc = "//bazel:empty_cc_lib",
Expand Down
1 change: 1 addition & 0 deletions src/rp2_common/hardware_boot_lock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cc_library(
hdrs = ["include/hardware/boot_lock.h"],
includes = ["include"],
tags = ["manual"],
deps = ["//src:pico_platform_internal"],
visibility = ["//src/rp2_common/pico_bootrom:__pkg__"],
)

Expand Down
6 changes: 5 additions & 1 deletion src/rp2_common/hardware_hazard3/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ package(default_visibility = ["//visibility:public"])

cc_library(
name = "hardware_hazard3",
hdrs = ["include/hardware/hazard3.h"],
hdrs = [
"include/hardware/hazard3.h",
"include/hardware/hazard3/features.h",
"include/hardware/hazard3/instructions.h",
],
includes = ["include"],
target_compatible_with = compatible_with_rp2() + ["@platforms//cpu:riscv32"],
deps = [
Expand Down
8 changes: 8 additions & 0 deletions src/rp2_common/hardware_uart/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
load("//bazel:defs.bzl", "compatible_with_rp2")
load("//bazel/util:sdk_define.bzl", "pico_sdk_define")

package(default_visibility = ["//visibility:public"])

pico_sdk_define(
name = "PICO_DEFAULT_UART_BAUD_RATE",
define_name = "PICO_DEFAULT_UART_BAUD_RATE",
from_flag = "//bazel/config:PICO_DEFAULT_UART_BAUD_RATE",
)

cc_library(
name = "hardware_uart",
srcs = ["uart.c"],
hdrs = ["include/hardware/uart.h"],
includes = ["include"],
target_compatible_with = compatible_with_rp2(),
deps = [
":PICO_DEFAULT_UART_BAUD_RATE",
"//src/rp2_common:hardware_regs",
"//src/rp2_common:hardware_structs",
"//src/rp2_common:pico_platform",
Expand Down
1 change: 1 addition & 0 deletions src/rp2_common/pico_bit_ops/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cc_library(
"//src/common/pico_bit_ops_headers:pico_bit_ops_interface",
"//src/rp2_common:pico_platform_internal",
"//src/rp2_common/pico_bootrom",
"//src/rp2_common/pico_runtime_init",
],
alwayslink = True, # Ensures the wrapped symbols are linked in.
)
18 changes: 8 additions & 10 deletions src/rp2_common/pico_bootrom/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("//bazel:defs.bzl", "compatible_with_rp2")

package(default_visibility = ["//visibility:public"])

# Picotool needs this, so we can't strictly constrain compatibility.
# Picotool needs this, so we can't strictly constrain platform compatibility.
cc_library(
name = "pico_bootrom_headers",
hdrs = [
Expand All @@ -15,8 +15,13 @@ cc_library(
tags = ["manual"],
visibility = ["@picotool//:__subpackages__"],
deps = [
"//src/rp2_common/boot_bootrom_headers",
"//src/rp2_common/hardware_boot_lock:hardware_boot_lock_headers",
],
"//src/rp2_common/pico_flash:pico_flash_headers",
] + select({
"//bazel/constraint:host": ["//src/host/hardware_sync"],
"//conditions:default": ["//src/rp2_common/hardware_sync"],
}),
)

cc_library(
Expand All @@ -25,22 +30,15 @@ cc_library(
"bootrom.c",
"bootrom_lock.c",
],
hdrs = [
"include/pico/bootrom.h",
"include/pico/bootrom/lock.h",
"include/pico/bootrom/sf_table.h",
"include/pico/bootrom_constants.h",
],
implementation_deps = [
"//src/common/boot_picobin_headers",
"//src/common/boot_picoboot_headers",
"//src/rp2_common/hardware_sync",
"//src/rp2_common/pico_runtime_init",
],
includes = ["include"],
target_compatible_with = compatible_with_rp2(),
deps = [
"//src/rp2_common/hardware_boot_lock",
":pico_bootrom_headers",
] + select({
"//bazel/constraint:host": [
],
Expand Down
16 changes: 14 additions & 2 deletions src/rp2_common/pico_flash/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ load("//bazel:defs.bzl", "compatible_with_rp2")

package(default_visibility = ["//visibility:public"])

# Picotool needs this (transitively through
# //src/rp2_common/pico_bootrom:pico_bootrom_headers), so we can't strictly
# constrain compatibility.
cc_library(
name = "pico_flash_headers",
hdrs = ["include/pico/flash.h"],
includes = ["include"],
visibility = ["//src/rp2_common/pico_bootrom:__pkg__"],
deps = [
"//src:pico_platform_internal",
],
)

cc_library(
name = "pico_flash",
srcs = ["flash.c"],
hdrs = ["include/pico/flash.h"],
defines = select({
"//bazel/constraint:pico_freertos_unset": ["PICO_FREERTOS_LIB=0"],
"//conditions:default": ["PICO_FREERTOS_LIB=1"],
}),
includes = ["include"],
target_compatible_with = compatible_with_rp2(),
deps = [
":pico_flash_headers",
"//src/common/pico_time",
"//src/rp2_common:pico_platform",
"//src/rp2_common/hardware_exception",
Expand Down
11 changes: 11 additions & 0 deletions src/rp2_common/pico_float/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ alias(
actual = select({
"//bazel/constraint:rp2040": ":pico_float_pico",
"@platforms//cpu:armv8-m": ":pico_float_vfp",
"@platforms//cpu:riscv32": ":pico_float_single_hazard3",
"//conditions:default": ":pico_float_compiler",
}),
visibility = ["//visibility:private"],
Expand Down Expand Up @@ -138,12 +139,22 @@ _PICO_FLOAT_IMPLS = [
"extra_deps": ["//src/rp2_common/hardware_dcp"],
"linkopts": _WRAP_FLOAT_SCI_FLAGS,
},
{
"name": "single_hazard3",
"srcs": [
"float_single_hazard3.S",
],
"compatibility": compatible_with_rp2() + ["@platforms//cpu:riscv32"],
"extra_deps": ["//src/rp2_common/hardware_hazard3"],
"linkopts": _WRAP_FLOAT_SCI_FLAGS,
},
]

# Creates:
# * pico_float_pico
# * pico_float_dcp
# * pico_float_vfp
# * pico_float_single_hazard3
[
cc_library(
name = "pico_float_{}".format(impl["name"]),
Expand Down
2 changes: 1 addition & 1 deletion src/rp2_common/pico_lwip/lwip.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ cc_library(
"contrib/ports/freertos/include/arch",
"src/include",
],
visibility = ["//visibility:private"],
deps = [
"@pico-sdk//bazel/config:PICO_LWIP_CONFIG",
"@pico-sdk//src/rp2_common/pico_lwip:pico_lwip_config",
],
visibility = ["//visibility:private"],
)

cc_library(
Expand Down
1 change: 1 addition & 0 deletions src/rp2_common/pico_mem_ops/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cc_library(
deps = [
"//src/rp2_common:pico_platform_internal",
"//src/rp2_common/pico_bootrom",
"//src/rp2_common/pico_runtime_init",
],
alwayslink = True, # Ensures the wrapped symbols are linked in.
)
23 changes: 23 additions & 0 deletions test/pico_float_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ load("//bazel/util:transition.bzl", "pico_float_test_binary")

package(default_visibility = ["//visibility:public"])

cc_binary(
name = "hazard3_test_gen",
srcs = ["hazard3_test_gen.c"],
target_compatible_with = ["//bazel/constraint:host"],
)

# TODO: Set up a transition to build this under RISC-V.
cc_binary(
name = "pico_float_test_hazard3",
testonly = True,
srcs = [
"pico_float_test_hazard3.c",
"vectors/hazard3_addsf.inc",
"vectors/hazard3_mulsf.inc",
],
includes = ["."],
target_compatible_with = compatible_with_rp2() + ["@platforms//cpu:riscv32"],
deps = [
"//src/rp2_common/pico_float",
"//src/rp2_common/pico_stdlib",
],
)

cc_binary(
name = "pico_float_test",
testonly = True,
Expand Down
21 changes: 21 additions & 0 deletions tools/bazel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"//test/pico_divider_test:pico_divider_nesting_test",
"//test/pico_float_test:pico_double_test",
"//test/pico_float_test:pico_float_test",
"//test/pico_float_test:pico_float_test_hazard3",
"//test/pico_sha256_test:pico_sha256_test",
"//test/pico_stdio_test:pico_stdio_test",
"//test/pico_time_test:pico_time_test",
Expand All @@ -63,6 +64,10 @@
(
"//test/kitchen_sink:kitchen_sink_lwip_poll",
"//test/kitchen_sink:kitchen_sink_lwip_background",
# Host only.
"//test/pico_float_test:hazard3_test_gen",
# No RISC-V on RP2040.
"//test/pico_float_test:pico_float_test_hazard3",
# hardware_sha256 doesn't appear to work on RP2040.
"//test/pico_sha256_test:pico_sha256_test",
)
Expand All @@ -76,6 +81,10 @@
(
"//test/kitchen_sink:kitchen_sink_lwip_poll",
"//test/kitchen_sink:kitchen_sink_lwip_background",
# Host only.
"//test/pico_float_test:hazard3_test_gen",
# TODO: RISC-V support.
"//test/pico_float_test:pico_float_test_hazard3",
)
),
},
Expand All @@ -90,6 +99,10 @@
(
"//test/kitchen_sink:kitchen_sink_lwip_poll",
"//test/kitchen_sink:kitchen_sink_lwip_background",
# Host only.
"//test/pico_float_test:hazard3_test_gen",
# No RISC-V on RP2040.
"//test/pico_float_test:pico_float_test_hazard3",
# hardware_sha256 doesn't appear to work on RP2040.
"//test/pico_sha256_test:pico_sha256_test",
)
Expand All @@ -106,6 +119,10 @@
(
"//test/kitchen_sink:kitchen_sink_lwip_poll",
"//test/kitchen_sink:kitchen_sink_lwip_background",
# Host only.
"//test/pico_float_test:hazard3_test_gen",
# TODO: RISC-V support.
"//test/pico_float_test:pico_float_test_hazard3",
)
),
},
Expand All @@ -118,6 +135,10 @@
"extra_targets": (),
"exclusions": frozenset(
(
# Host only.
"//test/pico_float_test:hazard3_test_gen",
# No RISC-V on RP2040.
"//test/pico_float_test:pico_float_test_hazard3",
# hardware_sha256 doesn't appear to work on RP2040.
"//test/pico_sha256_test:pico_sha256_test",
)
Expand Down

0 comments on commit b49d4ec

Please sign in to comment.