Skip to content

Windows support #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Windows support #263

wants to merge 2 commits into from

Conversation

NoiseByNorthwest
Copy link
Owner

@NoiseByNorthwest NoiseByNorthwest force-pushed the windows-support branch 17 times, most recently from 38263ad to d93b00e Compare September 8, 2024 17:35
@DanielRuf
Copy link
Contributor

Regarding zlib, there might be some additional logic at https://github.com/DanielRuf/php-spx/pull/1/files that can be helpful.

I didn't test this so far due to other more important things.

@NoiseByNorthwest NoiseByNorthwest force-pushed the windows-support branch 5 times, most recently from d3b1a59 to 114469d Compare September 8, 2024 21:35
@NoiseByNorthwest
Copy link
Owner Author

@DanielRuf Yes, I now have to add zlib dev package to the windows image. I'm looking for an example, without success so far.

@DanielRuf
Copy link
Contributor

DanielRuf commented Sep 8, 2024

Maybe vcpkg.exe install zlib helps further (see https://vcpkgx.com/details.html?package=zlib and https://vcpkg.io/en/).

https://github.com/DanielRuf/spx-windows-build/actions/runs/10763553391/job/29845207008#step:2:54

I also found this: https://wiki.php.net/internals/windows/libs/apache22

https://github.com/madler/zlib/tree/develop/win32

Not sure if there is some more step needed to compile and load the zlib library.

@NoiseByNorthwest NoiseByNorthwest force-pushed the windows-support branch 3 times, most recently from 953727e to ac17287 Compare September 8, 2024 22:53
@DanielRuf
Copy link
Contributor

DanielRuf commented Sep 8, 2024

zlib.lib and zlibd(ebug).lib should be there:

vcpkg.exe install zlib
dir C:/vcpkg/packages/zlib_x64-windows/debug/lib
dir C:/vcpkg/packages/zlib_x64-windows/lib
vcpkg.exe install zlib:x64-windows-static
dir C:/vcpkg/packages/zlib_x64-windows-static/debug/lib
dir C:/vcpkg/packages/zlib_x64-windows-static/lib

C:\vcpkg\packages\zlib_x64-windows\bin contains zlib.pdb and zlib1.dll.
C:\vcpkg\packages\zlib_x64-windows\include contains zconf.h and zlib.h.

I think these should be all relevant files.

I will check later, because a quick search at https://github.com/search?q=repo%3Aphp%2Fphp-windows-builder+libraries&type=code makes me think, that we can simply drop the files in some deps folder, that is linked somehow.

Upon further inspection, this is used via configure --with-php-build="..\deps" in the other project (deps is probably the src folder of PHP, didn't check further). The referenced URLs like https://downloads.php.net/~windows/php-sdk/deps contain some more dependencies (if needed). There we can also find the dll files (see https://downloads.php.net/~windows/php-sdk/deps/dllmapping.json).

@DanielRuf
Copy link
Contributor

@cmb69 before I am going in circles, where can we drop the files to let config.w32 find them with the least amount of changes and most portable setup (configure paramaters / changes only in the CI step)?

@cmb69
Copy link

cmb69 commented Oct 9, 2024

Something like

this patch
 Makefile.frag.w32     | 9 +++++++++
 config.w32            | 3 ++-
 src/php_spx.c         | 2 +-
 src/spx_reporter_fp.c | 2 +-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Makefile.frag.w32 b/Makefile.frag.w32
new file mode 100644
index 0000000..da1aaee
--- /dev/null
+++ b/Makefile.frag.w32
@@ -0,0 +1,9 @@
+
+spx_ui_assets_dir = $(PHP_PREFIX)/share/misc/php-spx/assets/web-ui
+
+install-spx-ui-assets:
+	@echo "Installing SPX web UI to: $(spx_ui_assets_dir)"
+	@mkdir -p $(spx_ui_assets_dir)
+	@cp -r assets/web-ui/* $(spx_ui_assets_dir)
+
+install: $(all_targets) $(install_targets) install-spx-ui-assets
diff --git a/config.w32 b/config.w32
index d6cc0f5..4231332 100644
--- a/config.w32
+++ b/config.w32
@@ -5,7 +5,7 @@ ARG_ENABLE("spx-dev", "Compile SPX with debugging symbols", "no");
 if (PHP_SPX == "yes") {
     AC_DEFINE("HAVE_SPX", 1, "spx");
 
-    ADD_FLAG("CFLAGS", "/Ox /Wall /WX /W2 /wd4820 /wd4774 /wd4711 /wd4710 /wd4464 /wd4005");
+    ADD_FLAG("CFLAGS", "/Ox /Wall /W2 /wd4820 /wd4774 /wd4711 /wd4710 /wd4464 /wd4005");
 
     if (PHP_SPX_DEV == "yes") {
         ADD_FLAG("CFLAGS", "/Zi");
@@ -18,6 +18,7 @@ if (PHP_SPX == "yes") {
         ERROR("zlib not found");
     }
 
+    AC_DEFINE("SPX_HTTP_UI_ASSETS_DIR", PHP_PREFIX.replace(/\\/g, "/") + "/share/misc/php-spx/assets/web-ui");
     EXTENSION("spx", "src/php_spx.c \
         src/spx_profiler.c \
         src/spx_profiler_tracer.c \
diff --git a/src/php_spx.c b/src/php_spx.c
index 02276f9..b9759cc 100644
--- a/src/php_spx.c
+++ b/src/php_spx.c
@@ -926,7 +926,7 @@ static void http_ui_handler_shutdown(void)
         goto finish;
     }
 
-    char local_file_absolute_path[PATH_MAX];
+    char local_file_absolute_path[MAXPATHLEN];
 
     if (
         spx_utils_resolve_confined_file_absolute_path(
diff --git a/src/spx_reporter_fp.c b/src/spx_reporter_fp.c
index 6c503ee..f4828d7 100644
--- a/src/spx_reporter_fp.c
+++ b/src/spx_reporter_fp.c
@@ -20,7 +20,7 @@
 #include <stdlib.h>
 #include <math.h>
 
-#include <unistd.h>
+// #include <unistd.h>
 
 #include "spx_reporter_fp.h"
 #include "spx_resource_stats.h"

should be a step in the right direction. With this patch applied (and also having pthreads in the deps/ folder; should be checked in config.w32), I get:

src/spx_metric.c(30): fatal error C1189: #error:  "Please open an issue"

@NoiseByNorthwest NoiseByNorthwest force-pushed the windows-support branch 4 times, most recently from bece402 to a9f39df Compare October 9, 2024 22:11
@NoiseByNorthwest
Copy link
Owner Author

Thanks @cmb69, I've applied your patch, with a slight variation around PATH_MAX management, and I got this error:

D:\a\php-spx\php-spx\build\ee0377d3\src\php_spx.c : fatal error C1083: Cannot open compiler generated file: 'D:\a\php-spx\php-spx\build\ee0377d3\x64\Release\src\php_spx.obj': No such file or directory

https://github.com/NoiseByNorthwest/php-spx/actions/runs/11263855256/job/31322677812

@NoiseByNorthwest NoiseByNorthwest force-pushed the windows-support branch 2 times, most recently from d651e72 to 7c4520e Compare October 20, 2024 16:34
@cmb69
Copy link

cmb69 commented Oct 20, 2024

I've applied your patch, with a slight variation around PATH_MAX management, and I got this error:

Sorry, I still had no time to look closer into this, but I do not understand why there is a src\ in x64\Release\src\php_spx.obj. The .obj files are supposed to be placed in x64\Release, and they are in my local build. Is that something that php/php-windows-builder does?

@NoiseByNorthwest
Copy link
Owner Author

Sorry, I still had no time to look closer into this

Don't worry, and thank you again for your help.

I do not understand why there is a src\ in x64\Release\src\php_spx.obj. The .obj files are supposed to be placed in x64\Release, and they are in my local build. Is that something that php/php-windows-builder does?

I don't know either, I will do some tests with other php-windows-builder's versions, and look at the doc and other extensions using it.

NoiseByNorthwest added a commit that referenced this pull request Nov 29, 2024
This patch is not a complete support of windows. Its goal is to
port to master branch right now the current changes made to src/ to
support windows.

See here: #263
@NoiseByNorthwest
Copy link
Owner Author

@DanielRuf I'm pausing the development of this PR until the future web UI version is released or sufficiently advanced.

The current status of this PR is that it is stuck on build issues at CI level. I'm not surprised as this is the kind of difficulty I had anticipated.
Once build issues are fixed, it could take only 1-2 weeks to reach a "working on windows" status. And then few other weeks for fixing windows-related issues with the help of beta testers.

I've also already merged most of the diff required for windows support in a separate branch (see #279) in order to minimize conflicts between master and this branch.

@xPaw
Copy link

xPaw commented Jun 25, 2025

Creating the "src" folder in build dir makes it progress further in the build, same as here: https://github.com/php/php-windows-builder/blob/05e226632e0d42889883a5fab741aa17233b3457/extension/BuildPhpExtension/patches/raphf.ps1

config.w32:

    base_dir = get_define('BUILD_DIR');
    WScript.Echo("Creating " + base_dir + "\\src" + "...");
    FSO.CreateFolder(base_dir+"\\src");

gets to:
D:\a\php-spx\php-spx\build\990b375a\src/spx_metric.c(30): fatal error C1189: #error: "Please open an issue"

@NoiseByNorthwest
Copy link
Owner Author

@xPaw This seems interesting, don't hesitate to make a PR targeting this branch.

Or just paste the patch here, I don't really see what needs to be modified in config.w32

@xPaw
Copy link

xPaw commented Jun 28, 2025

I just added these 3 lines inside of the if()

@xPaw
Copy link

xPaw commented Jun 28, 2025

I think you have to also update php-windows-builder to a fresher commit. But maybe if this branch was rebased on master it would have picked up the composer.json

@NoiseByNorthwest
Copy link
Owner Author

I think you have to also update php-windows-builder to a fresher commit. But maybe if this branch was rebased on master it would have picked up the composer.json

It's rebased and on last version of php-windows-builder now

@xPaw
Copy link

xPaw commented Jun 28, 2025

I think zlib needs to be removed from composer? When I tested I didn't rebase it so I didn't run into this issue, just updating the extension builder was enough.

@NoiseByNorthwest
Copy link
Owner Author

I think zlib needs to be removed from composer? When I tested I didn't rebase it so I didn't run into this issue, just updating the extension builder was enough.

Yes indeed, I also mentioned this point here
#291 (comment)

@xPaw
Copy link

xPaw commented Jun 28, 2025

Well it got to #error: "Please open an issue", that's the expected situation currently?

@NoiseByNorthwest
Copy link
Owner Author

NoiseByNorthwest commented Jun 28, 2025

Well it got to #error: "Please open an issue", that's the expected situation currently?

Yes, it goes further than before, thank you !

And yes, this error is expected, it's one of the compatibility issues I'll have to fix.

NoiseByNorthwest added 2 commits June 30, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants