D
D
da da2021-05-26 20:54:46
Rust
da da, 2021-05-26 20:54:46

Why does the compiled "Hello World" in Rust take up 10 megabytes on disk?

Yes, I also have a question. Why, if I write a project using some external library, it will be downloaded and compiled, and then in another project I will need the same library, and in the end it will be downloaded and compiled again, and as a result, projects on 5+GB.

Why couldn't it be done like in python, once you installed Libra, you use it everywhere!

Are the Rust developers going to fix this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Lesnikov, 2021-05-26
@IIggoorrII

Why does the compiled "Hello World" in Rust take up 10 megabytes on disk?

10mb sounds like a lot. Order 2-5 should rather - depends on the platform more precisely.
And the place in the vlob assembled "empty" helloworld is occupied, in theory, by pieces of the standard println library! although it looks simple, it pulls the formatting machinery, handling potential errors, promotion, backtraces, etc. with it. And all this with debug symbols.
Why couldn't it be done like in python, once you installed Libra, you use it everywhere!

In general, this is not the case in modern serious python development - package managers also create their own environment with their own dependencies for each project. Otherwise, at least, it is difficult to obtain build reproducibility.
Are the Rust developers going to fix this?

As far as I know, there is currently no clear consensus on whether this needs to be "fixed" at all, so I wouldn't expect big changes here in the foreseeable future. At the moment, you can explicitly ask cargo to use the common target directory yourself:
1) register at the required level in `.cargo/config`:
[build]
target-dir = "/hone/username/myrusttarget"

Or use an environment variable:
export CARGO_TARGET_DIR = "/hone/username/myrusttarget"

But keep in mind that some non-trivial dependencies may have problems with features or the confused logic of build.rs scripts, and plugins that are not designed for this cargo may stop working.

V
Vasily Bannikov, 2021-05-26
@vabka

Why couldn't it be done like in python, once you installed Libra, you use it everywhere!

Hell knows. Rust is not alone here.
Both approaches have their pros and cons
then it will be downloaded and compiled, and then in another project I will need the same library, and in the end it will be downloaded and compiled again,

Compilation is needed, because the raster compiler makes deep optimizations for each project, which require the availability of source codes.
Why does the compiled "Hello World" in Rust take up 10 megabytes on disk?

Depends on parameters. Most likely some of these in various combinations:
1. Lots of code, including dependencies
2. Built without size optimizations
3. Debugger info included

S
Stanislav Makarov, 2021-05-26
@Nipheris

Why, if I write a project using some external library, it will be downloaded and compiled, and then in another project I will need the same library, and in the end it will be downloaded and compiled again, and as a result, projects on 5+GB.

Those. Do you want Rust/Cargo to somehow integrate with the system's package manager? Then I suggest reading this article: https://habr.com/ru/post/433052/

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question