fix(bindings): improve python platform detection

(cherry picked from commit 99988b7081)
This commit is contained in:
ObserverOfTime 2025-05-22 08:44:03 +03:00 committed by Will Lillis
parent e920009d60
commit 3c0088f037
2 changed files with 8 additions and 4 deletions

View file

@ -624,10 +624,15 @@ pub fn generate_grammar_files(
allow_update,
|path| generate_file(path, SETUP_PY_TEMPLATE, language_name, &generate_opts),
|path| {
let contents = fs::read_to_string(path)?;
let mut contents = fs::read_to_string(path)?;
if !contents.contains("egg_info") || !contents.contains("Py_GIL_DISABLED") {
eprintln!("Replacing setup.py");
generate_file(path, SETUP_PY_TEMPLATE, language_name, &generate_opts)?;
} else {
contents = contents
.replace("path\nfrom platform import system", "name as os_name, path")
.replace("system() != \"Windows\"", "os_name != \"nt\"");
write_file(path, contents)?;
}
Ok(())
},

View file

@ -1,5 +1,4 @@
from os import path
from platform import system
from os import name as os_name, path
from sysconfig import get_config_var
from setuptools import Extension, find_packages, setup
@ -21,7 +20,7 @@ macros: list[tuple[str, str | None]] = [
if limited_api := not get_config_var("Py_GIL_DISABLED"):
macros.append(("Py_LIMITED_API", "0x030A0000"))
if system() != "Windows":
if os_name != "nt":
cflags = ["-std=c11", "-fvisibility=hidden"]
else:
cflags = ["/std:c11", "/utf-8"]