loading...

Managing Rust binary files and Git when using rustc

jjmax75 profile image John Behan Originally published at boxitoff.com ・1 min read

Getting started with Rust (3 Part Series)

1) Getting started with Rust on Mac 2) Managing Rust binary files and Git when using rustc 3) Using attributes in Rust to suppress warnings

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.

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 hello.rs.

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 folder 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.

Getting started with Rust (3 Part Series)

1) Getting started with Rust on Mac 2) Managing Rust binary files and Git when using rustc 3) Using attributes in Rust to suppress warnings

Posted on Mar 16 by:

jjmax75 profile

John Behan

@jjmax75

I am a software developer working with Javascript and starting with Rust

Discussion

markdown guide
 

but doesn't cargo deal with all that?, it makes a folder target/ with all the build "residue" and even makes a .gitignore with target/ on it. Whith other platforms sometimes I avoid those "scafoldings" but in the case of Rust Cargo doesn't add anything too fancy or complex. Is there some reason I don't see to not use cargo?

 

Yes, cargo takes care of this.

This post is for using rustc directly. I don't think there is any reason not to use cargo