Lateley i've been thinking about Rust as a useful language for website development. There are a lot of libraries with various quality scattered around, some are very well designed and tested, some not so, but what i see is lacking is a some sort of framework that allows to efficiently manage larger projects, to compose packages together, to manage dependencies and so cargo comes into question.
In a way cargo works like make, it compiles Rust code; it does it in a lot friendlier manner, since user does not have to specify each file that has to be compiled, but looking from functionality perspective those two tools have the same role. But not only that 'cargo' automatically downloads dependencies, in this regard it kind of works like package manager; it allows to install packages, so, kind of like package manager but not quiet.
Websites require that there are an HTML, CSS, and JavaScript files. There might be necessary some images for UI, maybe fonts. But cargo/crates in practice do not support packaging into them other resources than library or application itself. While crate is just an archive that contains crate sources and built artifacts, it does not allow to explicitly package images, fonts or other resources in it, although technically it would be possible.
Yes, sure, there are macros include_str! and include_bytes! and currenlty a lot of "web-related" crates take that approach, but to me this does not seem viable approach for bigger projects.
For example, if i would like to include bootstrap.js with UI elements, i would like to specify it in Cargo.toml as dependencies to current project, and cargo deals with dependencies very good; i could even go so far as to create a crate for each UI element that only contains JS and CSS files (from dependency perspective cargo handles this easilly), but in practice it is not possible to do it in a clean way, because crate must be a library. Yes, sure, i could use include_bytes! and somewhat achieve the goal, but this really seems more like a hack than a solution.
When building a crate that contains JavaScript, a minifier could be run; CSS minifier could be run as well, and what not. But cargo gets in a way with doing this. 1. it does not allow to package built artifacts into package/crate, even if i use build.rs file; 2. it does not allow to redistribute built result (since each project has to compile dependency crate localy, thus all build-deps have to be built as well; thus instead of just downloading minified JS file, user would download whole source and build minify it localy, which seems a waste of resources and time).
Another approach would be to use another/different package manager to build JS packages, but then i must build all project/Rust crates with that package manager as well, because cargo does not allow to specify a different package manager for dependency crates. It is not possible to delegate dependency building to other tool, cargo kind of forces "all or nothing".
So if a choice is made to use different package manager, then i'm on my own then, which is not a nice place to be, because cargo has a lot of good features and things already solved.
So my questions are:
- What is cargo? Is it intended to become a functional package manager that is capable to package resources or other artifacts as well or is it intended to be capable only to compile single little standalone projects? How do you see cargos role/place?
- How do you deal with UI elements like images, fonts, etc.? I mean, it would be so nice if those artifacts could be managed like any dependency.
- If not using cargo, then what are the alternatives? Crates.io is a nice package registry, it's very convenient to add a new dependency and it "just works". Is there someone using different package/dependency manager to build Rust projects?
- How hard it could be to implement a "resource crate" or similar concept to achieve this for current cargo? Cargo kind of seems quiet flexible, but i do not know internals and limitations.