Skip to content
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

Windows out-of-tree extension build (using phpize.bat) doesn't play nice when two folders contain .c files with the same name #16843

Open
dktapps opened this issue Nov 18, 2024 · 2 comments

Comments

@dktapps
Copy link
Contributor

dktapps commented Nov 18, 2024

Description

Relevant config.w32 code: https://github.com/pmmp/ext-pmmpthread/blob/ed6b7eeda8e6eab54f95c61bd94de69a15d339f6/config.w32#L29-L38

Both classes and src have different files called worker.c. This works fine when the extension is built in-tree, but bails out when using phpize on Windows.

Extension is fully successful in building on *nix, so this is a Windows build system specific issue.

NMAKE : warning U4004: too many rules for target 'D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\\worker.obj'
	"cl.exe" /I "D:\a\ext-pmmpthread\ext-pmmpthread\deps\include" /DHAVE_PTHREAD_H=1 /DHAVE_SCHED_H=1 /DHAVE__PTW32_H=1 /D ZEND_COMPILE_DL_EXT=1 /D COMPILE_DL_PMMPTHREAD /D PMMPTHREAD_EXPORTS=1 /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 /permissive- /ID:\a\ext-pmmpthread\ext-pmmpthread /nologo /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/main /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/Zend /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/TSRM /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/ext /D _WINDOWS /D WINDOWS=1 /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /D _USE_MATH_DEFINES /FD /wd4996 /RTC1 /Zc:__cplusplus /d2FuncCache1 /Zc:wchar_t /MP /LDd /MDd /Od /D _DEBUG /D ZEND_DEBUG=1 /Zi /D ZTS=1 /I "D:\a\ext-pmmpthread\ext-pmmpthread\deps\include" /FoD:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\\ /FpD:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\\ /FRD:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\\ /FdD:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\\ /c D:\a\ext-pmmpthread\ext-pmmpthread\classes\pool.c D:\a\ext-pmmpthread\ext-pmmpthread\classes\runnable.c D:\a\ext-pmmpthread\ext-pmmpthread\classes\thread.c D:\a\ext-pmmpthread\ext-pmmpthread\classes\thread_safe.c D:\a\ext-pmmpthread\ext-pmmpthread\classes\thread_safe_array.c D:\a\ext-pmmpthread\ext-pmmpthread\classes\worker.c
pool.c
runnable.c
thread.c
thread_safe.c
thread_safe_array.c
worker.c
	rc /nologo  /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/main /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/Zend /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/TSRM /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include/ext /I D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK/include /n /fo D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\php_pmmpthread.dll.res /d _DEBUG /d FILE_DESCRIPTION="\"php_pmmpthread.dll\"" /d FILE_NAME="\"php_pmmpthread.dll\"" /d URL="\"http://www.php.net\"" /d INTERNAL_NAME="\"PMMPTHREAD extension\"" /d THANKS_GUYS="\"\"" D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK\build\template.rc
	"link.exe" @"D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\resp\PMMPTHREAD_GLOBAL_OBJS.txt" D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK\lib\php8ts_debug.lib pthreadVC3.lib kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib psapi.lib bcrypt.lib D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\php_pmmpthread.dll.res /out:D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\php_pmmpthread.dll /dll /nologo /d2:-AllowCompatibleILVersions /debug /libpath:"\"D:\a\ext-pmmpthread\ext-pmmpthread\deps\lib\"" /libpath:"D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK\lib\;D:\a\ext-pmmpthread\ext-pmmpthread\bin\SDK" /libpath:"deps\lib"
D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\\worker.obj : warning LNK4042: object specified more than once; extras ignored
   Creating library D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\php_pmmpthread.lib and object D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\php_pmmpthread.exp
object.obj : error LNK2019: unresolved external symbol pmmpthread_worker_data_alloc referenced in function pmmpthread_worker_ctor
object.obj : error LNK2019: unresolved external symbol pmmpthread_worker_data_free referenced in function pmmpthread_base_free
object.obj : error LNK2019: unresolved external symbol pmmpthread_worker_get_gc_extra referenced in function pmmpthread_base_gc
routine.obj : error LNK2019: unresolved external symbol pmmpthread_worker_sync_collectable_tasks referenced in function pmmpthread_join
store.obj : error LNK2001: unresolved external symbol pmmpthread_worker_sync_collectable_tasks
routine.obj : error LNK2019: unresolved external symbol pmmpthread_worker_next_task referenced in function pmmpthread_routine
routine.obj : error LNK2019: unresolved external symbol pmmpthread_worker_add_garbage referenced in function pmmpthread_routine
worker.obj : error LNK2019: unresolved external symbol pmmpthread_worker_task_queue_size referenced in function zim_pmmp_thread_Worker_getStacked@@16
worker.obj : error LNK2019: unresolved external symbol pmmpthread_worker_add_task referenced in function zim_pmmp_thread_Worker_stack@@16
worker.obj : error LNK2019: unresolved external symbol pmmpthread_worker_dequeue_task referenced in function zim_pmmp_thread_Worker_unstack@@16
worker.obj : error LNK2019: unresolved external symbol pmmpthread_worker_collect_tasks referenced in function zim_pmmp_thread_Worker_collect@@16
pool.obj : error LNK2001: unresolved external symbol pmmpthread_worker_collect_tasks
worker.obj : error LNK2019: unresolved external symbol pmmpthread_worker_collect_function referenced in function zim_pmmp_thread_Worker_collect@@16
pool.obj : error LNK2001: unresolved external symbol pmmpthread_worker_collect_function
D:\a\ext-pmmpthread\ext-pmmpthread\x64\Debug_TS\php_pmmpthread.dll : fatal error LNK1[120](https://github.com/pmmp/ext-pmmpthread/actions/runs/11891680318/job/33132935789#step:4:121): 11 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\link.exe"' : return code '0x460'
Stop.

Microsoft (R) Program Maintenance Utility Version 14.29.30157.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        1 file(s) copied.
The system cannot find the file specified.
NMAKE : fatal error U1077: 'copy' : return code '0x1'
Stop.
Error: Process completed with exit code 1.

https://github.com/pmmp/ext-pmmpthread/actions/runs/11891894259/job/33133760918

PHP Version

8.1.30, 8.2.25 & 8.3.13

Operating System

GitHub Actions windows-2019 image

@dktapps
Copy link
Contributor Author

dktapps commented Nov 18, 2024

After digging through confutils.js I was able to come up with a workaround like so:

pmmp/ext-pmmpthread@5a6ae48

Looks like

var build_dir = (dirname ? dirname : "").replace(new RegExp("^..\\\\"), "");
is the problem. It still needs to respect dir in phpize mode. Probably needs to replace the base build dir with "" in dir instead of ignoring it completely.

@cmb69
Copy link
Member

cmb69 commented Nov 18, 2024

Indeed, this looks like a bug. Maybe the following is sufficient and won't break working builds:

 win32/build/confutils.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/win32/build/confutils.js b/win32/build/confutils.js
index 3623dcf7e2..d7e2a211e7 100644
--- a/win32/build/confutils.js
+++ b/win32/build/confutils.js
@@ -1614,8 +1614,15 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
 		if (obj_dir == null) {
 			if (MODE_PHPIZE) {
 				/* In the phpize mode, the subdirs are always relative to BUID_DIR.
-					No need to differentiate by extension, only one gets built. */
-				var build_dir = (dirname ? dirname : "").replace(new RegExp("^..\\\\"), "");
+					No need to differentiate by extension, only one gets built.
+					We still need to cater to subfolders, though. */
+				if (dir.charAt(configure_module_dirname.length) === "\\" &&
+					dir.substr(0, configure_module_dirname.length) === configure_module_dirname) {
+					var reldir = dir.substr(configure_module_dirname.length + 1);
+					var build_dir = (dirname ? (reldir + "\\" + dirname) : reldir).replace(new RegExp("^..\\\\"), "");
+				} else {
+					var build_dir = (dirname ? dirname : "").replace(new RegExp("^..\\\\"), "");
+				}
 			} else {
 				var build_dir = (dirname ? (dir + "\\" + dirname) : dir).replace(new RegExp("^..\\\\"), "");
 			}

Still, I'm not sure if we should apply this for stable PHP versions.

dktapps added a commit to pmmp/ext-pmmpthread that referenced this issue Nov 18, 2024
this required a MODE_PHPIZE switched workaround for php/php-src#16843

Extension is now built out-of-tree using phpize.bat, which significantly speeds up the build by allowing the main PHP part to be cached.

Exact versions of PHP are now used to improve build reproducibility, like the Linux builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants