From 2b06f507fa8825581e40e1b0e6fa93b9739da904 Mon Sep 17 00:00:00 2001 From: EtherealPsyche Date: Thu, 12 Mar 2026 14:35:33 +0800 Subject: [PATCH 1/2] Add feature `ctypes` to force enable _ctypes module --- Cargo.toml | 1 + crates/stdlib/Cargo.toml | 1 + crates/vm/Cargo.toml | 54 ++++++++++++++++++++----------------- crates/vm/src/stdlib/mod.rs | 22 +++++++++------ 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 545d85982d5..46b1e1ddd8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ license.workspace = true [features] default = ["threading", "stdlib", "stdio", "importlib", "ssl-rustls", "host_env"] host_env = ["rustpython-vm/host_env", "rustpython-stdlib?/host_env"] +ctypes = ["rustpython-vm/ctypes"] importlib = ["rustpython-vm/importlib"] encodings = ["rustpython-vm/encodings"] stdio = ["rustpython-vm/stdio"] diff --git a/crates/stdlib/Cargo.toml b/crates/stdlib/Cargo.toml index 36967095639..4427d3329ac 100644 --- a/crates/stdlib/Cargo.toml +++ b/crates/stdlib/Cargo.toml @@ -12,6 +12,7 @@ license.workspace = true [features] default = ["compiler", "host_env"] +ctypes = ["rustpython-vm/ctypes"] host_env = ["rustpython-vm/host_env"] compiler = ["rustpython-vm/compiler"] threading = ["rustpython-common/threading", "rustpython-vm/threading"] diff --git a/crates/vm/Cargo.toml b/crates/vm/Cargo.toml index 78b1608673e..561a2ae51e4 100644 --- a/crates/vm/Cargo.toml +++ b/crates/vm/Cargo.toml @@ -12,6 +12,7 @@ license.workspace = true [features] default = ["compiler", "wasmbind", "gc", "host_env", "stdio"] host_env = [] +ctypes = ["dep:libffi", "dep:libloading"] stdio = [] importlib = [] encodings = ["importlib"] @@ -83,6 +84,9 @@ optional = { workspace = true } result-like = "0.5.0" timsort = "0.1.2" +libffi = { workspace = true, features = ["system"], optional = true } +libloading = { version = "0.9", optional = true } + ## unicode stuff # TODO: use unic for this; needed for title case: # https://github.com/RustPython/RustPython/pull/832#discussion_r275428939 @@ -117,31 +121,31 @@ junction = { workspace = true } [target.'cfg(windows)'.dependencies.windows-sys] workspace = true features = [ - "Win32_Foundation", - "Win32_Globalization", - "Win32_Media_Audio", - "Win32_Networking_WinSock", - "Win32_Security", - "Win32_Security_Authorization", - "Win32_Storage_FileSystem", - "Win32_System_Console", - "Win32_System_Diagnostics_Debug", - "Win32_System_Environment", - "Win32_System_IO", - "Win32_System_Ioctl", - "Win32_System_Kernel", - "Win32_System_LibraryLoader", - "Win32_System_Memory", - "Win32_System_Performance", - "Win32_System_Pipes", - "Win32_System_Registry", - "Win32_System_SystemInformation", - "Win32_System_SystemServices", - "Win32_System_Threading", - "Win32_System_Time", - "Win32_System_WindowsProgramming", - "Win32_UI_Shell", - "Win32_UI_WindowsAndMessaging", + "Win32_Foundation", + "Win32_Globalization", + "Win32_Media_Audio", + "Win32_Networking_WinSock", + "Win32_Security", + "Win32_Security_Authorization", + "Win32_Storage_FileSystem", + "Win32_System_Console", + "Win32_System_Diagnostics_Debug", + "Win32_System_Environment", + "Win32_System_IO", + "Win32_System_Ioctl", + "Win32_System_Kernel", + "Win32_System_LibraryLoader", + "Win32_System_Memory", + "Win32_System_Performance", + "Win32_System_Pipes", + "Win32_System_Registry", + "Win32_System_SystemInformation", + "Win32_System_SystemServices", + "Win32_System_Threading", + "Win32_System_Time", + "Win32_System_WindowsProgramming", + "Win32_UI_Shell", + "Win32_UI_WindowsAndMessaging", ] [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] diff --git a/crates/vm/src/stdlib/mod.rs b/crates/vm/src/stdlib/mod.rs index 42514c46dda..efde0eba089 100644 --- a/crates/vm/src/stdlib/mod.rs +++ b/crates/vm/src/stdlib/mod.rs @@ -38,10 +38,13 @@ pub mod posix; #[path = "posix_compat.rs"] pub mod posix; -#[cfg(all( - feature = "host_env", - any(target_os = "linux", target_os = "macos", target_os = "windows"), - not(any(target_env = "musl", target_env = "sgx")) +#[cfg(any( + feature = "ctypes", + all( + feature = "host_env", + any(target_os = "linux", target_os = "macos", target_os = "windows"), + not(any(target_env = "musl", target_env = "sgx")) + ) ))] mod _ctypes; #[cfg(all(feature = "host_env", windows))] @@ -85,10 +88,13 @@ pub fn builtin_module_defs(ctx: &Context) -> Vec<&'static PyModuleDef> { atexit::module_def(ctx), _codecs::module_def(ctx), _collections::module_def(ctx), - #[cfg(all( - feature = "host_env", - any(target_os = "linux", target_os = "macos", target_os = "windows"), - not(any(target_env = "musl", target_env = "sgx")) + #[cfg(any( + feature = "ctypes", + all( + feature = "host_env", + any(target_os = "linux", target_os = "macos", target_os = "windows"), + not(any(target_env = "musl", target_env = "sgx")) + ) ))] _ctypes::module_def(ctx), errno::module_def(ctx), From 8b3264e70f936805682a9628b0afb85505dee41c Mon Sep 17 00:00:00 2001 From: EtherealPsyche Date: Thu, 12 Mar 2026 21:37:37 +0800 Subject: [PATCH 2/2] Remove feature `ctypes` and just add `target_os = "android"` to avoid introducing a new feature --- Cargo.toml | 1 - crates/stdlib/Cargo.toml | 1 - crates/vm/Cargo.toml | 56 +++++++++++++++++-------------------- crates/vm/src/stdlib/mod.rs | 32 +++++++++++---------- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 46b1e1ddd8f..545d85982d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ license.workspace = true [features] default = ["threading", "stdlib", "stdio", "importlib", "ssl-rustls", "host_env"] host_env = ["rustpython-vm/host_env", "rustpython-stdlib?/host_env"] -ctypes = ["rustpython-vm/ctypes"] importlib = ["rustpython-vm/importlib"] encodings = ["rustpython-vm/encodings"] stdio = ["rustpython-vm/stdio"] diff --git a/crates/stdlib/Cargo.toml b/crates/stdlib/Cargo.toml index 4427d3329ac..36967095639 100644 --- a/crates/stdlib/Cargo.toml +++ b/crates/stdlib/Cargo.toml @@ -12,7 +12,6 @@ license.workspace = true [features] default = ["compiler", "host_env"] -ctypes = ["rustpython-vm/ctypes"] host_env = ["rustpython-vm/host_env"] compiler = ["rustpython-vm/compiler"] threading = ["rustpython-common/threading", "rustpython-vm/threading"] diff --git a/crates/vm/Cargo.toml b/crates/vm/Cargo.toml index 561a2ae51e4..5f7e901b834 100644 --- a/crates/vm/Cargo.toml +++ b/crates/vm/Cargo.toml @@ -12,7 +12,6 @@ license.workspace = true [features] default = ["compiler", "wasmbind", "gc", "host_env", "stdio"] host_env = [] -ctypes = ["dep:libffi", "dep:libloading"] stdio = [] importlib = [] encodings = ["importlib"] @@ -84,9 +83,6 @@ optional = { workspace = true } result-like = "0.5.0" timsort = "0.1.2" -libffi = { workspace = true, features = ["system"], optional = true } -libloading = { version = "0.9", optional = true } - ## unicode stuff # TODO: use unic for this; needed for title case: # https://github.com/RustPython/RustPython/pull/832#discussion_r275428939 @@ -108,7 +104,7 @@ which = "8" errno = "0.3" widestring = { workspace = true } -[target.'cfg(all(any(target_os = "linux", target_os = "macos", target_os = "windows"), not(any(target_env = "musl", target_env = "sgx"))))'.dependencies] +[target.'cfg(all(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"), not(any(target_env = "musl", target_env = "sgx"))))'.dependencies] libffi = { workspace = true, features = ["system"] } libloading = "0.9" @@ -121,31 +117,31 @@ junction = { workspace = true } [target.'cfg(windows)'.dependencies.windows-sys] workspace = true features = [ - "Win32_Foundation", - "Win32_Globalization", - "Win32_Media_Audio", - "Win32_Networking_WinSock", - "Win32_Security", - "Win32_Security_Authorization", - "Win32_Storage_FileSystem", - "Win32_System_Console", - "Win32_System_Diagnostics_Debug", - "Win32_System_Environment", - "Win32_System_IO", - "Win32_System_Ioctl", - "Win32_System_Kernel", - "Win32_System_LibraryLoader", - "Win32_System_Memory", - "Win32_System_Performance", - "Win32_System_Pipes", - "Win32_System_Registry", - "Win32_System_SystemInformation", - "Win32_System_SystemServices", - "Win32_System_Threading", - "Win32_System_Time", - "Win32_System_WindowsProgramming", - "Win32_UI_Shell", - "Win32_UI_WindowsAndMessaging", + "Win32_Foundation", + "Win32_Globalization", + "Win32_Media_Audio", + "Win32_Networking_WinSock", + "Win32_Security", + "Win32_Security_Authorization", + "Win32_Storage_FileSystem", + "Win32_System_Console", + "Win32_System_Diagnostics_Debug", + "Win32_System_Environment", + "Win32_System_IO", + "Win32_System_Ioctl", + "Win32_System_Kernel", + "Win32_System_LibraryLoader", + "Win32_System_Memory", + "Win32_System_Performance", + "Win32_System_Pipes", + "Win32_System_Registry", + "Win32_System_SystemInformation", + "Win32_System_SystemServices", + "Win32_System_Threading", + "Win32_System_Time", + "Win32_System_WindowsProgramming", + "Win32_UI_Shell", + "Win32_UI_WindowsAndMessaging", ] [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] diff --git a/crates/vm/src/stdlib/mod.rs b/crates/vm/src/stdlib/mod.rs index efde0eba089..97fb4b372cf 100644 --- a/crates/vm/src/stdlib/mod.rs +++ b/crates/vm/src/stdlib/mod.rs @@ -38,13 +38,15 @@ pub mod posix; #[path = "posix_compat.rs"] pub mod posix; -#[cfg(any( - feature = "ctypes", - all( - feature = "host_env", - any(target_os = "linux", target_os = "macos", target_os = "windows"), - not(any(target_env = "musl", target_env = "sgx")) - ) +#[cfg(all( + feature = "host_env", + any( + target_os = "linux", + target_os = "macos", + target_os = "windows", + target_os = "android" + ), + not(any(target_env = "musl", target_env = "sgx")) ))] mod _ctypes; #[cfg(all(feature = "host_env", windows))] @@ -88,13 +90,15 @@ pub fn builtin_module_defs(ctx: &Context) -> Vec<&'static PyModuleDef> { atexit::module_def(ctx), _codecs::module_def(ctx), _collections::module_def(ctx), - #[cfg(any( - feature = "ctypes", - all( - feature = "host_env", - any(target_os = "linux", target_os = "macos", target_os = "windows"), - not(any(target_env = "musl", target_env = "sgx")) - ) + #[cfg(all( + feature = "host_env", + any( + target_os = "linux", + target_os = "macos", + target_os = "windows", + target_os = "android" + ), + not(any(target_env = "musl", target_env = "sgx")) ))] _ctypes::module_def(ctx), errno::module_def(ctx),