Hacker News new | ask | show | jobs
by kd5bjo 2590 days ago
I generally prefer to use Make as my build system everywhere, so that I only have to learn the quirks of one system, and it’s easier to handle mixed-language projects.

The documentation for using rustc directly is hard to find, but it’s quite possible to skip Cargo entirely. I’ve had no trouble using it mostly like a C compiler, but I have run into a couple of quirks I needed to work around:

* I haven’t figured out how to get dependency information out of the compiler, so I had to write a likely-fragile script to grep the rust sources.

* In any project, crates have a single, flat namespace. If you want to treat them like you would object files in a C project you’ll need some scheme to prevent name conflicts between subdirectories. The more rust-y thing is to use the module system to include anything that shouldn’t be visible at the top level of your hierarchy.

Otherwise, it’s fairly similar to a traditional compiler:

  rustc main.rs -o my-program # compile an executable
  rustc main.rs --test -o ... # compile the test framework
  rustc --crate-type=rlib ... # make an rlib (roughly equivalent to .o)
  rustc --extern name=path/to/rlib ... # reference another crate (required during compilation)
1 comments