diff options
Diffstat (limited to 'pw_span/BUILD.gn')
-rw-r--r-- | pw_span/BUILD.gn | 95 |
1 files changed, 75 insertions, 20 deletions
diff --git a/pw_span/BUILD.gn b/pw_span/BUILD.gn index e1c3f1171..91e294cc0 100644 --- a/pw_span/BUILD.gn +++ b/pw_span/BUILD.gn @@ -14,50 +14,105 @@ import("//build_overrides/pigweed.gni") +import("$dir_pw_build/module_config.gni") import("$dir_pw_build/target_types.gni") import("$dir_pw_docgen/docs.gni") +import("$dir_pw_toolchain/traits.gni") import("$dir_pw_unit_test/test.gni") -config("public_config") { +declare_args() { + # Whether or not to enable bounds-checking asserts in pw::span. Enabling this + # may significantly increase binary size, and can introduce dependency cycles + # if your pw_assert backend's headers depends directly or indirectly on + # pw_span. It's recommended to enable this for debug builds if possible. + pw_span_ENABLE_ASSERTS = false + + # The build target that overrides the default configuration options for this + # module. This should point to a source set that provides defines through a + # public config (which may -include a file or add defines directly). + # + # Most modules depend on pw_build_DEFAULT_MODULE_CONFIG as the default config, + # but since this module's config options require interaction with the build + # system, this defaults to an internal config to properly support + # pw_span_ENABLE_ASSERTS. + pw_span_CONFIG = "$dir_pw_span:span_asserts" +} + +config("public_include_path") { include_dirs = [ "public" ] visibility = [ ":*" ] } -config("overrides_config") { - include_dirs = [ "public_overrides" ] +pw_source_set("config") { + public = [ "public/pw_span/internal/config.h" ] + public_configs = [ ":public_include_path" ] + public_deps = [ pw_span_CONFIG ] + remove_public_deps = [ "*" ] visibility = [ ":*" ] } -# This source set provides the <span> header, which is accessed only through -# pw_polyfill. -pw_source_set("polyfill") { - remove_public_deps = [ "*" ] - public_configs = [ ":overrides_config" ] - public_deps = [ ":pw_span" ] - public = [ "public_overrides/span" ] - visibility = [ "$dir_pw_polyfill:*" ] +config("public_config") { + include_dirs = [ "public" ] + visibility = [ ":*" ] +} + +config("span_asserts_config") { + defines = [ "PW_SPAN_ENABLE_ASSERTS=${pw_span_ENABLE_ASSERTS}" ] + visibility = [ ":span_asserts" ] +} + +pw_source_set("span_asserts") { + public_configs = [ ":span_asserts_config" ] + visibility = [ ":config" ] } -# This source set provides the internal span.h header included by <span>. This -# source set is only used by pw_polyfill, so its visibility is restricted. +# Provides "pw_span/span.h" and pw::span. pw_source_set("pw_span") { - remove_public_deps = [ "*" ] public_configs = [ ":public_config" ] - public_deps = [ "$dir_pw_polyfill" ] - sources = [ "public/pw_span/internal/span.h" ] - visibility = [ ":*" ] + public = [ "public/pw_span/span.h" ] + public_deps = [ ":config" ] + + # Polyfill <cstddef> (std::byte) and <iterator> (std::size(), std::data) if + # C++17 is not supported. + if (pw_toolchain_CXX_STANDARD < pw_toolchain_STANDARD.CXX17) { + public_deps += [ + "$dir_pw_polyfill:cstddef", + "$dir_pw_polyfill:iterator", + ] + } + + # Only add a dependency on pw_assert if the flag is explicitly enabled. + if (pw_span_ENABLE_ASSERTS) { + public_deps += [ "$dir_pw_assert:assert" ] + } + + sources = [ "public/pw_span/internal/span_impl.h" ] } pw_test_group("tests") { - tests = [ ":test" ] + tests = [ + ":pw_span_test", + ":compatibility_test", + ] } -pw_test("test") { - deps = [ ":pw_span" ] +pw_test("pw_span_test") { + deps = [ + ":pw_span", + dir_pw_polyfill, + ] remove_configs = [ "$dir_pw_build:extra_strict_warnings" ] sources = [ "span_test.cc" ] } +pw_test("compatibility_test") { + deps = [ + ":pw_span", + dir_pw_polyfill, + ] + sources = [ "compatibility_test.cc" ] +} + pw_doc_group("docs") { sources = [ "docs.rst" ] } |