Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blurb about Cargo inner workings #4159

Merged
merged 2 commits into from
Jun 14, 2017
Merged

Blurb about Cargo inner workings #4159

merged 2 commits into from
Jun 14, 2017

Conversation

matklad
Copy link
Member

@matklad matklad commented Jun 12, 2017

Hi!

At today's dev tools meetings we've discussed how we can foster contributions to rust dev tools, and I've complained that some tools are difficult to contribute to because it's difficult to learn how they work because there are no docs, and some other people complained that Cargo is difficult to contribute to because it is rather complex. And, as a member of Cargo team, I thought that I am probably responsible for fixing that :)

So, here's my take at making it easier to dive in into Cargo! I've written a small birds eye overview of the current architecture of Cargo (more like a list of things to look at while reading the code actually :)

In general, I am skeptical about documenting internals of binaries (docs will become obsolete, and very fast), but such a high level picture should be pretty robust (I deliberately avoided linking to the actual source code), and so pretty low-effort to maintain. We do something similar for IntelliJ Rust: https://github.com/intellij-rust/intellij-rust/blob/master/ARCHITECTURE.md as well.

r? @alexcrichton

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Sounds like a great idea to me!

Cargo is organized as a set of subcommands. All subcommands live in
`src/bin` directory. However, only `src/bin/cargo.rs` file produces an
executable, other files inside the `bin` directory are submodules. See
`src/bin/cargo.rs` for how these subcommands get wired up with the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be totally onboard with redoing how these submodules are organized as well! Something like src/bin/subcommands/*.rs instead of src/bin/*.rs if we'd like to remove this clause!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was a bit shameful to explain ourselves here :) I think the layout should be

src/
  bin/
    cargo/
      main.ru
      buld.rs
      test.rs

to match that of #4086. I would like to fix #4086 first though, to make sure we follow conventional layout.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ARCHITECTURE.md Outdated
from. Typical sources are crates.io, a git repository or a folder on
the local hard drive.

`Resolve` is the representation of a direct acyclic graph of package
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/direct/directed/

ARCHITECTURE.md Outdated

## Concurrency

Cargo itself is mostly single hreaded, but it schedules compiler jobs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/shreaded/threaded/

ARCHITECTURE.md Outdated
in parallel if possible. However there can be several different
instances of Cargo running concurrently on the system, so Cargo uses
file locking when accessing potentially shared data like the registry
or the target directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth pointing out a few high-level things here like:

  • Concurrent invocations of Cargo are expected to "always work" but need not be "optimally interleaved". If someone holds the lock for way too long that's ok, we just need to guarantee that nothing needs to go too awry.
  • Within one invocation of Cargo there's only concurrency (currently) in the backend compiling. Really that's just spawning a bunch of processes in parallel, ideally this'd all be future-ized so we wouldn't have to have threads at all!

It sounded to me like this paragraph is going for the same thing, maybe it's just worth clarifying a little?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Cargo have any system global data (as opposed to per-user global)?
(E.g. can any locking affect multiple users running Cargo from a common system global toolchain?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so. All the "global" data live inside $CARGO_HOME, and each user usually have their own $CARGO_HOME, unless you explicitelly configure Cargo otherwise.

@matklad
Copy link
Member Author

matklad commented Jun 13, 2017

Reworded the concurrency section slightly, hope it's clearer now!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 13, 2017

📌 Commit 8495aa3 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 14, 2017

⌛ Testing commit 8495aa3 with merge 46252c6...

bors added a commit that referenced this pull request Jun 14, 2017
Blurb about Cargo inner workings

Hi!

At today's dev tools meetings we've discussed how we can foster contributions to rust dev tools, and I've complained that some tools are difficult to contribute to because it's difficult to learn how they work because there are no docs, and some other people complained that Cargo is difficult to contribute to because it is rather complex. And, as a member of Cargo team, I thought that I am probably responsible for fixing that :)

So, here's my take at making it easier to dive in into Cargo! I've written a small birds eye overview of the current architecture of Cargo (more like a list of things to look at while reading the code actually :)

In general, I am skeptical about documenting internals of binaries (docs will become obsolete, and very fast), but such a high level picture should be pretty robust (I deliberately avoided linking to the actual source code), and so pretty low-effort to maintain. We do something similar for IntelliJ Rust: https://github.com/intellij-rust/intellij-rust/blob/master/ARCHITECTURE.md as well.

r? @alexcrichton
@bors
Copy link
Contributor

bors commented Jun 14, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 46252c6 to master...

@bors bors merged commit 8495aa3 into rust-lang:master Jun 14, 2017
@matklad matklad deleted the arch branch March 17, 2018 08:39
@ehuss ehuss added this to the 1.20.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants