diff --git a/.bazelrc b/.bazelrc index e70ca8c7bb..c7eae98530 100644 --- a/.bazelrc +++ b/.bazelrc @@ -40,9 +40,6 @@ build:asan-libfuzzer \ --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan -# Configures toolchain with polyfill headers. -build --@rules_cc_toolchain_config//:user_defined=//pw_polyfill:toolchain_polyfill_overrides - # Specifies desired output mode for running tests. # Valid values are # 'summary' to output only test status summary diff --git a/WORKSPACE b/WORKSPACE index 1145d02712..e2ac7eec26 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -232,15 +232,6 @@ git_repository( remote = "https://github.com/bazelembedded/bazel-embedded.git", ) -# Instantiate Pigweed configuration for embedded toolchain, -# this must be called before bazel_embedded_deps. -load( - "//pw_build:pigweed_toolchain_upstream.bzl", - "toolchain_upstream_deps", -) - -toolchain_upstream_deps() - # Configure bazel_embedded toolchains and platforms. load( "@bazel_embedded//:bazel_embedded_deps.bzl", diff --git a/pw_build/pigweed_toolchain_upstream.bzl b/pw_build/pigweed_toolchain_upstream.bzl deleted file mode 100644 index a77cce6bed..0000000000 --- a/pw_build/pigweed_toolchain_upstream.bzl +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2021 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. -"""Implements the set of dependencies that bazel-embedded requires.""" - -def _toolchain_upstream_repository_impl(rctx): - """Creates a remote repository with a set of toolchain components. - - The bazel embedded toolchain expects two targets injected_headers - and polyfill. This is rule generates these targets so that - bazel-embedded can depend on them and so that the targets can depend - on pigweeds implementation of polyfill. This rule is only ever - intended to be instantiated with the name - "bazel_embedded_upstream_toolchain", and should only be used from - the "toolchain_upstream_deps" macro. - - The bazel-embedded package expects to be able to access these - targets as @bazel_embedded_upstream_toolchain//:polyfill and - @bazel_embedded_upstream_toolchain//:injected_headers. - - Args: - rctx: Repository context. - """ - rctx.file("BUILD", """ -package(default_visibility = ["//visibility:public"]) -load( - "@bazel_embedded//toolchains/tools/include_tools:defs.bzl", - "cc_injected_toolchain_header_library", - "cc_polyfill_toolchain_library", -) - -cc_polyfill_toolchain_library( - name = "polyfill", - deps = ["@pigweed//pw_polyfill:toolchain_polyfill_overrides"], -) - -cc_injected_toolchain_header_library( - name = "injected_headers", - deps = ["@pigweed//pw_polyfill:toolchain_injected_headers"], -) -""") - -_toolchain_upstream_repository = repository_rule( - _toolchain_upstream_repository_impl, - doc = """ -toolchain_upstream_repository creates a remote repository that can be -accessed by a toolchain repository to configure system includes. - -It's recommended to use this rule through the 'toolchain_upstream_deps' -macro rather than using this rule directly. -""", -) - -def toolchain_upstream_deps(): - """Implements the set of dependencies that bazel-embedded requires. - - These targets are used to override the default toolchain - requirements in the remote bazel-embedded toolchain. The remote - toolchain expects to find two targets; - - "@bazel_embedded_upstream_toolchain//:polyfill" -> Additional - system headers for the toolchain - - "@bazel_embedded_upstream_toolchain//:injected_headers" -> - Headers that are injected into the toolchain via the -include - command line argument - """ - _toolchain_upstream_repository( - name = "bazel_embedded_upstream_toolchain", - ) diff --git a/pw_bytes/BUILD.bazel b/pw_bytes/BUILD.bazel index 5c914c01bc..d95a032cff 100644 --- a/pw_bytes/BUILD.bazel +++ b/pw_bytes/BUILD.bazel @@ -45,6 +45,12 @@ pw_cc_library( ], ) +pw_cc_library( + name = "bit", + hdrs = ["public/pw_bytes/bit.h"], + includes = ["public"], +) + pw_cc_test( name = "array_test", srcs = ["array_test.cc"], diff --git a/pw_bytes/BUILD.gn b/pw_bytes/BUILD.gn index 97f10d1cc6..bd54e4405d 100644 --- a/pw_bytes/BUILD.gn +++ b/pw_bytes/BUILD.gn @@ -19,13 +19,13 @@ import("$dir_pw_build/target_types.gni") import("$dir_pw_docgen/docs.gni") import("$dir_pw_unit_test/test.gni") -config("default_config") { +config("public_include_path") { include_dirs = [ "public" ] visibility = [ ":*" ] } pw_source_set("pw_bytes") { - public_configs = [ ":default_config" ] + public_configs = [ ":public_include_path" ] public = [ "public/pw_bytes/array.h", "public/pw_bytes/byte_builder.h", @@ -41,6 +41,12 @@ pw_source_set("pw_bytes") { ] } +pw_source_set("bit") { + public_configs = [ ":public_include_path" ] + public = [ "public/pw_bytes/bit.h" ] + remove_public_deps = [ "*" ] +} + pw_test_group("tests") { tests = [ ":array_test", diff --git a/pw_bytes/CMakeLists.txt b/pw_bytes/CMakeLists.txt index 4bc6e4d571..99937f3039 100644 --- a/pw_bytes/CMakeLists.txt +++ b/pw_bytes/CMakeLists.txt @@ -37,6 +37,13 @@ if(Zephyr_FOUND AND CONFIG_PIGWEED_BYTES) zephyr_link_libraries(pw_bytes) endif() +pw_add_module_library(pw_bytes.bit + HEADERS + public/pw_bytes/bit.h + PUBLIC_INCLUDES + public +) + pw_add_test(pw_bytes.array_test SOURCES array_test.cc diff --git a/pw_bytes/docs.rst b/pw_bytes/docs.rst index 6313abb89c..fa5db2caf0 100644 --- a/pw_bytes/docs.rst +++ b/pw_bytes/docs.rst @@ -1,30 +1,33 @@ .. _module-pw_bytes: ---------- +========= pw_bytes ---------- +========= pw_bytes is a collection of utilities for manipulating binary data. +------------- Compatibility -============= +------------- C++17 +------------ Dependencies -============ +------------ * ``pw_preprocessor`` * ``pw_status`` * ``pw_span`` +-------- Features -======== +-------- pw_bytes/array.h ----------------- +================ Functions for working with byte arrays, primarily for building fixed-size byte arrays at compile time. pw_bytes/byte_builder.h ------------------------ +======================= .. cpp:class:: ByteBuilder ``ByteBuilder`` is a class that facilitates building or reading arrays of @@ -36,15 +39,22 @@ pw_bytes/byte_builder.h ``ByteBuilder`` with an internally allocated buffer. Size report: using ByteBuffer -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +----------------------------- .. include:: byte_builder_size_report +pw_bytes/bit.h +================ +Implementation of features provided by C++20's ```` header. Supported +features: + +* ``pw::endian`` -- Implementation of the ``std::endian`` enum. + pw_bytes/endian.h ------------------ +================= Functions for converting the endianness of integral values. pw_bytes/units.h ----------------- +================ Constants, functions and user-defined literals for specifying a number of bytes in powers of two, as defined by IEC 60027-2 A.2 and ISO/IEC 80000:13-2008. @@ -78,7 +88,8 @@ also similar functions: constexpr size_t kBufferSizeBytes = pw::bytes::MiB(1) + pw::bytes::KiB(42); +------ Zephyr -====== +------ To enable ``pw_bytes`` for Zephyr add ``CONFIG_PIGWEED_BYTES=y`` to the project's configuration. diff --git a/pw_bytes/public/pw_bytes/bit.h b/pw_bytes/public/pw_bytes/bit.h new file mode 100644 index 0000000000..c712719e68 --- /dev/null +++ b/pw_bytes/public/pw_bytes/bit.h @@ -0,0 +1,44 @@ +// Copyright 2022 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. + +// Features from the header introduced in C++20. +#pragma once + +#if __has_include() +#include +#endif // __has_include() + +namespace pw { + +#ifdef __cpp_lib_endian + +using std::endian; + +#elif defined(__GNUC__) + +enum class endian { + little = __ORDER_LITTLE_ENDIAN__, + big = __ORDER_BIG_ENDIAN__, + native = __BYTE_ORDER__, +}; + +#else + +static_assert(false, + "The pw::endian enum is not defined for this compiler. Add a " + "definition to pw_bytes/bit.h."); + +#endif // __cpp_lib_endian + +} // namespace pw diff --git a/pw_polyfill/BUILD.bazel b/pw_polyfill/BUILD.bazel index 1d119efcec..2efcd642ca 100644 --- a/pw_polyfill/BUILD.bazel +++ b/pw_polyfill/BUILD.bazel @@ -17,26 +17,11 @@ load( "pw_cc_library", "pw_cc_test", ) -load("@rules_cc_toolchain//cc_toolchain:cc_toolchain_import.bzl", "cc_toolchain_import") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) -cc_toolchain_import( - name = "toolchain_polyfill_overrides", - hdrs = [ - "bit_public_overrides/bit", - "standard_library_public/pw_polyfill/standard_library/bit.h", - "standard_library_public/pw_polyfill/standard_library/namespace.h", - ], - includes = [ - "bit_public_overrides", - "public", - "standard_library_public", - ], -) - pw_cc_library( name = "pw_polyfill", hdrs = [ @@ -46,16 +31,6 @@ pw_cc_library( includes = ["public"], ) -# TODO(b/235237667): Deprecate this once all users have been migrated to targeted -# polyfill deps. -pw_cc_library( - name = "overrides", - deps = [ - ":bit", - ":span", - ], -) - # Provides 's std::endian. pw_cc_library( name = "bit", @@ -64,10 +39,13 @@ pw_cc_library( "standard_library_public/pw_polyfill/standard_library/bit.h", ], includes = [ - "public_overrides", + "bit_public_overrides", "standard_library_public", ], - deps = [":standard_library"], + deps = [ + ":standard_library", + "//pw_bytes:bit", + ], ) # Provides 's std::byte. @@ -117,6 +95,7 @@ pw_cc_test( name = "test", srcs = ["test.cc"], deps = [ + ":bit", ":cstddef", ":iterator", ":pw_polyfill", diff --git a/pw_polyfill/BUILD.gn b/pw_polyfill/BUILD.gn index 24e46294a2..0f1df87b67 100644 --- a/pw_polyfill/BUILD.gn +++ b/pw_polyfill/BUILD.gn @@ -67,7 +67,10 @@ pw_source_set("bit") { ":standard_library_public", ":bit_overrides_config", ] - public_deps = [ ":standard_library" ] + public_deps = [ + ":standard_library", + "$dir_pw_bytes:bit", + ] remove_public_deps = [ "*" ] inputs = [ "bit_public_overrides/bit" ] public = [ "standard_library_public/pw_polyfill/standard_library/bit.h" ] diff --git a/pw_polyfill/CMakeLists.txt b/pw_polyfill/CMakeLists.txt index 7b72ff268f..edf137c83d 100644 --- a/pw_polyfill/CMakeLists.txt +++ b/pw_polyfill/CMakeLists.txt @@ -45,6 +45,7 @@ pw_add_module_library(pw_polyfill.bit bit_public_overrides standard_library_public PUBLIC_DEPS + pw_bytes.bit pw_polyfill.standard_library ) diff --git a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/bit.h b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/bit.h index 72cea9e491..1fa06756d3 100644 --- a/pw_polyfill/standard_library_public/pw_polyfill/standard_library/bit.h +++ b/pw_polyfill/standard_library_public/pw_polyfill/standard_library/bit.h @@ -13,19 +13,16 @@ // the License. #pragma once +#include "pw_bytes/bit.h" #include "pw_polyfill/standard_library/namespace.h" -_PW_POLYFILL_BEGIN_NAMESPACE_STD - #ifndef __cpp_lib_endian #define __cpp_lib_endian 201907L -enum class endian { - little = __ORDER_LITTLE_ENDIAN__, - big = __ORDER_BIG_ENDIAN__, - native = __BYTE_ORDER__, -}; +_PW_POLYFILL_BEGIN_NAMESPACE_STD -#endif // __cpp_lib_endian +using pw::endian; _PW_POLYFILL_END_NAMESPACE_STD + +#endif // __cpp_lib_endian diff --git a/pw_protobuf/BUILD.bazel b/pw_protobuf/BUILD.bazel index 59d978a8c1..4acdece74d 100644 --- a/pw_protobuf/BUILD.bazel +++ b/pw_protobuf/BUILD.bazel @@ -63,7 +63,6 @@ pw_cc_library( "//pw_containers:vector", "//pw_function", "//pw_polyfill:bit", - "//pw_polyfill:overrides", "//pw_result", "//pw_span", "//pw_status", diff --git a/pw_tls_client/BUILD.gn b/pw_tls_client/BUILD.gn index 8a89cf3a90..6ea1406c5e 100644 --- a/pw_tls_client/BUILD.gn +++ b/pw_tls_client/BUILD.gn @@ -116,6 +116,7 @@ pw_source_set("build_time") { pw_source_set("crlset") { public_configs = [ ":public_includes" ] public = [ "public/pw_tls_client/crlset.h" ] + public_deps = [ dir_pw_bytes ] # TODO(pwbug/396): Add sources generated from a CRLSet file to build. }