Skip to content

Commit 01bce21

Browse files
authored
Support for non-CL Clang on Windows
1 parent a9e4b27 commit 01bce21

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,39 @@ jobs:
221221
cl.exe /DJS_NAN_BOXING=1 /Zs cxxtest.cc
222222
223223
windows-clang:
224+
runs-on: windows-latest
225+
strategy:
226+
fail-fast: false
227+
matrix:
228+
buildType: [Debug, Release]
229+
steps:
230+
- uses: actions/checkout@v6
231+
- name: install ninja
232+
run: |
233+
choco install ninja
234+
ninja.exe --version
235+
- name: build
236+
run: |
237+
git submodule update --init --checkout --depth 1
238+
cmake -B build -DQJS_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{matrix.buildType}} -DCMAKE_C_COMPILER=clang.exe -G "Ninja"
239+
cmake --build build --config ${{matrix.buildType}}
240+
- name: stats
241+
run: |
242+
build\qjs.exe -qd
243+
- name: cxxtest
244+
run: |
245+
clang.exe -D JS_NAN_BOXING=0 -fsyntax-only cxxtest.cc
246+
clang.exe -D JS_NAN_BOXING=1 -fsyntax-only cxxtest.cc
247+
- name: test
248+
run: |
249+
cp build\fib.dll examples\
250+
cp build\point.dll examples\
251+
build\qjs.exe examples\test_fib.js
252+
build\qjs.exe examples\test_point.js
253+
build\run-test262.exe -c tests.conf
254+
build\function_source.exe
255+
256+
windows-clang-cl:
224257
runs-on: windows-latest
225258
strategy:
226259
fail-fast: false

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ if(NOT SUNOS)
108108
xcheck_add_c_compiler_flag(-funsigned-char)
109109
endif()
110110

111+
# Clang on Windows without MSVC command line fails because the codebase uses
112+
# functions like strcpy over strcpy_s
113+
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND WIN32 AND NOT MSVC)
114+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
115+
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
116+
endif()
117+
111118
# ClangCL is command line compatible with MSVC, so 'MSVC' is set.
112119
if(MSVC)
113120
xcheck_add_c_compiler_flag(-Wno-unsafe-buffer-usage)

cutils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ extern "C" {
110110

111111
/* Borrowed from Folly */
112112
#ifndef JS_PRINTF_FORMAT
113-
#ifdef _MSC_VER
113+
/* Clang on Windows doesn't seem to support _Printf_format_string_ */
114+
#if defined(_MSC_VER) && !defined(__clang__)
114115
#include <sal.h>
115116
#define JS_PRINTF_FORMAT _Printf_format_string_
116117
#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param)

quickjs-libc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ static void js_set_thread_state(JSRuntime *rt, JSThreadState *ts)
227227
js_std_cmd(/*SetOpaque*/1, rt, ts);
228228
}
229229

230-
#ifdef __GNUC__
230+
// Non-CL Clang on Windows does not define __GNUC__
231+
#if defined(__GNUC__) || defined(__clang__)
231232
#pragma GCC diagnostic push
232233
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
233-
#endif // __GNUC__
234+
#endif // __GNUC__ || __clang__
234235
static JSValue js_printf_internal(JSContext *ctx,
235236
int argc, JSValueConst *argv, FILE *fp)
236237
{
@@ -446,9 +447,9 @@ static JSValue js_printf_internal(JSContext *ctx,
446447
dbuf_free(&dbuf);
447448
return JS_EXCEPTION;
448449
}
449-
#ifdef __GNUC__
450+
#if defined(__GNUC__) || defined(__clang__)
450451
#pragma GCC diagnostic pop // ignored "-Wformat-nonliteral"
451-
#endif // __GNUC__
452+
#endif // __GNUC__ || __clang__
452453

453454
uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
454455
{

quickjs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8042,7 +8042,7 @@ static int JS_PRINTF_FORMAT_ATTR(3, 4) JS_ThrowTypeErrorOrFalse(JSContext *ctx,
80428042
}
80438043
}
80448044

8045-
#ifdef __GNUC__
8045+
#if defined(__GNUC__) || defined(__clang__)
80468046
#pragma GCC diagnostic push
80478047
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
80488048
#endif // __GNUC__
@@ -8059,7 +8059,7 @@ static JSValue JS_ThrowSyntaxErrorAtom(JSContext *ctx, const char *fmt, JSAtom a
80598059
JS_AtomGetStr(ctx, buf, sizeof(buf), atom);
80608060
return JS_ThrowSyntaxError(ctx, fmt, buf);
80618061
}
8062-
#ifdef __GNUC__
8062+
#if defined(__GNUC__) || defined(__clang__)
80638063
#pragma GCC diagnostic pop // ignored "-Wformat-nonliteral"
80648064
#endif // __GNUC__
80658065

quickjs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ extern "C" {
118118

119119
/* Borrowed from Folly */
120120
#ifndef JS_PRINTF_FORMAT
121-
#ifdef _MSC_VER
121+
/* Clang on Windows doesn't seem to support _Printf_format_string_ */
122+
#if defined(_MSC_VER) && !defined(__clang__)
122123
#include <sal.h>
123124
#define JS_PRINTF_FORMAT _Printf_format_string_
124125
#define JS_PRINTF_FORMAT_ATTR(format_param, dots_param)

0 commit comments

Comments
 (0)