From e46d660d04dc534ac7d3e72d7732897c151f8615 Mon Sep 17 00:00:00 2001
From: Julio Galvan <julio@epazote.net>
Date: Tue, 16 Jul 2019 16:48:32 -0700
Subject: [PATCH 1/3] New package: libco-1.0.1

---
 common/shlibs          |  1 +
 srcpkgs/libco-devel    |  1 +
 srcpkgs/libco/template | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)
 create mode 120000 srcpkgs/libco-devel
 create mode 100644 srcpkgs/libco/template

diff --git a/common/shlibs b/common/shlibs
index 2f146bbfa9d..e7771007e21 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -3493,3 +3493,4 @@ libkres.so.9 knot-resolver-4.0.0_1
 libnsl.so.2 libnsl-1.2.0_1
 libbcc.so.0 bcc-0.10.0_1
 libbcc_bpf.so.0 bcc-0.10.0_1
+libco.so libco-1.0.1_1
diff --git a/srcpkgs/libco-devel b/srcpkgs/libco-devel
new file mode 120000
index 00000000000..9cbee396adf
--- /dev/null
+++ b/srcpkgs/libco-devel
@@ -0,0 +1 @@
+libco
\ No newline at end of file
diff --git a/srcpkgs/libco/template b/srcpkgs/libco/template
new file mode 100644
index 00000000000..0b2efc00dfb
--- /dev/null
+++ b/srcpkgs/libco/template
@@ -0,0 +1,34 @@
+# Template file for 'libco'
+pkgname=libco
+version=1.0.1
+revision=1
+short_desc="Cooperative multithreading library written in C89"
+maintainer="Julio Galvan <julio@epazote.net>"
+license="Public Domain"
+homepage="https://github.com/freeekanayaka/libco"
+distfiles="https://github.com/freeekanayaka/libco/archive/v${version}.tar.gz"
+checksum=b5a49b0352e52edffc0046b592e4414945a2b637f7433f8c526b8cdaab9d24bd
+
+do_build() {
+	sed -i 's/gcc/$(CC)/g' Makefile
+	make
+}
+
+do_install() {
+	vinstall libco.so 0664 /usr/lib/ libco.so.${version}
+	ln -s libco.so.${version} ${DESTDIR}/usr/lib/libco.so.1
+	ln -s libco.so.${version} ${DESTDIR}/usr/lib/libco.so
+	vinstall libco.pc 0664 /usr/lib/pkgconfig
+	vinstall libco.a 0664 /usr/lib/
+	vinstall libco.h 0664 /usr/include/
+}
+
+libco-devel_package() {
+	depends="libco>=${version}_${revision}"
+	short_desc+=" - development files"
+	pkg_install() {
+		vmove usr/include
+		vmove usr/lib/pkgconfig
+		vmove "usr/lib/*.a"
+	}
+}

From b80ee5ee7485e1ffc21fae6e55adf98d01ff17c6 Mon Sep 17 00:00:00 2001
From: Julio Galvan <julio@epazote.net>
Date: Tue, 16 Jul 2019 16:59:54 -0700
Subject: [PATCH 2/3] New package: raft-0.9.1

---
 common/shlibs         |  1 +
 srcpkgs/raft-devel    |  1 +
 srcpkgs/raft/template | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)
 create mode 120000 srcpkgs/raft-devel
 create mode 100644 srcpkgs/raft/template

diff --git a/common/shlibs b/common/shlibs
index e7771007e21..45d3e0f1b0f 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -3494,3 +3494,4 @@ libnsl.so.2 libnsl-1.2.0_1
 libbcc.so.0 bcc-0.10.0_1
 libbcc_bpf.so.0 bcc-0.10.0_1
 libco.so libco-1.0.1_1
+libraft.so.0 raft-0.9.1_1
diff --git a/srcpkgs/raft-devel b/srcpkgs/raft-devel
new file mode 120000
index 00000000000..d96c908578a
--- /dev/null
+++ b/srcpkgs/raft-devel
@@ -0,0 +1 @@
+raft
\ No newline at end of file
diff --git a/srcpkgs/raft/template b/srcpkgs/raft/template
new file mode 100644
index 00000000000..89b354a2e57
--- /dev/null
+++ b/srcpkgs/raft/template
@@ -0,0 +1,36 @@
+# Template file for 'raft'
+pkgname=raft
+version=0.9.2
+revision=1
+build_style=gnu-configure
+configure_args="--enable-example=no"
+hostmakedepends="pkg-config autoconf automake libtool"
+makedepends="libuv-devel"
+short_desc="C implementation of the Raft consensus protocol"
+maintainer="Julio Galvan <julio@epazote.net>"
+license="Apache-2.0"
+homepage="https://github.com/CanonicalLtd/raft"
+distfiles="https://github.com/CanonicalLtd/raft/archive/v${version}.tar.gz"
+checksum=3090b1f44fafad712af5da08358cec3354164dff6036617011198baa351b9e92
+
+pre_configure() {
+	autoreconf -i
+}
+
+pre_build() {
+	case "$XBPS_TARGET_MACHINE" in
+		# fix musl missing error.h header
+		*-musl) sed -i '/error.h/d' src/replication.c;;
+	esac
+}
+
+raft-devel_package() {
+	depends="raft>=${version}_${revision}"
+	short_desc+=" - development files"
+	pkg_install() {
+		vmove usr/include
+		vmove usr/lib/pkgconfig
+		vmove "usr/lib/*.a"
+		vmove "usr/lib/*.so"
+	}
+}

From f7c4a0546f3b556c104c735e8e016886514d5b39 Mon Sep 17 00:00:00 2001
From: Julio Galvan <julio@epazote.net>
Date: Tue, 16 Jul 2019 15:39:24 -0700
Subject: [PATCH 3/3] dqlite: update to 0.9.1

---
 srcpkgs/dqlite/template | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/srcpkgs/dqlite/template b/srcpkgs/dqlite/template
index b11c2e93bd9..1818072b1e3 100644
--- a/srcpkgs/dqlite/template
+++ b/srcpkgs/dqlite/template
@@ -1,17 +1,17 @@
 # Template file for 'dqlite'
 pkgname=dqlite
-version=0.2.6
+version=0.9.1
 revision=1
 build_style=gnu-configure
 hostmakedepends="pkg-config autoconf automake libtool"
-makedepends="libuv-devel sqlite-replication-devel"
+makedepends="libuv-devel sqlite-replication-devel raft-devel libco-devel"
 depends="sqlite-replication"
 short_desc="Distributed SQLite database using the Raft algorithm"
 maintainer="Cameron Nemo <camerontnorman@gmail.com>"
 license="Apache-2.0"
 homepage="https://github.com/CanonicalLtd/dqlite"
 distfiles="${homepage}/archive/v${version}.tar.gz"
-checksum=47d31550d970a12d25101c331896cfb855128c110d912f5da3371062d9ece52b
+checksum=0d3f96343b1a0d5c2b717402c3a9f99b96452439af838cd64f6e07ae6899ef7b
 
 pre_configure() {
 	autoreconf -i
