You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Organize our rust code into crates/ directory #6214
All of our current crates are scattered in the top level of the repository, it's not very intuitive for newcomers to look at the code and know that common directory is for shared rust code, and that wtf8 is also a crate for example.
I propose that we create a new directory called crates where we will have the following:
I think it be better if we do those changes with many smaller PRs as not all of them would require changes to the CI, or any other changes. while minimizing the merge conflicts frequencies while we are in this transition.
For project examples that uses this workspace structure you can see:
I am personally not a fan of that structure when a project is a single build system based.
For RustPython, we only use cargo. Also it only has Lib to contains Python source code, and every other directories are basically rust crates.
But I am open to follow the convention if this is a well-known good practice. Do you have a good reference to learn why people decide to that or a good discussion what's the benefits of it?
For me at least, is to flatten the codebase while not cluttering the repo's top level.
From what I see, some projects uses the crates/ structure and some don't, but those who don't still name their rust directories with <project_name>_<component>, such as:
I'm in favor of reorganizing everything into a crates/ directory, since when the project first started I think there was much less of a consensus in the Rust community on directory structure. However it might make more sense to move it to crates/pylib, crates/common, crates/vm, etc, since the rustpython_ bit before every crate would just be redundant. I prefer a directory rather than just putting them in the root for the same reason we have a src/ dir, it separates the code from the other metadata of the project.
I'm in favor of reorganizing everything into a crates/ directory, since when the project first started I think there was much less of a consensus in the Rust community on directory structure. However it might make more sense to move it to crates/pylib, crates/common, crates/vm, etc, since the rustpython_ bit before every crate would just be redundant. I prefer a directory rather than just putting them in the root for the same reason we have a src/ dir, it separates the code from the other metadata of the project.
I think the main motivation for keeping the rustpython prefix is to avoid confusion when specifying dependencies in Cargo.toml.
Newcomers to Rust (or to specifying git dependencies in general), might struggle to understand how to correctly declare dependencies, especially since we are not publishing to crates.io ATM. It's not immediately obvious that cargo only cares about the name field in a crate's Cargo.toml file, not the directory name.
I can easily imagine someone looking at the repository structure and writing something like:
[dependencies]
vm = { git = "https://github.com/RustPython/RustPython.git" }
I also see lots of other projects use the prefix on directories. That looks actually more major convention than crates/ directory. I vote for putting prefix to be aligned to major convention.
I personally don't like both of them, maybe I am the one with bad taste 😂
wasmtime does this, e.g. wasmtime-environ is at crates/environ. boa does this, though with a core directory rather than a crates directory. Looking across repos, there doesn't seem to be a single standard - I see full or partial crate name in root or subdirectory. My preference for crates/vm is based on keeping the root directory clean, and also not making paths too long. It's much quicker to type cd crates/vm than cd crates/rustpython-vm, and easier in the eyes to read rustpython-vm = { path = "../vm" } than rustpython-vm = { path = "../rustpython-vm" }. (plus I myself have built up a muscle memory for six years of vim vm/src/... and just adding a crates/ prefix won't be too bad)
wasmtime does this, e.g. wasmtime-environ is at crates/environ. boa does this, though with a core directory rather than a crates directory. Looking across repos, there doesn't seem to be a single standard - I see full or partial crate name in root or subdirectory. My preference for crates/vm is based on keeping the root directory clean, and also not making paths too long. It's much quicker to type cd crates/vm than cd crates/rustpython-vm, and easier in the eyes to read rustpython-vm = { path = "../vm" } than rustpython-vm = { path = "../rustpython-vm" }.
Alright, so I'll move it to crates/pylib, crates/doc, etc. If @youknowone doesn't have a strong stance against it
(plus I myself have built up a muscle memory for six years of vim vm/src/... and just adding a crates/ prefix won't be too bad)
Activity
ShaharNaveh commentedon Oct 24, 2025
@youknowone can you please take a look? feel free to close it if you think this change is not worth doing
youknowone commentedon Oct 28, 2025
I am personally not a fan of that structure when a project is a single build system based.
For RustPython, we only use
cargo. Also it only hasLibto contains Python source code, and every other directories are basically rust crates.But I am open to follow the convention if this is a well-known good practice. Do you have a good reference to learn why people decide to that or a good discussion what's the benefits of it?
cc @coolreader18
ShaharNaveh commentedon Oct 28, 2025
It's not an official convention, or a "good practice" or a "bad practice", but it's something that I think would be beneficial for us.
Not really, the only thing I could find is this: https://matklad.github.io/2021/08/22/large-rust-workspaces.html
For me at least, is to flatten the codebase while not cluttering the repo's top level.
From what I see, some projects uses the
crates/structure and some don't, but those who don't still name their rust directories with<project_name>_<component>, such as:So a better approach would be to rename
compiler/codegen->rustpython_compiler_codegenfor example?At the end of the day it's a matter of personal taste, and not a hill I'm willing to die on.
coolreader18 commentedon Oct 31, 2025
I'm in favor of reorganizing everything into a
crates/directory, since when the project first started I think there was much less of a consensus in the Rust community on directory structure. However it might make more sense to move it tocrates/pylib,crates/common,crates/vm, etc, since therustpython_bit before every crate would just be redundant. I prefer a directory rather than just putting them in the root for the same reason we have asrc/dir, it separates the code from the other metadata of the project.ShaharNaveh commentedon Nov 1, 2025
I think the main motivation for keeping the
rustpythonprefix is to avoid confusion when specifying dependencies inCargo.toml.Newcomers to Rust (or to specifying git dependencies in general), might struggle to understand how to correctly declare dependencies, especially since we are not publishing to crates.io ATM. It's not immediately obvious that
cargoonly cares about the name field in a crate'sCargo.tomlfile, not the directory name.I can easily imagine someone looking at the repository structure and writing something like:
youknowone commentedon Nov 1, 2025
I also see lots of other projects use the prefix on directories. That looks actually more major convention than
crates/directory. I vote for putting prefix to be aligned to major convention.I personally don't like both of them, maybe I am the one with bad taste 😂
ShaharNaveh commentedon Nov 9, 2025
@youknowone @coolreader18 How should we proceed?
youknowone commentedon Nov 10, 2025
#6234 is also pending by this.
@coolreader18 Could you please share a few examples
crates/commonis also a widely-accepted convention for modern rust projects?To make things clear, I support more common conventions regardless my taste.
I disagree this point. Every cargo.toml file has crate name. We also have same named crate on crates.io too.
I wish we can make more progress 15th Nov not to block other PRs.
coolreader18 commentedon Nov 10, 2025
wasmtime does this, e.g.
wasmtime-environis atcrates/environ. boa does this, though with acoredirectory rather than acratesdirectory. Looking across repos, there doesn't seem to be a single standard - I see full or partial crate name in root or subdirectory. My preference forcrates/vmis based on keeping the root directory clean, and also not making paths too long. It's much quicker to typecd crates/vmthancd crates/rustpython-vm, and easier in the eyes to readrustpython-vm = { path = "../vm" }thanrustpython-vm = { path = "../rustpython-vm" }. (plus I myself have built up a muscle memory for six years ofvim vm/src/...and just adding acrates/prefix won't be too bad)ShaharNaveh commentedon Nov 10, 2025
Alright, so I'll move it to
crates/pylib,crates/doc, etc. If @youknowone doesn't have a strong stance against itDidn't know you're a vim user 🥳
youknowone commentedon Nov 11, 2025
@coolreader18 Thank you for references.
@ShaharNaveh That sounds good.
My taste was not the first priority, but I also prefer to use short path for daily tasks.
ShaharNaveh commentedon Nov 14, 2025
@youknowone @coolreader18 how should we name
compiler/coredirectory?crates/compiler_corecrates/compiler-core?
youknowone commentedon Nov 14, 2025
ShaharNaveh commentedon Nov 15, 2025
take