Move binary-only dependencies under a feature #1937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When mdBook is used as a library for preprocessors, preprocessors need far less functionality than for the main mdbook binary. However, even with
default-features = false
, mdbook currently has 91 transitive dependencies.Solution
This PR reduces the number of transitive dependencies from 91 to 46 with
default-features = false
, while maintaining enough API surface for preprocessors to function. It introduces a new default"full"
feature that activates several dependencies likechrono
andhandlebars
. This feature then gates the compilation of several modules and functions.To reduce the usage of
#[cfg(feature = "full")]
, this PR factors out theMDBook
data structure from thebook
module into a new modulemanage
(better names welcome), while leaving theBook
data structure (essential for preprocessors) inside thebook
module. Specifically the set of renamings are:book/book.rs
->book/mod.rs
book/mod.rs
->manage/mod.rs
book/init.rs
->manage/init.rs
Alternatives
In theory, a cleaner alternative would be to factor the monolithic
mdbook
project into a Cargo workspace: one crate for the core API that would be used by preprocessors, and one crate for building the mdbook binary. However, this is a much larger change that requires messing with CI, publishing multiple packages, etc. so this PR seemed like a simpler way to achieve the same desired outcome for now.Notes
Note there's still some TODOs for documentation --- I will add the docs if it is decided to go ahead with this PR.