Skip to content

Commit

Permalink
Add GLib-2.75.1 (needed because issue #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliusSutkus89 committed Dec 23, 2023
1 parent 85fbfbe commit dd46905
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 51 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Libraries built with different NDK versions should not be used in the same appli

#### [GLib](https://gitlab.gnome.org/GNOME/glib/)

Released versions 2.78.1 and 2.78.3 are problematic (issue #20).
Usable version is 2.75.1

[![glib2](https://github.com/ViliusSutkus89/ndkports/actions/workflows/glib2.yml/badge.svg)](https://github.com/ViliusSutkus89/ndkports/actions/workflows/glib2.yml)
[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/glib2-ndk25-static.svg?label=Maven%20Central%20glib2-ndk25-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:glib2-ndk25-static)
[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/glib2-ndk25-shared.svg?label=Maven%20Central%20glib2-ndk25-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:glib2-ndk25-shared)
Expand Down
92 changes: 41 additions & 51 deletions glib2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import com.android.ndkports.CMakeCompatibleVersion
import com.android.ndkports.PrefabSysrootPlugin
import org.gradle.jvm.tasks.Jar

val portVersion = "2.78.3"
val portVersion = "2.75.1"

group = rootProject.group
version = "${portVersion}-beta-2"
version = "${portVersion}-beta-1"

plugins {
id("maven-publish")
Expand All @@ -33,55 +33,47 @@ tasks.prefab {
generator.set(PrefabSysrootPlugin::class.java)
}

tasks.extractSrc {
doLast {
val srcDir = outDir.get().asFile
fun File.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): File {
writeText(readText().replace(oldValue, newValue, ignoreCase))
return this
}

// Make sure not to build proxy-libintl subproject, it's already used as regular dependency
srcDir.resolve("subprojects/proxy-libintl.wrap").delete()
fun File.patch(patch: String) {
patch(projectDir.resolve("patches/$portVersion").resolve(patch))
}

srcDir.resolve("glib/meson.build").apply {
writeText(
readText().replace(
"libraries : [libintl_deps],",
"libraries : [libintl_deps, libffi_dep],",
)
)
}
fun File.patch(patch: File) {
val pb = ProcessBuilder(
if (isFile) listOf("patch", "-p0", absolutePath)
else listOf("patch", "-p0")
)

val minSdkVersion = rootProject.extra.get("minSdkSupportedByNdk").toString().toInt()
if (minSdkVersion < 21) {
// usr/include/sys/epoll.h:
// int epoll_create(int __size);
// #if __ANDROID_API__ >= 21
// int epoll_create1(int __flags) __INTRODUCED_IN(21);
// #endif /* __ANDROID_API__ >= 21 */
if (isDirectory)
pb.directory(absoluteFile)

// Patch inspired by (taken from):
// https://github.com/deltachat/deltachat-android/pull/2324
// fcntl only if epoll created successfully
srcDir.resolve("gio/giounix-private.c").let {
it.writeText(it.readText().replace(
"#include <sys/epoll.h>",
"""
#include <sys/epoll.h>
#if __ANDROID_API__ < 21
#include <fcntl.h>
#define EPOLL_CLOEXEC O_CLOEXEC
static int epoll_create1(int flags) {
int fd = epoll_create(1);
if (-1 != fd && flags & O_CLOEXEC) {
int f = fcntl(fd, F_GETFD);
fcntl(fd, F_SETFD, f | FD_CLOEXEC);
}
return fd;
}
#endif
val process = pb.start()
process.outputStream.writer().use {
it.write(patch.readText())
}
process.errorStream.bufferedReader().use {
println(it.readText())
}
process.inputStream.bufferedReader().use {
println(it.readText())
}
if (process.waitFor() != 0) {
throw RuntimeException("Patch failed!\n")
}
}

""".trimIndent()
))
}
}
tasks.extractSrc {
doLast {
val srcDir = outDir.get().asFile
// Make sure not to build proxy-libintl subproject, it's already used as regular dependency
srcDir.resolve("subprojects/proxy-libintl.wrap").delete()
srcDir.resolve("glib/meson.build").patch("libffi-pkgconfig-pc.patch")
srcDir.resolve("gio/giounix-private.c").patch("epoll_create1.patch")
srcDir.resolve("meson.build").patch("ngettext.patch")
}
}

Expand Down Expand Up @@ -111,11 +103,8 @@ tasks.register<MesonPortTask>("buildPort") {
}
}

iDir.resolve("lib/pkgconfig/glib-2.0.pc").let {
it.writeText(it.readText()
.replace("-I\${libdir}/glib-2.0/include", "")
)
}
iDir.resolve("lib/pkgconfig/glib-2.0.pc")
.replace("-I\${libdir}/glib-2.0/include", "")
}
}
}
Expand Down Expand Up @@ -188,6 +177,7 @@ tasks.prefabPackage {
val packageSources = tasks.register<Jar>("packageSources") {
archiveClassifier.set("sources")
from(projectDir.resolve("build.gradle.kts"))
from(projectDir.resolve("patches/$portVersion"))
from(ndkPorts.source)
}

Expand Down
Binary file added glib2/glib-2.75.1.tar.xz
Binary file not shown.
25 changes: 25 additions & 0 deletions glib2/patches/2.75.1/epoll_create1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- gio/giounix-private.c
+++ gio/giounix-private.c
@@ -25,6 +25,22 @@
#include <sys/types.h>
#if defined (HAVE_EPOLL_CREATE)
#include <sys/epoll.h>
+#if __ANDROID_API__ < 21
+// Patch inspired by (taken from):
+// https://github.com/deltachat/deltachat-android/pull/2324
+// fcntl only if epoll created successfully
+#include <fcntl.h>
+#define EPOLL_CLOEXEC O_CLOEXEC
+static int epoll_create1(int flags) {
+ int fd = epoll_create(1);
+ if (-1 != fd && flags & O_CLOEXEC) {
+ int f = fcntl(fd, F_GETFD);
+ fcntl(fd, F_SETFD, f | FD_CLOEXEC);
+ }
+ return fd;
+}
+#endif
+
#elif defined (HAVE_KQUEUE)
#include <sys/event.h>
#include <sys/time.h>
11 changes: 11 additions & 0 deletions glib2/patches/2.75.1/libffi-pkgconfig-pc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- glib/meson.build
+++ glib/meson.build 2023-12-23 17:41:36.158000000 +0200
@@ -434,7 +434,7 @@
include_directories : [configinc, glibinc])

pkg.generate(libglib,
- libraries : [libintl_deps],
+ libraries : [libintl_deps, libffi_dep],
libraries_private : [win32_ldflags],
subdirs : ['glib-2.0'],
extra_cflags : ['-I${libdir}/glib-2.0/include'] + win32_cflags,
11 changes: 11 additions & 0 deletions glib2/patches/2.75.1/ngettext.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- meson.build
+++ meson.build 2023-12-22 23:24:51.020000000 +0200.txt
@@ -2097,7 +2097,7 @@
#
# Meson's builtin dependency lookup as of 0.60.0 doesn't check for
# pthread, so we do this manually here.
- if cc.has_function('ngettext', dependencies : libintl)
+ if cc.has_function('ngettext', dependencies : libintl, prefix : '#include <libintl.h>')
libintl_deps += [libintl]
else
libintl_pthread = cc.find_library('pthread', required : false)

0 comments on commit dd46905

Please sign in to comment.