Refactor Python scripts in build.rs

This commit is contained in:
kngwyu 2021-02-20 15:31:25 +09:00
parent f1fc17cbf0
commit 89f555f506
1 changed files with 19 additions and 19 deletions

View File

@ -318,18 +318,18 @@ fn parse_sysconfigdata(config_path: impl AsRef<Path>) -> Result<HashMap<String,
script += r#" script += r#"
print("version_major", build_time_vars["VERSION"][0]) # 3 print("version_major", build_time_vars["VERSION"][0]) # 3
print("version_minor", build_time_vars["VERSION"][2]) # E.g., 8 print("version_minor", build_time_vars["VERSION"][2]) # E.g., 8
if "WITH_THREAD" in build_time_vars: KEYS = [
print("WITH_THREAD", build_time_vars["WITH_THREAD"]) "WITH_THREAD",
if "Py_TRACE_REFS" in build_time_vars: "Py_DEBUG",
print("Py_TRACE_REFS", build_time_vars["Py_TRACE_REFS"]) "Py_REF_DEBUG",
if "COUNT_ALLOCS" in build_time_vars: "Py_TRACE_REFS",
print("COUNT_ALLOCS", build_time_vars["COUNT_ALLOCS"]) "COUNT_ALLOCS",
if "Py_REF_DEBUG" in build_time_vars: "Py_ENABLE_SHARED",
print("Py_REF_DEBUG", build_time_vars["Py_REF_DEBUG"]) "LDVERSION",
print("Py_DEBUG", build_time_vars["Py_DEBUG"]) "SIZEOF_VOID_P"
print("Py_ENABLE_SHARED", build_time_vars["Py_ENABLE_SHARED"]) ]
print("LDVERSION", build_time_vars["LDVERSION"]) for key in KEYS:
print("SIZEOF_VOID_P", build_time_vars["SIZEOF_VOID_P"]) print(key, build_time_vars.get(key, 0))
"#; "#;
let output = run_python_script(&find_interpreter()?, &script)?; let output = run_python_script(&find_interpreter()?, &script)?;
@ -690,30 +690,30 @@ fn find_interpreter_and_get_config() -> Result<(InterpreterConfig, BuildFlags)>
/// Extract compilation vars from the specified interpreter. /// Extract compilation vars from the specified interpreter.
fn get_config_from_interpreter(interpreter: &Path) -> Result<InterpreterConfig> { fn get_config_from_interpreter(interpreter: &Path) -> Result<InterpreterConfig> {
let script = r#" let script = r#"
import os.path
import platform import platform
import struct import struct
import sys import sys
import sysconfig from sysconfig import get_config_var
import os.path
PYPY = platform.python_implementation() == "PyPy" PYPY = platform.python_implementation() == "PyPy"
# Anaconda based python distributions have a static python executable, but include # Anaconda based python distributions have a static python executable, but include
# the shared library. Use the shared library for embedding to avoid rust trying to # the shared library. Use the shared library for embedding to avoid rust trying to
# LTO the static library (and failing with newer gcc's, because it is old). # LTO the static library (and failing with newer gcc's, because it is old).
ANACONDA = os.path.exists(os.path.join(sys.base_prefix, 'conda-meta')) ANACONDA = os.path.exists(os.path.join(sys.base_prefix, "conda-meta"))
libdir = sysconfig.get_config_var('LIBDIR') libdir = get_config_var("LIBDIR")
print("version_major", sys.version_info[0]) print("version_major", sys.version_info[0])
print("version_minor", sys.version_info[1]) print("version_minor", sys.version_info[1])
print("implementation", platform.python_implementation()) print("implementation", platform.python_implementation())
if libdir is not None: if libdir is not None:
print("libdir", libdir) print("libdir", libdir)
print("ld_version", sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')) print("ld_version", get_config_var("LDVERSION") or get_config_var("py_version_short"))
print("base_prefix", sys.base_prefix) print("base_prefix", sys.base_prefix)
print("framework", bool(sysconfig.get_config_var('PYTHONFRAMEWORK'))) print("framework", bool(get_config_var("PYTHONFRAMEWORK")))
print("shared", PYPY or ANACONDA or bool(sysconfig.get_config_var('Py_ENABLE_SHARED'))) print("shared", PYPY or ANACONDA or bool(get_config_var("Py_ENABLE_SHARED")))
print("executable", sys.executable) print("executable", sys.executable)
print("calcsize_pointer", struct.calcsize("P")) print("calcsize_pointer", struct.calcsize("P"))
"#; "#;