Skip to content

Commit

Permalink
C++20 toolchain
Browse files Browse the repository at this point in the history
- Define the pw_strict_host_clang_size_optimized_cpp20 toolchain that
  compiles with C++20.
- Create the cpp20_compatibility group and add it to the
  gn_full_build_check presubmit check.

Bug: 683
Change-Id: I732fb65b0588b2a84899e817015c438edf68d72e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/96442
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
  • Loading branch information
255 authored and CQ Bot Account committed Jun 2, 2022
1 parent d4163d4 commit 75a269c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
13 changes: 12 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ group("cpp14_compatibility") {
]
}

# Build Pigweed with -std=c++20 to ensure compatibility. Compile with
# optimizations since the compiler tends to catch more errors with optimizations
# enabled than without.
group("cpp20_compatibility") {
_cpp20_tc = "$_internal_toolchains:pw_strict_host_clang_size_optimized_cpp20"
deps = [
":apps($_cpp20_tc)",
":pw_module_tests.run($_cpp20_tc)",
]
}

# The default toolchain is not used for compiling C/C++ code.
if (current_toolchain != default_toolchain) {
group("apps") {
Expand All @@ -335,7 +346,7 @@ if (current_toolchain != default_toolchain) {
}
}

# All Pigweed modules that can be built using gn. This is not built by default.
# All Pigweed modules that can be built using gn. Not built by default.
group("pw_modules") {
deps = pw_modules
}
Expand Down
7 changes: 7 additions & 0 deletions pw_build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ config("cpp17") {
]
}

config("cpp20") {
cflags_cc = [
"-std=c++20",
"-Wno-register",
]
}

# Removes system-dependent prefixes from macros like __FILE__ and debug symbols.
config("relative_paths") {
_transformations = [
Expand Down
3 changes: 2 additions & 1 deletion pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def gn_full_build_check(ctx: PresubmitContext) -> None:
'pw_env_setup:build_pigweed_python_source_tree',
]

# TODO(b/234645359): Re-enable on Windows when cpp14_compatibility builds.
# TODO(b/234645359): Re-enable on Windows when compatibility tests build.
if sys.platform != 'win32':
build_targets.append('cpp14_compatibility')
build_targets.append('cpp20_compatibility')

build.gn_gen(ctx.root, ctx.output_dir)
build.ninja(ctx.output_dir, *build_targets)
Expand Down
14 changes: 9 additions & 5 deletions targets/host/target_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ downstream projects.

Toolchains for other C++ standards
==================================
Pigweed code requires C++17. A few modules, such as ``pw_tokenizer``, work with
C++14. To facilitate testing these modules with C++14, Pigweed uses the
``pw_strict_host_clang_debug_cpp14`` toolchain. This toolchain is only permitted
for use in upstream pigweed, but downstream users may create a similar toolchain
if needed.
Most Pigweed code requires C++17, but a few modules, such as ``pw_tokenizer``,
work with C++14. All Pigweed code is compatible with C++20. Pigweed defines
toolchains for testing with C++14 and C++20.

* ``pw_strict_host_clang_debug_cpp14`` -- Builds with ``-std=c++14``.
* ``pw_strict_host_clang_size_optimized_cpp20`` -- Builds with ``-std=c++20``.

These toolchains are only permitted for use in upstream pigweed, but downstream
users may create similar toolchains as needed.

--------
Building
Expand Down
15 changes: 15 additions & 0 deletions targets/host/target_toolchains.gni
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,19 @@ pw_internal_host_toolchains = [
pw_unit_test_MAIN = "$dir_pw_unit_test:printf_main"
}
},
{
name = "pw_strict_host_clang_size_optimized_cpp20"
_toolchain_base = pw_toolchain_host_clang.size_optimized
forward_variables_from(_toolchain_base, "*", _excluded_members)
defaults = {
forward_variables_from(_toolchain_base.defaults, "*")
forward_variables_from(_host_common, "*")
forward_variables_from(_pigweed_internal, "*")
forward_variables_from(_os_specific_config, "*")

remove_default_configs = [ "$dir_pw_build:cpp17" ]
default_configs += _clang_default_configs
default_configs += [ "$dir_pw_build:cpp20" ]
}
},
]

0 comments on commit 75a269c

Please sign in to comment.