php / php/php-src

Use pkg-config on Windows

Offen
#16,752 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@cmb69 arbeitet bereits daran.

Seit 16.11.2024.

Category: Build System Feature OS: Windows Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

On POSIX systems, we use pkg-config to configure most (all?) dependency libraries. On Windows, we still look for the headers and libraries "manually" (CHECK_LIB and CHECK_HEADER_ADD_INCLUDE, what is clumsy and likely more constraining than necessary. And maybe worse, it makes it harder to port m4 configurations to w32, or to keep them in sync. It gets especially annoying when we want to check for a certain package version (usually a minimum requirement). Instead I suggest to use pkg-config on Windows, too.

POC

I've put a pkg-config.exe in the PATH, put a suitable zlib.pc in %DEPS%\lib\pkgconfig, and added that to PKG_CONFIG_PATH.

Then I've applied the following patch to php-src:

 ext/zlib/config.w32      |  6 +++---
 win32/build/confutils.js | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/ext/zlib/config.w32 b/ext/zlib/config.w32
index 3bc24d88e1..623d752e57 100644
--- a/ext/zlib/config.w32
+++ b/ext/zlib/config.w32
@@ -3,9 +3,9 @@
 ARG_ENABLE("zlib", "ZLIB support", "yes");
 
 if (PHP_ZLIB == "yes") {
-	if (CHECK_LIB("zlib_a.lib;zlib.lib", "zlib", PHP_ZLIB) &&
-		CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects)) {
-
+	if (PKG_CHECK_MODULES("ZLIB", "zlib >= 1.2.11")) {
+		PHP_EVAL_INCLINE(ZLIB_CFLAGS);
+		PHP_EVAL_LIBLINE(ZLIB_LIBS, "zlib");
 		EXTENSION("zlib", "zlib.c zlib_fopen_wrapper.c zlib_filter.c", PHP_ZLIB_SHARED, "/D ZLIB_EXPORTS /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
 		AC_DEFINE("HAVE_ZLIB", 1, "Define to 1 if the PHP extension 'zlib' is available.");
 
diff --git a/win32/build/confutils.js b/win32/build/confutils.js
index 3623dcf7e2..63bd1b867a 100644
--- a/win32/build/confutils.js
+++ b/win32/build/confutils.js
@@ -1054,6 +1054,51 @@ function CHECK_HEADER_ADD_INCLUDE(header_name, flag_name, path_to_check, use_env
 	return p;
 }
 
+function PKG_CHECK_MODULES(prefix, list_of_modules)
+{
+	var out;
+	STDOUT.Write("checking for " + list_of_modules + "... ");
+	if (!(out = execute("pkg-config --cflags " + list_of_modules))) {
+		STDOUT.WriteLine("no");
+		return false;
+	}
+	eval(prefix + "_CFLAGS = out");
+	if (!(out = execute("pkg-config --libs " + list_of_modules))) {
+		STDOUT.WriteLine("no");
+		return false;
+	}
+	eval(prefix + "_LIBS = out");
+	STDOUT.WriteLine("yes");
+	return true;
+}
+
+function PHP_EVAL_LIBLINE(libline, libs_variable, not_extension)
+{
+	libs_variable = libs_variable.toUpperCase();
+	var args = libline.split(/\s/);
+	for (var i = 0; i < args.length; i++) {
+		var arg = args[i];
+		if (arg.match(/^-l(.*)/)) {
+			ADD_FLAG("LIBS_" + libs_variable, RegExp.$1 + ".lib");
+		} else if (arg.match(/^-L(.*)/)) {
+			var path = condense_path(RegExp.$1);
+			ADD_FLAG("LDFLAGS_" + libs_variable, '/libpath:"' + path + '" ');
+			ADD_FLAG("ARFLAGS_" + libs_variable, '/libpath:"' + path + '" ');
+		}
+	}
+}
+
+function PHP_EVAL_INCLINE(headerline)
+{
+	var args = headerline.split(/\s/);
+	for (var i = 0; i < args.length; i++) {
+		var arg = args[i];
+		if (arg.match(/^-I(.*)/)) {
+			ADD_FLAG("CFLAGS", "/I " + condense_path(RegExp.$1));
+		}
+	}
+}
+
 /* XXX check whether some manifest was originally supplied, otherwise keep using the default. */
 function generate_version_info_manifest(makefiletarget)
 {

If we want to take this route, we should ship pkg-config with https://github.com/php/php-sdk-binary-tools (we can probably use https://github.com/skeeto/u-config). And the winlibs builds would need to actually contain .pc files. I don't think it's viable to rebuilt all php-src dependency winlibs right away, but when updating to new versions, the *.pc files could be added, and then php-src could be adapted to use them.

Thoughts?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Prüfung des offenen Pull Requests #16830 und lies anschließend win32/build/confutils.js und ext/zlib/config.w32, insbesondere die vorgeschlagenen PKG_CHECK_MODULES-, PHP_EVAL_INCLINE- und PHP_EVAL_LIBLINE-Einstiegspunkte. Untersuche php-sdk-binary-tools und das in der Issue erwähnte winlibs-Dependency-Packaging. Als erledigt gilt die Aufgabe, wenn der Windows-Build pkg-config konsistent verwenden kann und die erforderlichen .pc-Dateien für Tool und Abhängigkeiten verfügbar sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
build-system, operating-systems
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.