blob: 1ffd1c3eaeb384c7331622bacf012d5cc5c6c3eb [file]
# Copyright 2025 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_rust//rust:defs.bzl", "rust_doc", "rust_library")
load("//pw_kernel/arch/arm_cortex_m:defs.bzl", "SUPPORTED_CORTEX_M_CPUS")
package(default_visibility = ["//visibility:public"])
CORTEX_M_DEPS = [
"@rust_crates//:cortex-m",
"@rust_crates//:cortex-m-rt",
]
RISCV_DEPS = [
"@rust_crates//:riscv",
]
rust_library(
name = "kernel",
srcs = [
"interrupt_controller.rs",
"lib.rs",
"panic.rs",
"scheduler.rs",
"scheduler/algorithm.rs",
"scheduler/core.rs",
"scheduler/locks.rs",
"scheduler/priority.rs",
"scheduler/priority_bitmask.rs",
"scheduler/process.rs",
"scheduler/thread.rs",
"scheduler/timer.rs",
"scheduler/wait_queue.rs",
"sync.rs",
"sync/event.rs",
"sync/mutex.rs",
"sync/spinlock.rs",
"target.rs",
"trace.rs",
] + select({
"//pw_kernel/userspace:userspace_build_enabled": [
"object.rs",
"object/buffer.rs",
"object/channel.rs",
"object/interrupt.rs",
"object/process.rs",
"object/thread.rs",
"object/wait_group.rs",
"syscall.rs",
],
"//conditions:default": [],
}),
crate_features = select({
"//pw_kernel/userspace:userspace_build_enabled": ["user_space"],
"//conditions:default": [],
}) + select({
":tracing_enabled": ["tracing"],
"//conditions:default": [],
}) + select({
":system_dump_enabled": ["system_dump_on_failure"],
"//conditions:default": [],
}) + selects.with_or({
SUPPORTED_CORTEX_M_CPUS: ["arch_arm_cortex_m"],
"@platforms//cpu:riscv32": ["arch_riscv"],
"//conditions:default": [
"std_panic_handler",
],
}),
edition = "2024",
proc_macro_deps = [
"@rust_crates//:paste",
] + selects.with_or({
SUPPORTED_CORTEX_M_CPUS: ["//pw_kernel/macros:arm_cortex_m_macro"],
"@platforms//cpu:riscv32": ["//pw_kernel/macros:riscv_macro"],
"//conditions:default": [],
}),
tags = ["kernel"],
target_compatible_with = selects.with_or({
SUPPORTED_CORTEX_M_CPUS: [],
"@platforms//cpu:riscv32": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
"//pw_assert/rust:pw_assert",
"//pw_kernel/config:kernel_config",
"//pw_kernel/lib/foreign_box",
"//pw_kernel/lib/list",
"//pw_kernel/lib/log_if",
"//pw_kernel/lib/magic_values",
"//pw_kernel/lib/memory_config",
"//pw_kernel/lib/pw_atomic",
"//pw_kernel/lib/pw_cast",
"//pw_kernel/lib/pw_kernel_tracing",
"//pw_kernel/lib/regs",
"//pw_kernel/lib/vectored_buffer",
"//pw_kernel/subsys/console",
"//pw_kernel/syscall:exit_status",
"//pw_log/rust:pw_log",
"//pw_status/rust:pw_status",
"//pw_time/rust:pw_time_core",
"@rust_crates//:bitflags",
] + select({
"//pw_kernel/userspace:userspace_build_enabled": [
"//pw_kernel/syscall:syscall_defs",
],
"//conditions:default": [],
}) + selects.with_or({
SUPPORTED_CORTEX_M_CPUS: CORTEX_M_DEPS,
"@platforms//cpu:riscv32": RISCV_DEPS,
"//conditions:default": [],
}),
)
rust_doc(
name = "kernel_doc",
crate = ":kernel",
rustdoc_flags = [
"--document-private-items",
] + select({
"//pw_kernel/userspace:userspace_build_enabled": ["--cfg=feature=\"user_space\""],
"//conditions:default": [],
}) + select({
# Arch feature selection will be removed when arch support moves out of
# the kernel crate.
"@platforms//cpu:armv8-m": ["--cfg=feature=\"arch_arm_cortex_m\""],
"@platforms//cpu:riscv32": ["--cfg=feature=\"arch_riscv\""],
"//conditions:default": [
"--cfg=feature=\"std_panic_handler\"",
],
}),
tags = ["kernel"],
)
bool_flag(
name = "tracing",
build_setting_default = False,
)
config_setting(
name = "tracing_enabled",
flag_values = {
":tracing": "true",
},
)
bool_flag(
name = "system_dump",
build_setting_default = False,
)
config_setting(
name = "system_dump_enabled",
flag_values = {
":system_dump": "true",
},
)