1# Copyright 2014 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//testing/libfuzzer/fuzzer_test.gni") 6 7if (is_win) { 8 import("//build/config/win/visual_studio_version.gni") 9} 10 11config("brotli_defines") { 12 # By default, brotli depends on undefined behavior, but setting 13 # BROTLI_BUILD_PORTABLE should result in a build which does not. 14 if (is_ubsan) { 15 defines = [ "BROTLI_BUILD_PORTABLE" ] 16 } 17} 18 19config("includes") { 20 include_dirs = [ "include" ] 21} 22 23source_set("headers") { 24 sources = [ 25 "include/brotli/decode.h", 26 "include/brotli/encode.h", 27 "include/brotli/port.h", 28 "include/brotli/types.h", 29 ] 30} 31 32common_sources = [ 33 "common/constants.c", 34 "common/constants.h", 35 "common/context.c", 36 "common/context.h", 37 "common/dictionary.c", 38 "common/dictionary.h", 39 "common/platform.c", 40 "common/platform.h", 41 "common/shared_dictionary.c", 42 "common/shared_dictionary_internal.h", 43 "common/transform.c", 44 "common/transform.h", 45 "common/version.h", 46] 47 48static_library("common") { 49 sources = common_sources 50 public_configs = [ ":includes" ] 51 configs += [ ":brotli_defines" ] 52 deps = [ ":headers" ] 53} 54 55static_library("common_no_dictionary_data") { 56 sources = common_sources 57 public_configs = [ ":includes" ] 58 configs += [ ":brotli_defines" ] 59 deps = [ ":headers" ] 60 defines = [ "BROTLI_EXTERNAL_DICTIONARY_DATA" ] 61} 62 63dec_sources = [ 64 "dec/bit_reader.c", 65 "dec/bit_reader.h", 66 "dec/decode.c", 67 "dec/huffman.c", 68 "dec/huffman.h", 69 "dec/prefix.h", 70 "dec/state.c", 71 "dec/state.h", 72] 73 74enc_sources = [ 75 "enc/backward_references_hq.c", 76 "enc/backward_references_hq.h", 77 "enc/backward_references_inc.h", 78 "enc/backward_references.c", 79 "enc/backward_references.h", 80 "enc/bit_cost_inc.h", 81 "enc/bit_cost.c", 82 "enc/bit_cost.h", 83 "enc/block_encoder_inc.h", 84 "enc/block_splitter_inc.h", 85 "enc/block_splitter.c", 86 "enc/block_splitter.h", 87 "enc/brotli_bit_stream.c", 88 "enc/brotli_bit_stream.h", 89 "enc/cluster_inc.h", 90 "enc/cluster.c", 91 "enc/cluster.h", 92 "enc/command.c", 93 "enc/command.h", 94 "enc/compound_dictionary.c", 95 "enc/compound_dictionary.h", 96 "enc/compress_fragment_two_pass.c", 97 "enc/compress_fragment_two_pass.h", 98 "enc/compress_fragment.c", 99 "enc/compress_fragment.h", 100 "enc/dictionary_hash.c", 101 "enc/dictionary_hash.h", 102 "enc/encode.c", 103 "enc/encoder_dict.c", 104 "enc/encoder_dict.h", 105 "enc/entropy_encode_static.h", 106 "enc/entropy_encode.c", 107 "enc/entropy_encode.h", 108 "enc/fast_log.c", 109 "enc/fast_log.h", 110 "enc/find_match_length.h", 111 "enc/hash_composite_inc.h", 112 "enc/hash_forgetful_chain_inc.h", 113 "enc/hash_longest_match_inc.h", 114 "enc/hash_longest_match_quickly_inc.h", 115 "enc/hash_longest_match64_inc.h", 116 "enc/hash_rolling_inc.h", 117 "enc/hash_to_binary_tree_inc.h", 118 "enc/hash.h", 119 "enc/histogram_inc.h", 120 "enc/histogram.c", 121 "enc/histogram.h", 122 "enc/literal_cost.c", 123 "enc/literal_cost.h", 124 "enc/memory.c", 125 "enc/memory.h", 126 "enc/metablock_inc.h", 127 "enc/metablock.c", 128 "enc/metablock.h", 129 "enc/params.h", 130 "enc/prefix.h", 131 "enc/quality.h", 132 "enc/ringbuffer.h", 133 "enc/static_dict_lut.h", 134 "enc/static_dict.c", 135 "enc/static_dict.h", 136 "enc/utf8_util.c", 137 "enc/utf8_util.h", 138 "enc/write_bits.h", 139] 140 141static_library("dec") { 142 sources = dec_sources 143 public_configs = [ ":includes" ] 144 configs += [ ":brotli_defines" ] 145 public_deps = [ ":headers" ] 146 deps = [ ":common" ] 147 148 configs -= [ "//build/config/compiler:chromium_code" ] 149 configs += [ "//build/config/compiler:no_chromium_code" ] 150 151 # Since we never debug brotli, freeze the optimizations to -O2. 152 configs -= [ "//build/config/compiler:default_optimization" ] 153 configs += [ "//build/config/compiler:optimize_max" ] 154} 155 156static_library("dec_no_dictionary_data") { 157 sources = dec_sources 158 public_configs = [ ":includes" ] 159 configs += [ ":brotli_defines" ] 160 public_deps = [ ":headers" ] 161 deps = [ ":common_no_dictionary_data" ] 162 163 configs -= [ "//build/config/compiler:chromium_code" ] 164 configs += [ "//build/config/compiler:no_chromium_code" ] 165 166 # Since we never debug brotli, freeze the optimizations to -O2. 167 configs -= [ "//build/config/compiler:default_optimization" ] 168 configs += [ "//build/config/compiler:optimize_max" ] 169} 170 171static_library("enc") { 172 sources = enc_sources 173 public_configs = [ ":includes" ] 174 configs += [ ":brotli_defines" ] 175 public_deps = [ ":headers" ] 176 deps = [ ":common" ] 177 178 configs -= [ "//build/config/compiler:chromium_code" ] 179 configs += [ "//build/config/compiler:no_chromium_code" ] 180 181 # Since we never debug brotli, freeze the optimizations to -O2. 182 configs -= [ "//build/config/compiler:default_optimization" ] 183 configs += [ "//build/config/compiler:optimize_max" ] 184} 185 186if (current_toolchain == host_toolchain) { 187 executable("brotli") { 188 sources = [ "tools/brotli.c" ] 189 public_configs = [ ":includes" ] 190 configs += [ ":brotli_defines" ] 191 192 deps = [ 193 ":common", 194 ":dec", 195 ":enc", 196 ":headers", 197 "//build/win:default_exe_manifest", 198 ] 199 200 if (is_win && visual_studio_version == "2015") { 201 # Disabling "result of 32-bit shift implicitly converted to 64 bits", 202 # caused by code like: foo |= (1 << i); // warning 4334 203 cflags = [ "/wd4334" ] 204 } 205 206 # Always build release since this is a build tool. 207 if (is_debug) { 208 configs -= [ "//build/config:debug" ] 209 configs += [ "//build/config:release" ] 210 } 211 } 212} 213 214fuzzer_test("brotli_fuzzer") { 215 sources = [ "fuzz/decode_fuzzer.c" ] 216 deps = [ ":dec" ] 217 libfuzzer_options = [ "max_len=1280" ] 218} 219