How do I directly compile a rust file to an executable?

Using Arch-based Linux, WITHOUT using the cargo package manager, how do I compile a file that I directly wrote and saved it as *.rs to a binary executable?

rustc builds it

1 Like

I suggest using --verbose with cargo once to see what it passes to rustc. You can then adapt that as needed.


Note: rustc has optimizations disabled by default. For cases where performance matters, you'll want to use (at minimum) the -O flag:

rustc -O

(That's a capital letter “o”, not a zero.)


Can I specify -O3 (e.g. rustc -O3

Use -C opt-level=3 if you want to set a specific optimization level.

-O is currently equivalent to -C opt-level=2.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.