Support PICO_BARE_METAL in Bazel
diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel
index 1376f22..b55d630 100644
--- a/bazel/config/BUILD.bazel
+++ b/bazel/config/BUILD.bazel
@@ -1,5 +1,15 @@
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+
package(default_visibility = ["//visibility:public"])
+
+# PICO_BAZEL_CONFIG: PICO_BARE_METAL, Flag to exclude anything except base headers from the build, type=bool, default=0, group=build
+bool_flag(
+ name = "PICO_BARE_METAL",
+ build_setting_default = False,
+)
+
+
# This should always point to a cc_library that provides
# a "pico_config_extra_headers.h".
label_flag(
diff --git a/bazel/constraint/BUILD.bazel b/bazel/constraint/BUILD.bazel
index 8af93fa..d6131af 100644
--- a/bazel/constraint/BUILD.bazel
+++ b/bazel/constraint/BUILD.bazel
@@ -30,6 +30,11 @@
],
)
+config_setting(
+ name = "pico_baremetal_enabled",
+ flag_values = {"//bazel/config:PICO_BARE_METAL": "True"},
+)
+
# This constraint setting guides Bazel's build file evaluation differences
# across different stdio configurations (e.g. stdio_usb needs TinyUSB).
constraint_setting(
diff --git a/src/common/pico_base/BUILD.bazel b/src/common/pico_base/BUILD.bazel
index e4aa2f7..894d38a 100644
--- a/src/common/pico_base/BUILD.bazel
+++ b/src/common/pico_base/BUILD.bazel
@@ -95,16 +95,11 @@
# via an intermediate.
":pico_platform",
":pico_base_interface",
- ] + select({
+ ],
+ implementation_deps = select({
"//bazel/constraint:rp2": [
- "//src/rp2_common/boot_stage2",
- "//src/rp2_common/cmsis:cmsis_core",
- "//src/rp2_common/pico_bootrom",
- "//src/rp2_common/pico_runtime",
- "//src/rp2_common/pico_standard_link",
+ "//src/rp2_common/pico_platform:platform_link_deps",
],
- "//bazel/constraint:host": [
- "//src/host/pico_platform",
- ],
+ "//conditions:default": [],
}),
)
diff --git a/src/rp2_common/pico_platform/BUILD.bazel b/src/rp2_common/pico_platform/BUILD.bazel
index 72c61c8..0009aa5 100644
--- a/src/rp2_common/pico_platform/BUILD.bazel
+++ b/src/rp2_common/pico_platform/BUILD.bazel
@@ -52,3 +52,23 @@
"//src/rp2_common/hardware_base",
],
)
+
+cc_library(
+ name = "platform_link_deps",
+ deps = select({
+ # When PICO_BARE_METAL is enabled, don't automagically add link-time
+ # dependencies.
+ "//bazel/constraint:pico_baremetal_enabled": [],
+ "//conditions:default": [
+ "//src/rp2_common/boot_stage2",
+ "//src/rp2_common/cmsis:cmsis_core",
+ "//src/rp2_common/pico_bootrom",
+ "//src/rp2_common/pico_runtime",
+ "//src/rp2_common/pico_standard_link",
+ ],
+ }),
+ target_compatible_with = select({
+ "//bazel/constraint:rp2": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
diff --git a/src/rp2_common/pico_runtime/BUILD.bazel b/src/rp2_common/pico_runtime/BUILD.bazel
index 4dcbf0e..dc7cedb 100644
--- a/src/rp2_common/pico_runtime/BUILD.bazel
+++ b/src/rp2_common/pico_runtime/BUILD.bazel
@@ -21,4 +21,5 @@
"//src/rp2_common/pico_platform:hardware_structs",
"//src/rp2_common/pico_printf",
],
+ alwayslink = True,
)