If the host_env feature is enabled, then enable the _ctypes module on the Android platform.#7402
If the host_env feature is enabled, then enable the _ctypes module on the Android platform.#7402youknowone merged 2 commits into
host_env feature is enabled, then enable the _ctypes module on the Android platform.#7402Conversation
📝 WalkthroughWalkthroughThe pull request adds Android platform support to the RustPython VM by extending platform-specific target dependencies and module configurations to include the Android operating system alongside Linux, macOS, and Windows. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan for PR comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
Cargo.toml (1)
15-15: Consider propagating torustpython-stdlibfor consistency.Other features like
host_env(line 14) propagate to bothrustpython-vmandrustpython-stdlib:host_env = ["rustpython-vm/host_env", "rustpython-stdlib?/host_env"]While
ctypesonly propagates torustpython-vm. Sincerustpython-stdlib/ctypesjust forwards torustpython-vm/ctypes, this works correctly, but for consistency you might consider:ctypes = ["rustpython-vm/ctypes", "rustpython-stdlib?/ctypes"]This is a minor consistency suggestion and not required for correctness.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Cargo.toml` at line 15, Update the Cargo.toml feature entry for "ctypes" so it also propagates to rustpython-stdlib like other features do; specifically modify the "ctypes" feature definition (currently referencing "rustpython-vm/ctypes") to include the rustpython-stdlib propagation (add "rustpython-stdlib?/ctypes") so the feature list becomes ["rustpython-vm/ctypes", "rustpython-stdlib?/ctypes"] and maintains consistency with other features such as "host_env".crates/vm/Cargo.toml (1)
87-88: Potential redundancy with target-specific dependencies.These optional dependencies overlap with the non-optional target-specific dependencies on lines 111-113:
[target.'cfg(all(any(target_os = "linux", target_os = "macos", target_os = "windows"), not(any(target_env = "musl", target_env = "sgx"))))'.dependencies] libffi = { workspace = true, features = ["system"] } libloading = "0.9"On supported platforms (Linux/macOS/Windows, non-musl, non-SGX),
libffiandlibloadingare always included regardless of thectypesfeature. The optional deps here are only meaningful for platforms outside that target condition where a user explicitly enables--features ctypes.This design works but creates a subtle distinction: the
ctypesfeature is only necessary for "unsupported" platforms. Consider adding a comment to clarify this intent.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/vm/Cargo.toml` around lines 87 - 88, The optional dependencies libffi and libloading declared in the crate root (libffi = { workspace = true, features = ["system"], optional = true } and libloading = { version = "0.9", optional = true }) overlap with the non-optional target-specific dependencies under the target.'cfg(... )'.dependencies block, so add a brief comment above the optional deps explaining that they exist to enable the "ctypes" feature on unsupported platforms (i.e., when the target cfg does not match Linux/macOS/Windows non-musl/non-SGX) and that on supported platforms the target-specific section will always supply these crates regardless of the ctypes feature.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/vm/src/stdlib/mod.rs`:
- Around line 41-49: Document that enabling the "ctypes" feature bypasses the
platform guards around the mod _ctypes and therefore may try to build
dependencies (libffi, libloading) that are unsupported on musl and SGX targets;
update Cargo.toml (feature description for "ctypes") and/or the README to
explicitly state the platform constraints and the potential for compile errors
on musl/SGX when users pass --features ctypes, and mention that the conditional
cfg(any(feature = "ctypes", ...)) in mod _ctypes is the reason this opt-in can
override the target checks.
---
Nitpick comments:
In `@Cargo.toml`:
- Line 15: Update the Cargo.toml feature entry for "ctypes" so it also
propagates to rustpython-stdlib like other features do; specifically modify the
"ctypes" feature definition (currently referencing "rustpython-vm/ctypes") to
include the rustpython-stdlib propagation (add "rustpython-stdlib?/ctypes") so
the feature list becomes ["rustpython-vm/ctypes", "rustpython-stdlib?/ctypes"]
and maintains consistency with other features such as "host_env".
In `@crates/vm/Cargo.toml`:
- Around line 87-88: The optional dependencies libffi and libloading declared in
the crate root (libffi = { workspace = true, features = ["system"], optional =
true } and libloading = { version = "0.9", optional = true }) overlap with the
non-optional target-specific dependencies under the target.'cfg(...
)'.dependencies block, so add a brief comment above the optional deps explaining
that they exist to enable the "ctypes" feature on unsupported platforms (i.e.,
when the target cfg does not match Linux/macOS/Windows non-musl/non-SGX) and
that on supported platforms the target-specific section will always supply these
crates regardless of the ctypes feature.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 2641b466-5ad6-4df5-bee3-2485151d769b
📒 Files selected for processing (4)
Cargo.tomlcrates/stdlib/Cargo.tomlcrates/vm/Cargo.tomlcrates/vm/src/stdlib/mod.rs
Sorry, something went wrong.
psyche314
left a comment
There was a problem hiding this comment.
libffi can actually be used on Android systems, but why is the _ctypes module only enabled when
cfg(all(any(target_os = "linux", target_os = "macos", target_os = "windows"),
not(any(target_env = "musl", target_env = "sgx")))) is satisfied?
For example, Termux provides a libffi (-static) package that can be used to link against a precompiled libffi.
This modification was originally done on my Android phone using Termux, but I accidentally lost the original changes.
Now I have recreated the changes on my computer from memory and created a PR, so there may be mistakes (previously it worked fine when tested on Termux).
Sorry, something went wrong.
youknowone
left a comment
There was a problem hiding this comment.
I believe the ideal cfg for ctypes will be only cfg(feature = "host_env").
Could you please remove ctypes feature but add android (or termux) to the cfg condition? I believe it is not excluded by intend.
Sorry, something went wrong.
|
@youknowone should we start to officially support android as a platform? (like cpython does it from 3.13) |
Sorry, something went wrong.
ShaharNaveh
left a comment
There was a problem hiding this comment.
Just line @youknowone said, I don't see the benefit of having a feature of ctypes, but to gate it behind the host_env feature, unless we would want to go with a feature gate per module (which has it's pros&cons)
Sorry, something went wrong.
|
How do you define official and unofficial platform? If you mean enhancing CI to guarantee it works, I agree. |
Sorry, something went wrong.
https://peps.python.org/pep-0738/ And sure, I'll try to implement a CI step that checks CI on android as well |
Sorry, something went wrong.
… introducing a new feature
|
Okay, let's simply add |
Sorry, something went wrong.
ShaharNaveh
left a comment
There was a problem hiding this comment.
Looks great! tysm!
Sorry, something went wrong.
youknowone
left a comment
There was a problem hiding this comment.
Thank you so much! welcome to RustPython project
Sorry, something went wrong.
0f61464
into
RustPython:main
Mar 12, 2026
…e on the Android platform. (RustPython#7402)
…e on the Android platform. (RustPython#7402)
Summary by CodeRabbit
New Features
Chores