forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_sysconfigdata.rs
More file actions
75 lines (67 loc) · 2.83 KB
/
_sysconfigdata.rs
File metadata and controls
75 lines (67 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// spell-checker: words LDSHARED ARFLAGS CPPFLAGS CCSHARED BASECFLAGS BLDSHARED
pub(crate) use _sysconfigdata::module_def;
#[pymodule]
mod _sysconfigdata {
use crate::stdlib::sys::{RUST_MULTIARCH, multiarch, sysconfigdata_name};
use crate::{
Py, PyResult, VirtualMachine,
builtins::{PyDictRef, PyModule},
convert::ToPyObject,
};
fn module_exec(vm: &VirtualMachine, module: &Py<PyModule>) -> PyResult<()> {
// Set build_time_vars attribute
let build_time_vars = build_time_vars(vm);
// Add runtime-dependent values needed by sysconfig
let paths = &vm.state.config.paths;
build_time_vars.set_item("prefix", paths.prefix.clone().to_pyobject(vm), vm)?;
build_time_vars.set_item("exec_prefix", paths.exec_prefix.clone().to_pyobject(vm), vm)?;
let bindir = format!("{}/bin", &paths.exec_prefix);
build_time_vars.set_item("BINDIR", bindir.to_pyobject(vm), vm)?;
module.set_attr("build_time_vars", build_time_vars, vm)?;
// Ensure the module is registered under the platform-specific name
// (import_builtin() already handles this, but double-check for safety)
let sys_modules = vm.sys_module.get_attr("modules", vm)?;
let sysconfigdata_name = sysconfigdata_name();
sys_modules.set_item(sysconfigdata_name.as_str(), module.to_owned().into(), vm)?;
Ok(())
}
#[pyattr]
fn build_time_vars(vm: &VirtualMachine) -> PyDictRef {
let vars = vm.ctx.new_dict();
let multiarch = multiarch();
macro_rules! sysvars {
($($key:literal => $value:expr),*$(,)?) => {{
$(vars.set_item($key, $value.to_pyobject(vm), vm).unwrap();)*
}};
}
sysvars! {
// Extension module suffix in CPython-compatible format
"EXT_SUFFIX" => format!(".rustpython313-{multiarch}.so"),
"MULTIARCH" => multiarch.clone(),
"RUST_MULTIARCH" => RUST_MULTIARCH,
// enough for tests to stop expecting urandom() to fail after restricting file resources
"HAVE_GETRANDOM" => 1,
// RustPython has no GIL (like free-threaded Python)
"Py_GIL_DISABLED" => 1,
"Py_DEBUG" => 0,
"ABIFLAGS" => "t",
// Compiler configuration for native extension builds
"CC" => "cc",
"CXX" => "c++",
"CFLAGS" => "",
"CPPFLAGS" => "",
"LDFLAGS" => "",
"LDSHARED" => "cc -shared",
"CCSHARED" => "",
"SHLIB_SUFFIX" => ".so",
"SO" => ".so",
"AR" => "ar",
"ARFLAGS" => "rcs",
"OPT" => "",
"BASECFLAGS" => "",
"BLDSHARED" => "cc -shared",
}
include!(concat!(env!("OUT_DIR"), "/env_vars.rs"));
vars
}
}