Cargo do not allow any fancy features to declare a path, even ~ is not allowed.
Now I have a workspace and some crates, some of them are really deep in the file trees, so I have to use some_crate = {path = "../../../../../another_crate"}, and what worse is that the paths are different based on where the some_crate` locates.
So is there any way I can get rid of this? I tried create an environment variable workspace_home, but cargo do not allow env in toml either.
I'd X-Y the problem and figure out why you need deeply nested paths to begin with. Possibly by uploading to crates.io, using git dependencies, or git submodules.
Using something like ~ wouldn't be a good idea in the long run because it's not portable between machines unless you copy all projects into the exact same files.
The reason of using path instead of crate.io or others is that all the crates in the workspace are currently under development, we put them into one workspace so we can modify the code directly and testing if we found bugs on other crates.
Your suggestion is very reasonable and we will use the normal way to import packages, but for now, this is where we are...
Unless your workspace is gigantic (>1mloc), I suggest using flat structure for all the crates. In rust-analyzer, we just put everything into the /crates directory, and, empirically, it works better then nested workspaces with hierarchical structure. rustc itself also uses flat structure.
Thanks for pointing out that rustc uses flat structure, I'm considering to do it the same way, although my personal opinion is that if crates are grouped by foundations, the project may be more readable...