Compiling multiple files separately

Hey there, I'm really satisfied with Rust + Cargo, but I need some help. I need to compile multiple files seperately, example x.rs and y.rs, both seperately but I don't know how to, normally I would do with rustc but I have configs on Cargo.toml.

TL;DR if I'm saying right I need to output multiple products from a single Cargo.toml.

If you put them in src/bin/x.rs and src/bin/y.rs, then cargo will compile it into two different binaries, each with its own main function.

To share code between them, define a src/lib.rs and put the shared code either in that lib.rs file or in sub-modules of lib.rs. When you are in the x.rs and y.rs files, you will need use your_package_name::* to import the shared code.

4 Likes

Thanks!