pepsighan
pepsighan

Reputation: 908

Which files from the target directory are actually required by the executable?

After compiling my program 'zagir', the release folder has the size of more than 200MiB, which is ridiculous for the program I have written. So, I tried to check whether only the 'zagir' executable runs in isolation and it did.

But the confusion is that, release folder also includes libzagir.rlib file along with .d files and a bunch of other folders.

  1. What exactly are they?
  2. Are they really required?
  3. Am I going to get error during execution when those files are ignored?
  4. What are the files I should bundle for a complete executable?

Cargo.toml

[package]
authors = ["Sharad Chand"]
name = "zagir"
version = "0.1.0"

[dependencies]
bcrypt = "0.1.3"
dotenv = "0.10.1"
image = "0.17.0"
log = "0.3.8"
r2d2 = "0.7.3"
r2d2-diesel = "0.16.0"
rand = "0.3.16"
rocket = "0.3.2"
rocket_codegen = "0.3.2"
serde = "1.0.11"
serde_derive = "1.0.11"
serde_json = "1.0.2"
validator = "0.6.0"
validator_derive = "0.6.0"

[dependencies.bigdecimal]
features = ["serde"]
version = "0.0.10"

[dependencies.chrono]
features = ["serde"]
version = "0.4.0"

[dependencies.diesel]
features = [
    "mysql",
    "chrono",
    "unstable",
    "numeric",
    "huge-tables",
]
version = "0.16.0"

[dependencies.diesel_codegen]
features = ["mysql"]
version = "0.16.0"

[dependencies.rocket_contrib]
features = ["handlebars_templates"]
version = "0.3.2"

[dependencies.uuid]
features = ["v4"]
version = "0.4"

Upvotes: 30

Views: 8442

Answers (1)

Shepmaster
Shepmaster

Reputation: 430554

Which files from the target directory are actually required by the executable

None of them, other than the executable itself. By default, Rust produces statically-linked binaries.

The other files are merely build artifacts maintained by Cargo in order to make rebuilding your code more efficient. They include things like your dependencies.

A non-exhaustive sampling of some of the files you might find:

  • *.d — Makefile-compatible dependency lists
  • *.rlib — Rust library files. Contain the compiled code of a dependency
  • build — Directories for build scripts to use as scratch space
  • deps — Your compiled dependencies
  • examples — Binaries from the examples directory
  • incremental — A directory for the incremental compilation cache
  • *-{hash} — Binaries from cargo test
  • executables — Your target binaries

Some of this is documented in the Cargo source code.

Upvotes: 46

Related Questions