SOONG: BPF: add libbpf_prog soong module

This commit adds the libbpf_prog soong module which is heavily based on
the bpf soong module. Due to issues encountered and concerns around
compatibility and testability of mainlined bpf modules, support for
libbpf is added as a separate module.

Specifically, when changing the bpf module from
InitAndroidArchModule(... android.MultilibCommon) to MultilibFirst, the
soong apex bpfs functionality breaks. We have not identified a good
mechanism to fix this, and as we would then be creating architecture
specific bpf program binarys, additional testing and infrastructure
would be required.

It should be noted that libbpf_prog should not be used for features
which target 32bit kernel architectures at this point, as we do not
have a mechanism to identify the kernel arch at build time. I.E. 32bit
userspace could be on either 32bit or 64bit kernel arch, and we require
arch specific includes (vmlinux.h). Therefore, we default to 32bit
userspace on 64bit kernel to match the precedence set with the legacy
bpf programs.

Example use:
libbpf_prog {
    name: "xyz.o",
    srcs: ["xyz.c"],
    arch: {
        arm: {
            local_include_dirs: ["vmlinux/arm64"],
        },
        arm64: {
            local_include_dirs: ["vmlinux/arm64"],
        },
        x86: {
            local_include_dirs: ["vmlinux/x86_64"],
        },
        x86_64: {
            local_include_dirs: ["vmlinux/x86_64"],
        },
    },
}

Bug: 359646531
Test: manual
Change-Id: Ie58515d70abee061470cf4bb803228e00d496ac3
Signed-off-by: Neill Kapron <nkapron@google.com>
diff --git a/bpf/libbpf/libbpf_prog_test.go b/bpf/libbpf/libbpf_prog_test.go
new file mode 100644
index 0000000..f4f5167
--- /dev/null
+++ b/bpf/libbpf/libbpf_prog_test.go
@@ -0,0 +1,69 @@
+// Copyright 2024 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package libbpf_prog
+
+import (
+	"os"
+	"testing"
+
+	"android/soong/android"
+	"android/soong/cc"
+)
+
+func TestMain(m *testing.M) {
+	os.Exit(m.Run())
+}
+
+var prepareForLibbpfProgTest = android.GroupFixturePreparers(
+	cc.PrepareForTestWithCcDefaultModules,
+	android.FixtureMergeMockFs(
+		map[string][]byte{
+			"bpf.c":              nil,
+			"bpf_invalid_name.c": nil,
+			"BpfTest.cpp":        nil,
+		},
+	),
+	PrepareForTestWithLibbpfProg,
+)
+
+func TestLibbpfProgDataDependency(t *testing.T) {
+	bp := `
+		libbpf_prog {
+			name: "bpf.o",
+			srcs: ["bpf.c"],
+		}
+
+		cc_test {
+			name: "vts_test_binary_bpf_module",
+			srcs: ["BpfTest.cpp"],
+			data: [":bpf.o"],
+			gtest: false,
+		}
+	`
+
+	prepareForLibbpfProgTest.RunTestWithBp(t, bp)
+}
+
+func TestLibbpfProgSourceName(t *testing.T) {
+	bp := `
+		libbpf_prog {
+			name: "bpf_invalid_name.o",
+			srcs: ["bpf_invalid_name.c"],
+		}
+	`
+	prepareForLibbpfProgTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
+		`invalid character '_' in source name`)).
+		RunTestWithBp(t, bp)
+}