diff --git a/build/chip/fuzz_test.gni b/build/chip/fuzz_test.gni index 3d101c21e03762..7d40a70851a222 100644 --- a/build/chip/fuzz_test.gni +++ b/build/chip/fuzz_test.gni @@ -45,17 +45,21 @@ template("chip_fuzz_target") { executable(target_name) { forward_variables_from(invoker, "*") - if (defined(public_configs)) { - public_configs += [ - "//build/config/compiler:libfuzzer_fuzzing", - "//build/config/compiler:sanitize_address", - ] + fuzz_configs = [] + if (oss_fuzz) { + fuzz_configs += [ "//build/config/compiler:oss_fuzz" ] } else { - public_configs = [ + fuzz_configs += [ "//build/config/compiler:libfuzzer_fuzzing", "//build/config/compiler:sanitize_address", ] } + + if (defined(public_configs)) { + public_configs += fuzz_configs + } else { + public_configs = fuzz_configs + } if (!defined(oubput_dir)) { output_dir = "${root_out_dir}/tests" } diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 5c2accfcdc078e..577dac76c66642 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -453,11 +453,20 @@ config("libfuzzer_fuzzing") { ldflags = cflags } +config("oss_fuzz") { + cflags = string_split(getenv("CFLAGS")) + ldflags = string_split(getenv("CXXFLAGS")) + ldflags += [ getenv("LIB_FUZZING_ENGINE") ] +} + config("fuzzing_default") { configs = [] if (is_libfuzzer) { configs += [ ":libfuzzer_fuzzing" ] } + if (oss_fuzz) { + configs += [ ":oss_fuzz" ] + } } config("coverage") { diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni index b25aa5c51ca957..5717df7fa33474 100644 --- a/build/config/compiler/compiler.gni +++ b/build/config/compiler/compiler.gni @@ -56,4 +56,7 @@ declare_args() { # Debug prefix mapping (values for -fdebug-prefix-map=). prefix_mappings = [] + + # Enable fuzzer build for OSS-Fuzz + oss_fuzz = false } diff --git a/build/config/linux/pkg_config.gni b/build/config/linux/pkg_config.gni index fb8f5aab32d703..016defafbc3617 100644 --- a/build/config/linux/pkg_config.gni +++ b/build/config/linux/pkg_config.gni @@ -125,6 +125,17 @@ template("pkg_config") { lib_dirs = pkgresult[3] } + # Link libraries statically for OSS-Fuzz fuzzer build + if (oss_fuzz) { + libs = [] + ldflags = [ "-Wl,-Bstatic" ] + foreach(lib, pkgresult[2]) { + ldflags += [ "-l$lib" ] + } + ldflags += [ "-Wl,-Bdynamic" ] + lib_dirs = pkgresult[3] + } + forward_variables_from(invoker, [ "defines",