diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 119fc8e89..c49fe2d31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,6 +215,39 @@ jobs: cl.exe /DJS_NAN_BOXING=1 /Zs cxxtest.cc windows-clang: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + buildType: [Debug, Release] + steps: + - uses: actions/checkout@v4 + - name: install ninja + run: | + choco install ninja + ninja.exe --version + - name: build + run: | + git submodule update --init --checkout --depth 1 + cmake -B build -DQJS_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{matrix.buildType}} -DCMAKE_C_COMPILER=clang.exe -G "Ninja" + cmake --build build --config ${{matrix.buildType}} + - name: stats + run: | + build\qjs.exe -qd + - name: cxxtest + run: | + clang.exe -D JS_NAN_BOXING=0 -fsyntax-only cxxtest.cc + clang.exe -D JS_NAN_BOXING=1 -fsyntax-only cxxtest.cc + - name: test + run: | + cp build\fib.dll examples\ + cp build\point.dll examples\ + build\qjs.exe examples\test_fib.js + build\qjs.exe examples\test_point.js + build\run-test262.exe -c tests.conf + build\function_source.exe + + windows-clang-cl: runs-on: windows-latest strategy: fail-fast: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 88e98bb0c..df9ed1648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,13 @@ xcheck_add_c_compiler_flag(-Wno-stringop-truncation) xcheck_add_c_compiler_flag(-Wno-array-bounds) xcheck_add_c_compiler_flag(-funsigned-char) +# Clang on Windows without MSVC command line fails because the codebase uses +# functions like strcpy over strcpy_s +if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND WIN32 AND NOT MSVC) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) +endif() + # ClangCL is command line compatible with MSVC, so 'MSVC' is set. if(MSVC) xcheck_add_c_compiler_flag(-Wno-unsafe-buffer-usage) @@ -90,6 +97,10 @@ endif() if(WIN32) if(MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8388608") + elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") + # Clang on Windows uses Windows' default linker, but requires GCC-style + # -Wl to specify a linker argument + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,/STACK:8388608") else() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,8388608") endif() diff --git a/cutils.h b/cutils.h index 50fee11a1..149c421e4 100644 --- a/cutils.h +++ b/cutils.h @@ -106,7 +106,8 @@ extern "C" { /* Borrowed from Folly */ #ifndef JS_PRINTF_FORMAT -#ifdef _MSC_VER +/* Clang on Windows doesn't seem to support _Printf_format_string_ */ +#if defined(_MSC_VER) && !defined(__clang__) #include #define JS_PRINTF_FORMAT _Printf_format_string_ #define JS_PRINTF_FORMAT_ATTR(format_param, dots_param) diff --git a/quickjs-libc.c b/quickjs-libc.c index 6082b7465..5dcd67668 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -208,10 +208,11 @@ static void js_set_thread_state(JSRuntime *rt, JSThreadState *ts) js_std_cmd(/*SetOpaque*/1, rt, ts); } -#ifdef __GNUC__ +// Non-CL Clang on Windows does not define __GNUC__ +#if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif // __GNUC__ +#endif // __GNUC__ || __clang__ static JSValue js_printf_internal(JSContext *ctx, int argc, JSValueConst *argv, FILE *fp) { @@ -427,9 +428,9 @@ static JSValue js_printf_internal(JSContext *ctx, dbuf_free(&dbuf); return JS_EXCEPTION; } -#ifdef __GNUC__ +#if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop // ignored "-Wformat-nonliteral" -#endif // __GNUC__ +#endif // __GNUC__ || __clang__ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename) { diff --git a/quickjs.c b/quickjs.c index b6277b562..c90e00c21 100644 --- a/quickjs.c +++ b/quickjs.c @@ -7044,7 +7044,7 @@ static int JS_PRINTF_FORMAT_ATTR(3, 4) JS_ThrowTypeErrorOrFalse(JSContext *ctx, } } -#ifdef __GNUC__ +#if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif // __GNUC__ @@ -7061,7 +7061,7 @@ static JSValue JS_ThrowSyntaxErrorAtom(JSContext *ctx, const char *fmt, JSAtom a JS_AtomGetStr(ctx, buf, sizeof(buf), atom); return JS_ThrowSyntaxError(ctx, fmt, buf); } -#ifdef __GNUC__ +#if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop // ignored "-Wformat-nonliteral" #endif // __GNUC__ diff --git a/quickjs.h b/quickjs.h index 59c4956fd..41b89fa44 100644 --- a/quickjs.h +++ b/quickjs.h @@ -49,7 +49,8 @@ extern "C" { /* Borrowed from Folly */ #ifndef JS_PRINTF_FORMAT -#ifdef _MSC_VER +/* Clang on Windows doesn't seem to support _Printf_format_string_ */ +#if defined(_MSC_VER) && !defined(__clang__) #include #define JS_PRINTF_FORMAT _Printf_format_string_ #define JS_PRINTF_FORMAT_ATTR(format_param, dots_param)