1# Copyright 2020 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16import("$dir_pigweed/targets/host/target_toolchains.gni") 17import("$dir_pw_toolchain/generate_toolchain.gni") 18 19config("common_config") { 20 include_dirs = [ "//include" ] 21 22 # No language extensions, to promote portability. 23 cflags_c = [ 24 "-Wvla", 25 "-std=c99", 26 "-pedantic", 27 ] 28 29 # Modern C++ for test and tooling. 30 cflags_cc = [ "-std=c++20" ] 31} 32 33config("enable_sanitizers") { 34 filter_path = rebase_path("sanitize_filter.txt", root_build_dir) 35 cflags = [ 36 "-fsanitize=address,undefined,integer", 37 "-fsanitize-blacklist=$filter_path", # inclusive-language: ignore 38 ] 39 ldflags = cflags 40 inputs = [ "sanitize_filter.txt" ] 41} 42 43config("enable_fuzzer") { 44 cflags = [ 45 "-fsanitize=fuzzer", 46 "-O1", 47 "-fno-omit-frame-pointer", 48 "-fno-optimize-sibling-calls", 49 ] 50 ldflags = cflags 51} 52 53# Define a scope for each toolchain that can be fed into generate_toolchain. 54_host_debug = { 55 # Use Pigweed's host_clang_debug toolchain as a base. 56 _toolchain_base = pw_target_toolchain_host.clang_debug 57 58 # Forward everything except the defaults scope from that toolchain. 59 forward_variables_from(_toolchain_base, "*", [ "defaults" ]) 60 61 defaults = { 62 # Forward everything from the base toolchain's defaults. 63 forward_variables_from(_toolchain_base.defaults, "*") 64 65 # Extend with custom build arguments for the target. 66 default_configs += [ 67 "//toolchains:common_config", 68 "//toolchains:enable_sanitizers", 69 ] 70 } 71} 72 73_host_fuzz = { 74 # Use Pigweed's host_clang_debug toolchain as a base. 75 _toolchain_base = pw_target_toolchain_host.clang_debug 76 77 # Forward everything except the defaults scope from that toolchain. 78 forward_variables_from(_toolchain_base, "*", [ "defaults" ]) 79 80 defaults = { 81 # Forward everything from the base toolchain's defaults. 82 forward_variables_from(_toolchain_base.defaults, "*") 83 84 # Extend with custom build arguments for the target. 85 default_configs += [ 86 "//toolchains:common_config", 87 "//toolchains:enable_sanitizers", 88 "//toolchains:enable_fuzzer", 89 ] 90 } 91} 92 93_host_optimized = { 94 # Use Pigweed's host_clang_size_optimized toolchain as a base. 95 _toolchain_base = pw_target_toolchain_host.clang_size_optimized 96 97 # Forward everything except the defaults scope from that toolchain. 98 forward_variables_from(_toolchain_base, "*", [ "defaults" ]) 99 100 defaults = { 101 # Forward everything from the base toolchain's defaults. 102 forward_variables_from(_toolchain_base.defaults, "*") 103 104 # Extend with custom build arguments for the target. 105 default_configs += [ "//toolchains:common_config" ] 106 } 107} 108 109# Create the actual GN toolchains. 110generate_toolchain("host_debug") { 111 forward_variables_from(_host_debug, "*") 112} 113 114generate_toolchain("host_fuzz") { 115 forward_variables_from(_host_fuzz, "*") 116} 117 118generate_toolchain("host_optimized") { 119 forward_variables_from(_host_optimized, "*") 120} 121