What is rustc?
rustc is the compiler for Rust. When we use
cargo to compile our source files it is actually calling
rustc to do all the hard work.
Don't believe me? :D Use this command to see the full output from a call to
cargo build --verbose
rustc outputs the compiled binary file to the same directory as it is called in.
rustc hello.rs will create the binary file
hello in the same directory as our source file
Where does Git come in to this?
All good. But if we are using Git we don't want to commit these binary files to our repository. "Let's just use a .gitignore file" I hear you cry. Perfect but we can only git ignore files and directories by name not by type or anything else.
A little trick we can use is to create a directory called
bin and git ignore that. Then use the following when compiling with rustc -
rustc --out-dir bin hello
Now our source files and binary files are kept apart and our binaries never make it into the Git repository.