|
| 1 | +# Copyright (c) 2024 Project CHIP Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import("//build_overrides/build.gni") |
| 16 | +import("//build_overrides/pigweed.gni") |
| 17 | + |
| 18 | +import("$dir_pigweed/targets/host/target_toolchains.gni") |
| 19 | +import("${build_root}/toolchain/gcc_toolchain.gni") |
| 20 | + |
| 21 | +# creating a secondary toolchain to be used with pw_fuzzer FuzzTests |
| 22 | +# This toolchain is downstreamed from pigweed's pw_target_toolchain_host.clang_fuzz |
| 23 | +# it allows us to specifically use googletest for fuzzing (instead of the lighter version of googletest used for unit testing) |
| 24 | + |
| 25 | +gcc_toolchain("chip_pw_fuzztest") { |
| 26 | + forward_variables_from(pw_target_toolchain_host.clang_fuzz, "*", [ "name" ]) |
| 27 | + |
| 28 | + toolchain_args = { |
| 29 | + # This is needed to have the defaults passed from pw_target_toolchain_host.clang_fuzz to the current scope |
| 30 | + forward_variables_from(defaults, "*") |
| 31 | + |
| 32 | + pw_unit_test_MAIN = "$dir_pw_fuzzer:fuzztest_main" |
| 33 | + pw_unit_test_BACKEND = "$dir_pw_fuzzer:gtest" |
| 34 | + |
| 35 | + # The next three lines are needed by the gcc_toolchain template |
| 36 | + current_os = host_os |
| 37 | + current_cpu = host_cpu |
| 38 | + is_clang = true |
| 39 | + |
| 40 | + # the upstream pigweed host_clang toolchain defines a default sysroot, which results in build errors |
| 41 | + # since it does not include SSL lib and is supposed to be minimal by design. |
| 42 | + # by removing this default config, we will use the system's libs. Otherwise we can define our own sysroot. |
| 43 | + # discussion on: https://discord.com/channels/691686718377558037/1275092695764959232 |
| 44 | + remove_default_configs = [ "$dir_pw_toolchain/host_clang:linux_sysroot" ] |
| 45 | + |
| 46 | + # when is_debug = true, we pass -O0 to cflags and ldflags, while upstream pw_fuzzer toolchain defines "optimize_speed" config that passes -O2. |
| 47 | + # This condition was added to prevent mixing the flags |
| 48 | + if (is_debug) { |
| 49 | + remove_default_configs += [ "$dir_pw_build:optimize_speed" ] |
| 50 | + } |
| 51 | + |
| 52 | + # removing pigweed downstreamed configs related to warnings |
| 53 | + # These are triggering an error related to -Wcast-qual in third_party/nlio |
| 54 | + remove_default_configs += [ |
| 55 | + "$dir_pw_build:strict_warnings", |
| 56 | + "$dir_pw_build:extra_strict_warnings", |
| 57 | + ] |
| 58 | + |
| 59 | + # the third_party abseil-cpp triggers warnings related to [-Wformat-nonliteral] |
| 60 | + treat_warnings_as_errors = false |
| 61 | + |
| 62 | + dir_pw_third_party_abseil_cpp = "//third_party/abseil-cpp/src" |
| 63 | + dir_pw_third_party_fuzztest = "//third_party/fuzztest" |
| 64 | + dir_pw_third_party_googletest = "//third_party/googletest" |
| 65 | + |
| 66 | + # TODO: Seems that re2 support within FuzzTest was deprecated, keeping it defined is triggering warning |
| 67 | + # Remove if re2 is indeed not needed |
| 68 | + # dir_pw_third_party_re2 = "//third_party/re2/src" |
| 69 | + } |
| 70 | +} |
0 commit comments