From 901fa3130955679be3a6fd9354b07771a2b662d3 Mon Sep 17 00:00:00 2001 From: Zhou Qiankang Date: Thu, 4 Dec 2025 19:22:22 +0800 Subject: [PATCH] build: add windows mingw-w64 compatibility Signed-off-by: Zhou Qiankang --- binding.gyp | 17 ++++++++--------- setup.py | 8 ++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/binding.gyp b/binding.gyp index e678f54e..5009aad6 100644 --- a/binding.gyp +++ b/binding.gyp @@ -13,18 +13,17 @@ "src/parser.c", "src/scanner.c", ], - "conditions": [ - ["OS!='win'", { - "cflags_c": [ - "-std=c11", - ], - }, { # OS == "win" - "cflags_c": [ + "cflags_c": [ + "-std=c11", + ], + "msvs_settings": { + "VCCLCompilerTool": { + "AdditionalOptions": [ "/std:c11", "/utf-8", ], - }], - ], + }, + }, } ] } diff --git a/setup.py b/setup.py index f038a5fe..db5c534c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from os import path -from platform import system from sysconfig import get_config_var +from distutils.ccompiler import new_compiler from setuptools import Extension, find_packages, setup from setuptools.command.build import build @@ -21,10 +21,10 @@ if limited_api := not get_config_var("Py_GIL_DISABLED"): macros.append(("Py_LIMITED_API", "0x030A0000")) -if system() != "Windows": - cflags = ["-std=c11", "-fvisibility=hidden"] -else: +if new_compiler().compiler_type == "msvc": cflags = ["/std:c11", "/utf-8"] +else: + cflags = ["-std=c11", "-fvisibility=hidden"] class Build(build):