treewide: setup libelf build

Change-Id: I42ead2eac3be455015a302f947dfcc311057e46e
Reviewed-on: https://review.monogon.dev/c/monogon/+/4097
Tested-by: Jenkins CI
Reviewed-by: Jan Schär <jan@monogon.tech>
diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel
index 80b8cfb..7a1c6c1 100644
--- a/third_party/BUILD.bazel
+++ b/third_party/BUILD.bazel
@@ -24,3 +24,9 @@
     actual = "@zlib",
     visibility = ["//visibility:public"],
 )
+
+alias(
+    name = "zstd",
+    actual = "@zstd//:zstd",
+    visibility = ["//visibility:public"],
+)
diff --git a/third_party/libelf/BUILD.bazel b/third_party/libelf/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/libelf/BUILD.bazel
diff --git a/third_party/libelf/libelf.bzl b/third_party/libelf/libelf.bzl
new file mode 100644
index 0000000..179630f
--- /dev/null
+++ b/third_party/libelf/libelf.bzl
@@ -0,0 +1,27 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+filegroup(
+    name = "all",
+    srcs = glob(["**/*"]),
+    visibility = ["//visibility:public"],
+)
+
+cc_library(
+    name = "elf",
+    srcs = glob(["src/*.c", "src/*.h"]),
+    hdrs = glob(["include/*.h"]),
+    textual_hdrs = glob(["src/*.c"]),
+    copts = [
+        "-I{path}/include".format(path = package_relative_label(":all").workspace_root),
+        "-I{path}/src".format(path = package_relative_label(":all").workspace_root),
+    ],
+    local_defines = [
+        "HAVE_CONFIG_H",
+    ],
+    linkstatic = True,
+    deps = [
+        "@zlib//:zlib",
+        "@zstd//:zstd",
+    ],
+    visibility = ["//visibility:public"],
+)