当前位置: 首页 > news >正文

【RustPython】 RustPython Cargo.toml 配置文件详解

[package] 包基本信息

[package]
name = "rustpython"
description = "A python interpreter written in rust."
include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

解释:

  • name: 包名为 rustpython
  • description: 项目描述 - “用 Rust 编写的 Python 解释器”
  • include: 指定发布包时包含的文件(仅包含许可证、配置文件和源代码)
  • .workspace = true: 所有元数据都从工作空间统一继承,确保一致性

[features] 功能特性配置

[features]
default = ["threading", "stdlib", "stdio", "importlib"]
importlib = ["rustpython-vm/importlib"]
encodings = ["rustpython-vm/encodings"]
stdio = ["rustpython-vm/stdio"]
stdlib = ["rustpython-stdlib", "rustpython-pylib", "encodings"]
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
freeze-stdlib = ["stdlib", "rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
jit = ["rustpython-vm/jit"]
threading = ["rustpython-vm/threading", "rustpython-stdlib/threading"]
sqlite = ["rustpython-stdlib/sqlite"]
ssl = ["rustpython-stdlib/ssl"]
ssl-vendor = ["ssl", "rustpython-stdlib/ssl-vendor"]
tkinter = ["rustpython-stdlib/tkinter"]

核心特性说明:

  • default: 默认包含线程支持、标准库、标准IO和导入库功能
  • stdlib: 启用完整的 Python 标准库支持
  • jit: 启用实验性的即时编译功能
  • ssl: 启用 HTTPS/SSL 支持
  • freeze-stdlib: 将标准库编译进二进制文件(用于 WASM 部署)

[dependencies] 依赖关系

核心内部依赖

rustpython-compiler = { workspace = true }
rustpython-pylib = { workspace = true, optional = true }
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
rustpython-vm = { workspace = true, features = ["compiler"] }
ruff_python_parser = { workspace = true }

模块化架构:

  • rustpython-vm: 虚拟机核心(必需)
  • rustpython-compiler: 编译器模块
  • rustpython-stdlib: 标准库实现(可选)
  • rustpython-pylib: Python 库支持(可选)
  • ruff_python_parser: 使用 Ruff 的高性能解析器

条件依赖

[target.'cfg(windows)'.dependencies]
libc = { workspace = true }[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rustyline = { workspace = true }
  • Windows: 需要 libc
  • 非WASM平台: 包含 rustyline 用于交互式命令行编辑

[workspace] 工作空间配置

[workspace]
resolver = "2"
members = ["compiler","compiler/core", "compiler/codegen","compiler/literal",".","common","derive","jit","vm","vm/sre_engine","pylib","stdlib","derive-impl","wtf8","wasm/lib",
]

项目模块结构:

  • compiler/: 编译器相关模块(核心、代码生成、字面量处理)
  • vm/: 虚拟机核心(包含正则表达式引擎)
  • stdlib/: 标准库实现
  • pylib/: Python 库支持
  • jit/: 即时编译功能

性能优化配置

[profile.dev.package."*"]
opt-level = 3[profile.test]
opt-level = 3[profile.bench]
lto = "thin"
codegen-units = 1
opt-level = 3[profile.release]
lto = "thin"

优化策略:

  • 开发模式: 对所有依赖包启用 O3 优化级别
  • 测试模式: 启用优化以保证测试性能
  • 发布模式: 使用 ThinLTO 链接时优化
  • 基准测试: 最大程度优化(单代码生成单元 + ThinLTO)

特殊配置

包发布元数据

[package.metadata.packager]
product-name = "RustPython"
identifier = "com.rustpython.rustpython"
description = "An open source Python 3 interpreter written in Rust"

Windows 特定配置

[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
rev = "2024.02.14"

使用 vcpkg 管理 Windows 上的原生依赖(如 OpenSSL)

代码质量保证

[workspace.lints.rust]
unsafe_code = "allow"
unsafe_op_in_unsafe_fn = "deny"
elided_lifetimes_in_paths = "warn"[workspace.lints.clippy]
perf = "warn"
style = "warn"
complexity = "warn"
suspicious = "warn"
correctness = "warn"

代码检查策略:

  • 允许 unsafe: 解释器底层需要 unsafe 代码
  • 严格检查: 对性能、代码风格、复杂性进行全面警告
  • 安全性: 禁止在 unsafe 函数中不安全操作

总结

这个配置文件展示了 RustPython 的现代化 Rust 项目架构:

  1. 模块化设计: 清晰的内部模块划分
  2. 灵活的特性系统: 按需启用功能
  3. 跨平台支持: 针对不同平台的优化配置
  4. 性能优先: 全方位的编译优化设置
  5. 代码质量: 严格的静态检查规则
http://www.dtcms.com/a/406323.html

相关文章:

  • 献县网站做映射后 内网无法通过域名访问网站
  • Go语言 对接全球股票K线API实战 - 以美股市场为例
  • Linux系统Nginx服务(四)
  • Linux to go Ubuntu 22.04 不匹配无线网卡 MT7925 的解决方法
  • Go语言在区块链开发中的应用场景详解
  • go的基础数据结构 slice源码阅读
  • 百度网盟推广 网站四川建设网有限责任公司官网
  • 破局渠道垄断:青蓝的流量入口变现路径
  • 【C++STL :string类 (二) 】从接口应用到内存模型的全面探索
  • 学做面包到什么网站网站点击按钮回到页面顶部怎么做
  • 领航 网站设计主机屋怎么做网站
  • 在VTK中实现相机自动绕轴旋转
  • 关于解决switch开关属性中active-value=“1“为数值形失败的问题
  • Seata 深度解析:微服务分布式事务管理的实践指南
  • LeetCode:53.课程表
  • 中国县域经济韧性(2006-2021)
  • MySQL零基础学习Day3——函数和约束
  • Bililive-go+cpolar:跨平台直播录制的远程管理方案
  • 飞马无人机正射/倾斜影像数据预处理
  • 2025 AI 技术跃迁与产业融合:从实验室到价值场
  • 济源网站建设价格蓝色系网站
  • MySQL InnoDB缓冲池优化全指南
  • Redis 内存淘汰策略 LRU 和传统 LRU 差异
  • 焞煌网站怎么做产品营销型网站建设
  • 【C++】:stack、queue和deque全面讲解
  • 【MySQL学习笔记】数据库的CURD(一)
  • 使用Excel在标签打印软件快速新建标签,表格导入并实现批量打印
  • WEB日常刷题练习(1)
  • 信阳网站建设的费用潍坊网站建设维护
  • Kafka-消息不丢失