diff --git a/README.md b/README.md index e07afeb..1acadb7 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/glib2/build.gradle.kts b/glib2/build.gradle.kts index 660302a..7a82b4e 100644 --- a/glib2/build.gradle.kts +++ b/glib2/build.gradle.kts @@ -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") @@ -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 ", - """ - #include - #if __ANDROID_API__ < 21 - #include - #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") } } @@ -111,11 +103,8 @@ tasks.register("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", "") } } } @@ -188,6 +177,7 @@ tasks.prefabPackage { val packageSources = tasks.register("packageSources") { archiveClassifier.set("sources") from(projectDir.resolve("build.gradle.kts")) + from(projectDir.resolve("patches/$portVersion")) from(ndkPorts.source) } diff --git a/glib2/glib-2.75.1.tar.xz b/glib2/glib-2.75.1.tar.xz new file mode 100644 index 0000000..48a9450 Binary files /dev/null and b/glib2/glib-2.75.1.tar.xz differ diff --git a/glib2/patches/2.75.1/epoll_create1.patch b/glib2/patches/2.75.1/epoll_create1.patch new file mode 100644 index 0000000..609f612 --- /dev/null +++ b/glib2/patches/2.75.1/epoll_create1.patch @@ -0,0 +1,25 @@ +--- gio/giounix-private.c ++++ gio/giounix-private.c +@@ -25,6 +25,22 @@ + #include + #if defined (HAVE_EPOLL_CREATE) + #include ++#if __ANDROID_API__ < 21 ++// Patch inspired by (taken from): ++// https://github.com/deltachat/deltachat-android/pull/2324 ++// fcntl only if epoll created successfully ++#include ++#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 + #include diff --git a/glib2/patches/2.75.1/libffi-pkgconfig-pc.patch b/glib2/patches/2.75.1/libffi-pkgconfig-pc.patch new file mode 100644 index 0000000..d3988b0 --- /dev/null +++ b/glib2/patches/2.75.1/libffi-pkgconfig-pc.patch @@ -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, diff --git a/glib2/patches/2.75.1/ngettext.patch b/glib2/patches/2.75.1/ngettext.patch new file mode 100644 index 0000000..f43149a --- /dev/null +++ b/glib2/patches/2.75.1/ngettext.patch @@ -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_deps += [libintl] + else + libintl_pthread = cc.find_library('pthread', required : false)