Skip to content

Multiarch CI jobs fail #390

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
nickva opened this issue Mar 18, 2025 · 11 comments · Fixed by #391
Open

Multiarch CI jobs fail #390

nickva opened this issue Mar 18, 2025 · 11 comments · Fixed by #391

Comments

@nickva
Copy link
Contributor

nickva commented Mar 18, 2025

Noticed recently most of the multi-arch CI jobs fail

It seems $platform/$image syntax is not support any longer by runner.

docker run --rm --interactive --mount type=bind,source=$(pwd),target=/host arm32v6/alpine
nickva added a commit to nickva/quickjs that referenced this issue Mar 18, 2025
@bellard
Copy link
Owner

bellard commented Mar 19, 2025

Thank you. It would be good to add the following targets:

  • x86 32 bit build on debian:

make CONFIG_M32=y

  • Windows 64 bit cross build using mingw on debian. At least some tests may be run with wine:

make CONFIG_WIN32=y

  • if possible, cosmopolitan build by downloading the cosmocc compiler.

@nickva
Copy link
Contributor Author

nickva commented Mar 19, 2025

Linux 32 bit and Cosmopolitan: #392

For 32bit linux it was easier to go with Ubuntu rather than Debian, as it's a directly supported OS for a Github Actions. Installing gcc-multiib package seems to worked to allow compiling with -m32.

@nickva
Copy link
Contributor Author

nickva commented Mar 19, 2025

Cross compiling on Ubuntu with CONFIG_WIN32=y fails when trying to link to pthreads.

Tested on Ubuntu 24 host and sudo apt install mingw-w64.

$ make CONFIG_WIN32=y 
mkdir -p .obj .obj/examples .obj/tests
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/quickjs.check.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -DCONFIG_CHECK_JSVALUE -c -o .obj/quickjs.check.o quickjs.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/qjs.check.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -DCONFIG_CHECK_JSVALUE -c -o .obj/qjs.check.o qjs.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/qjs.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/qjs.o qjs.c
gcc -g -Wall -MMD -MF .obj/qjsc.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -DCONFIG_CC=\"gcc\" -DCONFIG_PREFIX=\"/usr/local\" -O2 -c -o .obj/qjsc.host.o qjsc.c
gcc -g -Wall -MMD -MF .obj/quickjs.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/quickjs.host.o quickjs.c
gcc -g -Wall -MMD -MF .obj/dtoa.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/dtoa.host.o dtoa.c
gcc -g -Wall -MMD -MF .obj/libregexp.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/libregexp.host.o libregexp.c
gcc -g -Wall -MMD -MF .obj/libunicode.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/libunicode.host.o libunicode.c
gcc -g -Wall -MMD -MF .obj/cutils.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/cutils.host.o cutils.c
gcc -g -Wall -MMD -MF .obj/quickjs-libc.host.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/quickjs-libc.host.o quickjs-libc.c
gcc -g -o host-qjsc .obj/qjsc.host.o .obj/quickjs.host.o .obj/dtoa.host.o .obj/libregexp.host.o .obj/libunicode.host.o .obj/cutils.host.o .obj/quickjs-libc.host.o -lm -ldl -lpthread
./host-qjsc -c -o repl.c -m repl.js
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/repl.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/repl.o repl.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/quickjs.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/quickjs.o quickjs.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/dtoa.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/dtoa.o dtoa.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/libregexp.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/libregexp.o libregexp.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/libunicode.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/libunicode.o libunicode.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/cutils.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/cutils.o cutils.c
x86_64-w64-mingw32-gcc -g -Wall -MMD -MF .obj/quickjs-libc.o.d -Wno-array-bounds -Wno-format-truncation -fwrapv  -D_GNU_SOURCE -DCONFIG_VERSION=\"2024-02-14\" -D__USE_MINGW_ANSI_STDIO  -O2 -c -o .obj/quickjs-libc.o quickjs-libc.c
x86_64-w64-mingw32-gcc -g  -o qjs.exe .obj/qjs.o .obj/repl.o .obj/quickjs.o .obj/dtoa.o .obj/libregexp.o .obj/libunicode.o .obj/cutils.o .obj/quickjs-libc.o -lm 
/usr/bin/x86_64-w64-mingw32-ld: .obj/quickjs.o: in function `JS_NewClassID':
/home/nickv/src/quickjs/quickjs.c:3231:(.text+0x5755): undefined reference to `pthread_mutex_lock'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:3239:(.text+0x5774): undefined reference to `pthread_mutex_unlock'
/usr/bin/x86_64-w64-mingw32-ld: .obj/quickjs.o: in function `js_atomics_notify':
/home/nickv/src/quickjs/quickjs.c:53004:(.text+0x36c10): undefined reference to `pthread_mutex_lock'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:53019:(.text+0x36ca5): undefined reference to `pthread_cond_signal'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:53021:(.text+0x36cb6): undefined reference to `pthread_mutex_unlock'
/usr/bin/x86_64-w64-mingw32-ld: .obj/quickjs.o: in function `js_atomics_wait':
/home/nickv/src/quickjs/quickjs.c:52936:(.text+0x3c2b4): undefined reference to `pthread_mutex_lock'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52949:(.text+0x3c2f2): undefined reference to `pthread_cond_init'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52958:(.text+0x3c34b): undefined reference to `clock_gettime'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52965:(.text+0x3c3b1): undefined reference to `pthread_cond_timedwait'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52970:(.text+0x3c3e9): undefined reference to `pthread_mutex_unlock'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52971:(.text+0x3c3f1): undefined reference to `pthread_cond_destroy'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52943:(.text+0x3c46e): undefined reference to `pthread_mutex_unlock'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52954:(.text+0x3c497): undefined reference to `pthread_cond_wait'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52970:(.text+0x3c4f4): undefined reference to `pthread_mutex_unlock'
/usr/bin/x86_64-w64-mingw32-ld: /home/nickv/src/quickjs/quickjs.c:52971:(.text+0x3c4fc): undefined reference to `pthread_cond_destroy'
collect2: error: ld returned 1 exit status
make: *** [Makefile:245: qjs.exe] Error 1

I can see winpthreads is installed but it may need either a linker flag to make it link staticly?

/usr/i686-w64-mingw32/lib $ ls *winpthread*
libwinpthread-1.dll  libwinpthread.a  libwinpthread.dll.a

There is a windows runner for Github Actions, that could be an option if compiling with Msys2?

@nickva
Copy link
Contributor Author

nickva commented Mar 19, 2025

I managed to compile with mingw64 with this patch:

diff --git i/Makefile w/Makefile
index 8314cb7..dca0d70 100644
--- i/Makefile
+++ w/Makefile
@@ -233,7 +233,9 @@ QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/repl.o $(QJS_LIB_OBJS)
 
 HOST_LIBS=-lm -ldl -lpthread
 LIBS=-lm
-ifndef CONFIG_WIN32
+ifdef CONFIG_WIN32
+LIBS+=-static-libgcc -Wl,-Bstatic -lpthread
+else
 LIBS+=-ldl -lpthread
 endif
 LIBS+=$(EXTRA_LIBS)

If static option is not provided then need to put libwinpthread-1.dll somewhere to be found at runtime.

Wine seems to run a few tests successfully. Others fail.

$ wine qjs.exe tests/test_bigint.js 
$ wine qjs.exe tests/test_builtin.js 
$ wine qjs.exe tests/test_closure.js 
$ wine qjs.exe tests/test_language.js 
$ wine qjs.exe tests/test_loop.js

$ wine qjs.exe tests/test_bjson.js 
ReferenceError: shared library modules are not supported yet

$ wine qjs.exe tests/test_std.js 
Can't recognize 'cat tmp_file.txt' as an internal or external command, or batch script.
Error: assertion failed: got ||, expected |hello world|
    at assert (tests/test_std.js:19)
    at test_popen (tests/test_std.js:124)
    at <anonymous> (tests/test_std.js:301)

$ wine qjs.exe tests/test_worker.js 
TypeError: not a function
    at test_worker (tests/test_worker.js:28)
    at <anonymous> (tests/test_worker.js:62)

$ wine qjs.exe tests/test_worker_module.js 
TypeError: cannot read property 'parent' of undefined
    at <anonymous> (tests/test_worker_module.js:5)

Microbenchmark segfaults

Couldn't get first exception for process 00e0 Z:\home\....\src\quickjs\qjs.exe.
No backtrace available
Modules:
Module  Address                                 Debug info      Name (11 modules)
PE             140000000-       14046a000       Deferred        qjs
ELF         5bcb0cae8000-    5bcb0caed000       Deferred        <wine-loader>
PE-Wine     6ffffefc0000-    6fffff317000       Deferred        msvcrt
PE-Wine     6fffff470000-    6fffffa6c000       Deferred        kernelbase
PE-Wine     6fffffa80000-    6fffffc38000       Deferred        kernel32
PE-Wine     6fffffc50000-    6ffffffeb000       Deferred        ntdll
ELF         761421400000-    761421612000       Deferred        libc.so.6
ELF         76142162e000-    761421660000       Deferred        liblzma.so.5
ELF         761421660000-    76142167b000       Deferred        libunwind.so.8
ELF         76142167b000-    761421736000       Export          ntdll.so
ELF         761421756000-    761421790000       Deferred        ld-linux-x86-64.so.2
Threads:
process  tid      prio    name (all IDs are in hex)
00000020 start.exe
	00000024    0     
00000038 services.exe
	0000003c    0     
	00000040    0     wine_rpcrt4_server
	0000004c    0     wine_rpcrt4_io
	0000005c    0     wine_rpcrt4_io
	0000007c    0     wine_rpcrt4_io
	000000a4    0     wine_rpcrt4_io
	000000c0    0     wine_rpcrt4_io
	000000d4    0     
	000000fc    0     wine_rpcrt4_io
00000044 winedevice.exe
	00000048    0     
	00000054    0     
	00000058    0     wine_sechost_service
	00000060    0     
	0000006c    0     
	00000070    0     
	000000cc    0     
	000000d0    0     
00000064 explorer.exe
	00000068    0     
	000000e8    0     
	000000ec    0     wine_rpcrt4_server
00000074 winedevice.exe
	00000078    0     
	00000080    0     
	00000084    0     wine_sechost_service
	00000088    0     
	0000008c    0     
	00000090    0     
	00000094    0     
	00000098    0     
0000009c plugplay.exe
	000000a0    0     
	000000a8    0     
	000000b0    0     wine_sechost_service
	000000b4    0     wine_rpcrt4_server
000000b8 svchost.exe
	000000bc    0     
	000000c4    0     
	000000c8    0     wine_sechost_service
000000d8 conhost.exe
	000000dc    0     
000000e0 (D) Z:\home\nickv\src\quickjs\qjs.exe
	000000e4    0     
000000f4 rpcss.exe
	000000f8    0     
	00000100    0     
	00000104    0     wine_sechost_service
	00000108    0     wine_rpcrt4_server
	0000010c    0     wine_rpcrt4_server
	00000110    0     wine_rpcrt4_io
System information:
    Wine build: wine-9.0 (Ubuntu 9.0~repack-4build3)
    Platform: x86_64 (guest: i386)
    Version: Windows 10
    Host system: Linux
    Host version: 6.8.0-55-generic

@nickva
Copy link
Contributor Author

nickva commented Mar 20, 2025

I wonder is the intent that workers/atomics or anything related to pthreads should work for windows? If not, perhaps we can exclude it with an #ifdef section, then the linker won't look for it at all.

A while back I created a PR to add such a mode #300, as we at Apache CouchDB don't use workers and didn't want to include the winpthreads.dll in the distribution, but now I wonder if perhaps pthreads were never intended to work on Windows all.

@bellard
Copy link
Owner

bellard commented Mar 20, 2025

Regarding -lpthread, your patch is not needed. You need instead to copy libwinpthread*.dll to the same directory as qjs.exe (see how the Windows binary packages are built in the win_binary target of the "release.sh" script).

@bellard
Copy link
Owner

bellard commented Mar 20, 2025

I wonder is the intent that workers/atomics or anything related to pthreads should work for windows? If not, perhaps we can exclude it with an #ifdef section, then the linker won't look for it at all.

A while back I created a PR to add such a mode #300, as we at Apache CouchDB don't use workers and didn't want to include the winpthreads.dll in the distribution, but now I wonder if perhaps pthreads were never intended to work on Windows all.

I confirm workers are not supported with Windows. #ifdef can be added in the Makefile.

@nickva
Copy link
Contributor Author

nickva commented Mar 28, 2025

I added CONFIG_LTO=y, mingw cross-compile and a windows msys2 target

@nickva
Copy link
Contributor Author

nickva commented Mar 31, 2025

@bellard I think #393 is ready for another look

@bnoordhuis
Copy link
Contributor

I merged Windows support for os.Worker (no pthreads) in quickjs-ng/quickjs@62fb636 just now. It builds on previous work and won't cherry-pick cleanly but maybe you can use bits and pieces.

@big-r81
Copy link

big-r81 commented Apr 7, 2025

Another option is to bring in (like mentioned above) the compiler switch -Bstatic -lpthread like we do it for the Windows build of CouchDB. So we don't need to include and ship the extra dll...

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 a pull request may close this issue.

4 participants