Compiling a crate into one .rs file?

Hello everyone, I'm planning on doing some competitive programming in Rust. Is there any existing tools to compile my crate and all of its dependencies into one .rs file so that I can submit it? If not, what should I use to build such tool?

Typically you do not have dependencies beyond the standard library available in competitive programming. I tried out solving some problems using Rust a month ago or so, and you can see how I set it up here here.

Unfortunately, it's not possible in general because proc-macro crates (such as serde_derive or structopt) always have to be a separate crate.

If you prevent such crates from sneaking in to your dependency tree (although I doubt you can do it easily), it's theoretically possible to do carefully expand cfg attrs, replace absolute paths, adjust edition differences, and inline the crates and modules into mod { ... } items. However, even if you (or someone) complete such a hard work, that hypothetical "Rust Packer" (named after webpack) may still fail due to various isses such as type inference breakage.

Thank you for the inputs! I'll investigate further to see if there is any workarounds for the problems.

Another road blocker is the crates with ffi lib dependencies. Even rayon depends on it to manageprocess-unique thread pool