third_party/urcu: init at 0.14.0

Adds userspace-rcu aka urcu, a userspace RCU library. Generated files
needed to be patched in and have been stripped of any unnecessary
definitions to make review easier and keep the patch small.

This is used by modern versions of xfsprogs, so we need to add it.

Change-Id: I280d313a9365fc642ca6c1cfd1d997094c0a0f98
Reviewed-on: https://review.monogon.dev/c/monogon/+/3345
Tested-by: Jenkins CI
Reviewed-by: Jan Schär <jan@monogon.tech>
diff --git a/WORKSPACE b/WORKSPACE
index 9e374ba..28b4b9b 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -44,6 +44,12 @@
     name = "util_linux",
     version = "2.36.2",
 )
+load("//third_party/urcu:external.bzl", "urcu_external")
+
+urcu_external(
+    name = "urcu",
+    version = "0.14.0",
+)
 
 load("//third_party/xfsprogs:external.bzl", "xfsprogs_external")
 
diff --git a/third_party/urcu/BUILD.bazel b/third_party/urcu/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/urcu/BUILD.bazel
diff --git a/third_party/urcu/config.h b/third_party/urcu/config.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/urcu/config.h
diff --git a/third_party/urcu/external.bzl b/third_party/urcu/external.bzl
new file mode 100644
index 0000000..df78388
--- /dev/null
+++ b/third_party/urcu/external.bzl
@@ -0,0 +1,16 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+def urcu_external(name, version):
+    sums = {
+        "0.14.0": "sha256-QvtRKaP//lpLeQ3+HqOnNMae4JX++/ZJMmJpu6lMJi0=",
+    }
+
+    http_archive(
+        name = name,
+        integrity = sums[version],
+        strip_prefix = "userspace-rcu-" + version,
+        build_file = "@//third_party/urcu:urcu.bzl",
+        patch_args = ["-p1"],
+        patches = ["//third_party/urcu/patches:generated-files.patch"],
+        urls = ["https://github.com/urcu/userspace-rcu/archive/refs/tags/v%s.tar.gz" % version],
+    )
diff --git a/third_party/urcu/patches/BUILD.bazel b/third_party/urcu/patches/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/urcu/patches/BUILD.bazel
diff --git a/third_party/urcu/patches/generated-files.patch b/third_party/urcu/patches/generated-files.patch
new file mode 100644
index 0000000..62808ae
--- /dev/null
+++ b/third_party/urcu/patches/generated-files.patch
@@ -0,0 +1,39 @@
+From 9801dd97397d77ff0dd9d7d57a4915ca604f49c2 Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@monogon.tech>
+Date: Wed, 21 Aug 2024 16:59:02 +0200
+Subject: [PATCH] Add generated configs
+
+---
+ include/config.h      | 8 ++++++++
+ include/urcu/config.h | 4 ++++
+ 2 files changed, 12 insertions(+)
+ create mode 100644 include/config.h
+ create mode 100644 include/urcu/config.h
+
+diff --git a/include/config.h b/include/config.h
+new file mode 100644
+index 0000000..9d25ae3
+--- /dev/null
++++ b/include/config.h
+@@ -0,0 +1,8 @@
++#define CONFIG_RCU_HAVE_CLOCK_GETTIME 1
++#define CONFIG_RCU_SMP 1
++#define CONFIG_RCU_TLS 1
++
++#define HAVE_SCHED_SETAFFINITY 1
++#define HAVE_GETTID 1
++#define HAVE_SCHED_GETCPU 1
++#define HAVE_SYSCONF 1
+diff --git a/include/urcu/config.h b/include/urcu/config.h
+new file mode 100644
+index 0000000..1a07402
+--- /dev/null
++++ b/include/urcu/config.h
+@@ -0,0 +1,4 @@
++#define CONFIG_RCU_SMP 1
++#define CONFIG_RCU_TLS 1
++#define CONFIG_RCU_HAVE_CLOCK_GETTIME 1
++#define CONFIG_RCU_HAVE_MULTIFLAVOR 1
+-- 
+2.44.1
+
diff --git a/third_party/urcu/urcu.bzl b/third_party/urcu/urcu.bzl
new file mode 100644
index 0000000..3dfb0f8
--- /dev/null
+++ b/third_party/urcu/urcu.bzl
@@ -0,0 +1,22 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@@//build/utils:template_file.bzl", "template_file")
+
+template_file(
+    name = "config.h",
+    src = "@@//third_party/urcu:config.h.in",
+    substitutions = { },
+)
+
+cc_library(
+    name = "urcu",
+    srcs = glob(
+        [
+            "src/*.c",
+            "src/*.h",
+        ],
+    ),
+    hdrs = glob(["include/**/*.h"]),
+    includes = ["include"],
+    local_defines = ["RCU_MEMBARRIER", "_GNU_SOURCE"],
+    visibility = ["//visibility:public"],
+)