| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/go/go_binary.gni") |
| import("//build/go/go_library.gni") |
| import("//build/package.gni") |
| |
| declare_args() { |
| # Used by syz-ci to build with own syz-executor source. |
| syzkaller_dir = "//third_party/syzkaller" |
| } |
| |
| group("syzkaller") { |
| testonly = true |
| deps = [ ":tests" ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ ":syz-executor-pkg" ] |
| } |
| |
| package("syz-executor-pkg") { |
| deps = [ ":syz-executor" ] |
| binaries = [ |
| { |
| name = "syz-executor" |
| shell = true |
| }, |
| ] |
| } |
| |
| src = rebase_path(syzkaller_dir) |
| |
| if (target_cpu == "x64") { |
| GOARCH = "amd64" |
| } else { |
| GOARCH = target_cpu |
| } |
| |
| GOOS = "fuchsia" |
| HOSTGOOS = "linux" |
| |
| # Like "git rev-parse HEAD", but without needing a Python script wrapper. |
| GIT_REVISION = read_file("${src}/.git/HEAD", "trim string") |
| GIT_BRANCH = string_replace(GIT_REVISION, "ref: ", "", 1) |
| if (GIT_BRANCH != GIT_REVISION) { |
| GIT_REVISION = read_file("${src}/.git/${GIT_BRANCH}", "trim string") |
| } |
| |
| executable("syz-executor") { |
| sources = [ |
| "${src}/executor/common.h", |
| "${src}/executor/common_akaros.h", |
| "${src}/executor/common_bsd.h", |
| "${src}/executor/common_fuchsia.h", |
| "${src}/executor/common_kvm_amd64.h", |
| "${src}/executor/common_kvm_arm64.h", |
| "${src}/executor/common_linux.h", |
| "${src}/executor/common_test.h", |
| "${src}/executor/common_usb.h", |
| "${src}/executor/common_windows.h", |
| "${src}/executor/executor.cc", |
| "${src}/executor/executor_akaros.h", |
| "${src}/executor/executor_bsd.h", |
| "${src}/executor/executor_fuchsia.h", |
| "${src}/executor/executor_linux.h", |
| "${src}/executor/executor_test.h", |
| "${src}/executor/executor_windows.h", |
| "${src}/executor/kvm.S.h", |
| "${src}/executor/kvm.h", |
| "${src}/executor/nocover.h", |
| "${src}/executor/test.h", |
| "${src}/executor/test_linux.h", |
| ] |
| cflags = [ |
| "-DGOOS_${GOOS}=1", |
| "-DGOARCH_${GOARCH}=1", |
| "-DHOSTGOOS_${HOSTGOOS}=1", |
| "-DGIT_REVISION=\"${GIT_REVISION}\"", |
| |
| # TODO(mdempsky): How do we avoid hard-coding this path? |
| "-Ihost_x64/gen/src/testing/fuzzing/syzkaller/sysgen/executor", |
| ] |
| configs -= [ "//build/config:default_warnings" ] |
| configs += [ ":warnings" ] |
| deps = [ |
| ":run-sysgen($host_toolchain)", |
| "//sdk/lib/fdio", |
| "//src/devices/lib/driver", |
| "//src/lib/ddk", |
| ] |
| } |
| |
| # Match the warnings enabled for Fuchsia builds in syzkaller/sys/targets/targets.go. |
| config("warnings") { |
| cflags = [ |
| "-Wall", |
| "-Werror", |
| "-Wparentheses", |
| "-Wunused-const-variable", |
| "-Wframe-larger-than=16384", |
| "-Wunused-const-variable", |
| "-Wno-deprecated", |
| ] |
| } |
| |
| if (is_host) { |
| go_library("syzkaller-go") { |
| name = "github.com/google/syzkaller/..." |
| source_dir = syzkaller_dir |
| allow_globbing = true |
| } |
| |
| syz_ldflags = [ |
| "-s", |
| "-w", |
| "-X github.com/google/syzkaller/sys.GitRevision=${GIT_REVISION}", |
| "-X 'github.com/google/syzkaller/sys.gitRevisionDate=Sun Jan 10 11:00:00 1970 -0700'", |
| ] |
| |
| go_binary("syz-sysgen") { |
| gopackage = "github.com/google/syzkaller/sys/syz-sysgen" |
| ldflags = syz_ldflags |
| deps = [ ":syzkaller-go" ] |
| } |
| |
| action("run-sysgen") { |
| script = "run-sysgen.sh" |
| args = [ |
| rebase_path("$root_out_dir/syz-sysgen", root_build_dir), |
| "--src", |
| src, |
| "--out", |
| rebase_path("$target_gen_dir/sysgen", root_build_dir), |
| ] |
| outputs = [ |
| "$target_gen_dir/sysgen/executor/defs.h", |
| "$target_gen_dir/sysgen/executor/syscalls.h", |
| ] |
| deps = [ ":syz-sysgen" ] |
| } |
| } |