Skip to content

Commit 8c7305c

Browse files
committed
ci: fix compilers build
1 parent 0fac2df commit 8c7305c

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

.github/workflows/bytecode-compilers.yml

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ jobs:
167167
if [ "${{ matrix.host }}" = "win32-x64" ]; then
168168
# CONFIG_WIN32=y selects the x86_64-w64-mingw32- cross toolchain.
169169
make -j"$jobs" CONFIG_WIN32=y libquickjs.a
170+
# bellard's win32 LIBS are "-lm -lpthread" (winpthreads provides the
171+
# pthread_* and clock_gettime symbols quickjs.c uses).
170172
x86_64-w64-mingw32-gcc -O2 -DNSBC_MAGIC='"NSBCQJS"' -I. \
171-
-o "$out/nsbc-quickjs.exe" "$SHIM" libquickjs.a -lm
173+
-o "$out/nsbc-quickjs.exe" "$SHIM" libquickjs.a -lm -lpthread
172174
# Cross-built Windows binary — not runnable on the Linux host.
173175
else
174176
# Use bellard's own Makefile so CONFIG_VERSION / _GNU_SOURCE and the
@@ -228,19 +230,23 @@ jobs:
228230
SHIM: ${{ github.workspace }}/tools/bytecode-compiler/native/qjs-compile.c
229231
run: |
230232
set -euxo pipefail
231-
# Build only the static engine lib target ('qjs' -> libqjs.a / qjs.lib);
232-
# skip the CLI/test executables.
233+
# Build the shim as a CMake target so it uses the SAME toolchain + CRT
234+
# as the engine lib. Linking a separately-compiled (clang) shim against
235+
# the MSVC-built qjs.lib fails with __imp_*/CRT-mismatch link errors on
236+
# Windows. The 'qjs' target propagates its public include dirs and libm.
237+
cp "$SHIM" quickjs-ng/nsbc-quickjs-ng.c
238+
cat >> quickjs-ng/CMakeLists.txt <<'CMAKE'
239+
240+
add_executable(nsbc-quickjs-ng nsbc-quickjs-ng.c)
241+
target_link_libraries(nsbc-quickjs-ng PRIVATE qjs)
242+
target_compile_definitions(nsbc-quickjs-ng PRIVATE NSBC_MAGIC=\"NSBCNGS\")
243+
CMAKE
233244
cmake -S quickjs-ng -B quickjs-ng/build -DCMAKE_BUILD_TYPE=Release
234-
cmake --build quickjs-ng/build --config Release --target qjs
235-
lib="$(find quickjs-ng/build -type f \( -name 'libqjs.a' -o -name 'qjs.lib' \) | head -n1)"
236-
test -n "$lib"
237-
# Windows has no libm (math is in the CRT); only pass -lm off-Windows.
238-
CC="cc"; LIBM="-lm"
239-
if [ "${{ runner.os }}" = "Windows" ]; then CC="clang"; LIBM=""; fi
245+
cmake --build quickjs-ng/build --config Release --target nsbc-quickjs-ng
240246
out="out/quickjs-ng/${{ matrix.host }}"; mkdir -p "$out"
241-
bin="$out/nsbc-quickjs-ng"; [ "${{ runner.os }}" = "Windows" ] && bin="$bin.exe"
242-
$CC -O2 -DNSBC_MAGIC='"NSBCNGS"' -I quickjs-ng -o "$bin" "$SHIM" "$lib" $LIBM
243-
"$bin" || true
247+
bin="$(find quickjs-ng/build -type f \( -name 'nsbc-quickjs-ng' -o -name 'nsbc-quickjs-ng.exe' \) | head -n1)"
248+
test -n "$bin"; cp "$bin" "$out/"
249+
[ "${{ runner.os }}" = "Windows" ] || "$out/nsbc-quickjs-ng" || true
244250
245251
- uses: actions/upload-artifact@v4
246252
with:
@@ -256,8 +262,8 @@ jobs:
256262
# Unix only, and NOT linux-arm64: PrimJS's envsetup.sh aborts on Windows, and
257263
# its DEPS only provides a linux sysroot for x86_64. So: linux-x64 + macOS.
258264
#
259-
# NOTE: this is the first automated PrimJS build; `hab sync` pulls a large
260-
# toolchain and the exact gn/ninja target may need tweaking on the first run.
265+
# Validated locally on darwin-arm64 (hab sync -> gn gen -> ninja nsbc-primjs
266+
# produces a working CLI). Linux uses the same flow.
261267
# ---------------------------------------------------------------------------
262268
primjs:
263269
name: primjs (${{ matrix.host }})
@@ -291,18 +297,19 @@ jobs:
291297
SHIM: ${{ github.workspace }}/tools/bytecode-compiler/native/primjs-compile.c
292298
run: |
293299
set -euxo pipefail
294-
# Build as C++ (.cc) to match the working qjs-cli target; the LEPUS_*
295-
# API is extern "C", so linkage is fine either way.
300+
# Build as C++ (.cc); the LEPUS_* API is extern "C" so linkage is fine.
296301
cp "$SHIM" primjs/tools/qjs-cli/nsbc-primjs.cc
297-
# A standalone executable that links the same engine as qjs-cli.
298-
cat >> primjs/tools/qjs-cli/BUILD.gn <<'GN'
302+
# Add the target to the ROOT BUILD.gn (always loaded, so it's always
303+
# generated) linking ONLY the core engine (//src:quickjs_lib). We avoid
304+
# qjs_wasm_binding — its WASM/JSC code doesn't build under the bundled
305+
# toolchain's -Werror, and our shim doesn't need it. (Validated locally.)
306+
cat >> primjs/BUILD.gn <<'GN'
299307
300308
executable("nsbc-primjs") {
301309
cflags = [ "-Wno-c99-designator" ]
302-
sources = [ "nsbc-primjs.cc" ]
310+
sources = [ "//tools/qjs-cli/nsbc-primjs.cc" ]
303311
include_dirs = [ "//include" ]
304-
deps = [ ":qjs_wasm_binding" ]
305-
configs += [ ":wasm_internal_config" ]
312+
deps = [ "//src:quickjs_lib" ]
306313
}
307314
GN
308315

0 commit comments

Comments
 (0)