Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare Bazel for Pigweed #88

Merged
merged 5 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
nobazel
# Don't want node_modules
node_modules
# Bazel directories
bazel-bin
bazel-out
bazel-testlogs
110 changes: 94 additions & 16 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,81 @@
# See https://bazel.build/docs/user-manual for option definitions
#
# Standard Pigweed flags
# ======================
# All Pigweed projects are expected to set these flags. They mostly pre-adopt
# future Bazel settings.
#
# Do not attempt to configure an autodetected (local) toolchain. We vendor all
# our toolchains, and CI VMs may not have any local toolchain to detect.
common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# Required for new toolchain resolution API.
build --incompatible_enable_cc_toolchain_resolution

# Don't propagate flags or defines to the exec config. This will become the
# default one day (https://github.com/bazelbuild/bazel/issues/22457) and will
# improve cache hit rates between builds targeting different platforms. This is
# especially impactful for large host tools like protoc, which will have its
# cache invalidated when your host C++ config changes.
common --experimental_exclude_defines_from_exec_config
common --experimental_exclude_starlark_flags_from_exec_config

# Don't automatically create __init__.py files.
#
# This prevents spurious package name collisions at import time, and should be
# the default (https://github.com/bazelbuild/bazel/issues/7386). It's
# particularly helpful for Pigweed, because we have many potential package name
# collisions due to a profusion of stuttering paths like
# pw_transfer/py/pw_transfer.
common --incompatible_default_to_explicit_init_py

# Don't inherit system PATH. Improves hermeticity and cache hit rates. Should
# be true by default one day (https://github.com/bazelbuild/bazel/issues/7026).
common --incompatible_strict_action_env

# Expose exec toolchains for Python. We use these toolchains in some rule
# implementations (git grep for
# "@rules_python//python:exec_tools_toolchain_type").
build --@rules_python//python/config_settings:exec_tools_toolchain=enabled

# C++ toolchain configuration
# ===========================

# Ignore all warnings in third-party code.
common --per_file_copt=external/.*@-w
common --host_per_file_copt=external/.*@-w

# Picotool needs to build with exceptions and RTTI enabled.
common --per_file_copt=external.*picotool.*@-fexceptions,-frtti
common --host_per_file_copt=external.*picotool.*@-fexceptions,-frtti

# Keep debugging symbols, but don't send them when flashing.
build --strip=never

build --@pico-sdk//bazel/config:PICO_STDIO_USB=True
build --@pico-sdk//bazel/config:PICO_STDIO_UART=True

# UX settings
# ===========
# Error output settings.
common --verbose_failures
# View failed test output
test --test_output=errors

# Platform configuration
# ======================
build --@pigweed//pw_build:default_module_config=//system:module_config

# Host platform default backends.
common --@pigweed//pw_log:backend=@pigweed//pw_log_string
common --@pigweed//pw_log:backend_impl=@pigweed//pw_log_string:impl
common --@pigweed//pw_log_string:handler_backend=@pigweed//pw_system:log_backend
common --@pigweed//pw_sys_io:backend=@pigweed//pw_sys_io_stdio
common --@pigweed//pw_system:io_backend=@pigweed//pw_system:socket_target_io

# My rules
# ========
#
# Avoid incompatible_sandbox_hermetic_tmp causing relative paths to change.
# https://github.com/aspect-build/gcc-toolchain/issues/161
build --noincompatible_sandbox_hermetic_tmp
Expand All @@ -26,35 +102,37 @@ build --host_cxxopt='-std=c++23'
# Only build tests when testing
test --build_tests_only

# View failed test output
test --test_output=errors

# Allow silent builds with --config=quiet
build:quiet --ui_event_filters=-info,-stdout,-stderr
build:quiet --noshow_progress

# Allow user to extend .bazelrc
try-import %workspace%/user.bazelrc

# TODO(https://github.com/michael-christen/toolbox/issues/28): stop interference with rules_rust
# # https://github.com/aspect-build/gcc-toolchain/issues/85
# build --incompatible_enable_cc_toolchain_resolution
# build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
# # Performance per #85
# build --experimental_reuse_sandbox_directories
# # Have rules_rust use the right hermetic toolchain sysroot, symlink folders
# # into execution directory
# build --@rules_rust//cargo/settings:experimental_symlink_execroot=True
# Performance per #85
build --experimental_reuse_sandbox_directories
# Have rules_rust use the right hermetic toolchain sysroot, symlink folders
# into execution directory
build --@rules_rust//cargo/settings:experimental_symlink_execroot=True

# Must match PYTHON_VERSION in MODULE.bazel
# LINK(7e463bc3_e4d9_4464_ba39_3217c4a86004)
common --@aspect_rules_py//py:interpreter_version=3.11.9

# Remote Cache: https://app.nativelink.com/c690e34c-beac-420a-b672-6320b8f5b419/quickstart
# Remote Cache
# ============
#
# Link: : https://app.nativelink.com/c690e34c-beac-420a-b672-6320b8f5b419/quickstart
#
# NOTE: Causing link to take 8s ...
build --remote_cache=grpcs://cas-michael-christen.build-faster.nativelink.net
build --remote_header=x-nativelink-api-key=66f9052f8b6613865377d05b5202334eb9a5bb702e64270381c202f6e9ae4072
build --bes_backend=grpcs://bes-michael-christen.build-faster.nativelink.net
build --bes_header=x-nativelink-api-key=66f9052f8b6613865377d05b5202334eb9a5bb702e64270381c202f6e9ae4072
build --remote_timeout=600


# Allow user to extend .bazelrc
# https://bazel.build/configure/best-practices#bazelrc-file
#
# note: this should be at the bottom of the file, so that user-specified
# options override anything in this file
# (https://bazel.build/run/bazelrc#imports)
try-import %workspace%/user.bazelrc
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.2.1
0ddcfd327ffd012d348deeae08ec0836409706ad
6 changes: 3 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
gazelle_python.yaml linguist-generated=true
requirements_lock.txt linguist-generated=true
MODULE.bazel.lock linguist-generated=true
gazelle_python.yaml linguist-generated=true -diff
requirements_lock.txt linguist-generated=true -diff
MODULE.bazel.lock linguist-generated=true -diff
90 changes: 86 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module(
# Generic deps
########################################
bazel_dep(name = "aspect_bazel_lib", version = "2.5.1")
bazel_dep(name = "platforms", version = "0.0.9")

########################################
# Set up rules_python and pip
Expand All @@ -23,7 +22,7 @@ bazel_dep(name = "aspect_rules_py", version = "0.7.3")

# Minimum version needs:
# feat: add interpreter_version_info to py_runtime by @mattem in #1671
bazel_dep(name = "rules_python", version = "0.29.0", dev_dependency = True)
bazel_dep(name = "rules_python", version = "0.34.0", dev_dependency = True)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")

Expand All @@ -44,7 +43,8 @@ pip.parse(
)
use_repo(pip, "pip")

bazel_dep(name = "protobuf", version = "26.0")
# TODO(#91): Allow bumping this up to 26 or greater while avoiding segfault
bazel_dep(name = "protobuf", version = "24.4")
bazel_dep(name = "rules_rust", version = "0.48.0")

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
Expand Down Expand Up @@ -148,7 +148,7 @@ bazel_dep(name = "rules_apple", version = "3.7.0", repo_name = "build_bazel_rule
# Bazel rule helpers, including testing
bazel_dep(name = "bazel_skylib", version = "1.7.1")

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True) # mchristen add

# Allow platform transitions
bazel_dep(name = "rules_platform", version = "0.1.0")
Expand All @@ -165,3 +165,85 @@ register_toolchains(
"//examples/bazel:foo_rude_toolchain",
"//examples/bazel:foo_nice_toolchain",
)

# Pigweed
######################################

bazel_dep(name = "freertos", version = "10.5.1.bcr.2")
bazel_dep(name = "nanopb", repo_name = "com_github_nanopb_nanopb")
bazel_dep(name = "pico-sdk", version = "2.0.0")
bazel_dep(name = "pigweed")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "pw_toolchain")
bazel_dep(name = "rules_cc")

bazel_dep(name = "hedron_compile_commands", dev_dependency = True)

# Module overrides
# ================
# TODO: https://pwbug.dev/349880767 - Point this back to the upstream repo once
# this PR is merged.
archive_override(
module_name = "hedron_compile_commands",
strip_prefix = "bazel-compile-commands-extractor-163521345aa6366fd1ed801b989b668b5c806f69",
urls = ["https://github.com/chadnorvell/bazel-compile-commands-extractor/archive/163521345aa6366fd1ed801b989b668b5c806f69.tar.gz"],
)

archive_override(
module_name = "rules_rust",
integrity = "sha256-+bWb47wg0VchIADaHt6L5Dma2Gn+Q589nz/MKcTi+lo=",
# Can only apply patches from local workspace
# patch_strip = 1,
# patches = [
# # Fix rustdoc test w/ proc macros
# # https://github.com/bazelbuild/rules_rust/pull/1952
# "@pigweed//pw_rust/bazel_patches:0001-rustdoc_test-Apply-prefix-stripping-to-proc_macro-de.patch",
# # Adds prototype functionality for documenting multiple crates in one
# # HTML output directory. While the approach in this patch may have
# # issues scaling to giant mono-repos, it is appropriate for embedded
# # projects and minimally invasive and should be easy to maintain. Once
# # the `rules_rust` community decides on a way to propperly support this,
# # we will migrate to that solution.
# # https://github.com/konkers/rules_rust/tree/wip/rustdoc
# "@pigweed//pw_rust/bazel_patches:0002-PROTOTYPE-Add-ability-to-document-multiple-crates-at.patch",
# ],
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.45.1/rules_rust-v0.45.1.tar.gz"],
)

# TODO: https://pwbug.dev/354274498 - nanopb is not yet in the BCR.
git_override(
module_name = "nanopb",
commit = "7c6c581bc6f7406a4f01c3b9853251ff0a68458b",
remote = "https://github.com/nanopb/nanopb.git",
)

git_override(
module_name = "pigweed",
# ROLL: Warning: this entry is automatically updated.
# ROLL: Last updated 2024-08-14.
# ROLL: By https://cr-buildbucket.appspot.com/build/8739669590315800497.
commit = "c9d5bef2f82612fa8d4be0d53b614bbc02bab62b",
remote = "https://pigweed.googlesource.com/pigweed/pigweed",
)

git_override(
module_name = "pw_toolchain",
# ROLL: Warning: this entry is automatically updated.
# ROLL: Last updated 2024-08-14.
# ROLL: By https://cr-buildbucket.appspot.com/build/8739669590315800497.
commit = "c9d5bef2f82612fa8d4be0d53b614bbc02bab62b",
remote = "https://pigweed.googlesource.com/pigweed/pigweed",
strip_prefix = "pw_toolchain_bazel",
)

# TODO: https://pwbug.dev/258836641 - Pre-release version needed for the Pico
# SDK. Remove this once rules_cc 0.10.0 is released and the Pico SDK
# MODULE.bazel declares its dependency on it.
archive_override(
module_name = "rules_cc",
integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=",
strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f",
urls = [
"https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip",
],
)
Loading