From 9eb791c8af3280d7748e56291b9b6434526605eb Mon Sep 17 00:00:00 2001 From: Maxim Polyakov Date: Tue, 14 Feb 2023 08:27:01 +0000 Subject: [PATCH] remove include_dirs from the public config + added special target for building headers There are several problems with the current BUILD.gn 1. several folders are poisoned by wrong include paths, thus projects that includes libbpf as a dependency will have wrong kernel headers for example. It will lead to compilation errors. 2. original Makefile has a special target build_headers that copies a list of headers in a separate location that starts from bpf/ and client code also starts includes from bpf folder, for instance a normal include should look like this: #include however, in the current BUILD.gn such include will lead to a compilation error because there is no such file bpf/bpf.h (it's just bpf.h) Signed-off-by: Maxim Polyakov --- BUILD.gn | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 31a7139..16f09ed 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -13,6 +13,37 @@ import("//build/ohos.gni") import("//build/ohos/ndk/ndk.gni") + +libbpf_headers = [ + "bpf.h", + "libbpf.h", + "btf.h", + "libbpf_common.h", + "libbpf_legacy.h", + "xsk.h", + "bpf_helpers.h", + "bpf_helper_defs.h", + "bpf_tracing.h", + "bpf_endian.h", + "bpf_core_read.h", + "skel_internal.h", + "libbpf_version.h", +] + +foreach(file, libbpf_headers) { + copy("headers_{$file}") { + sources = [ "//third_party/libbpf/src/${file}" ] + outputs = [ "${target_out_dir}/bpf_headers/bpf/${file}" ] + } +} + +group("make_headers") { + deps = [] + foreach(file, libbpf_headers) { + deps += [":headers_{$file}"] + } +} + config("libbpf_config") { cflags = [ "-Wno-incompatible-pointer-types", @@ -33,13 +64,16 @@ config("libbpf_config") { "-Wno-uninitialized", ] defines = [ "HAVE_ELFIO" ] -} - -config("libbpf_public_config") { + include_dirs = [ "./src", "./include", "./include/uapi", + ] +} + +config("libbpf_public_config") { + include_dirs = [ "//third_party/zlib", "//third_party/elfio/c_wrapper", "//third_party/elfio/elfio", @@ -48,6 +82,7 @@ config("libbpf_public_config") { ohos_shared_library("libbpf") { deps = [ + ":make_headers", "//third_party/elfio:elfio", "//third_party/zlib:libz", ] -- Gitee