Skip to content

Make actix dependency optional #1021

@kamoshi

Description

@kamoshi

Currently, when using the pagefind crate as a library inside another Rust project, the crate pulls in ~340 dependencies, including actix, even when the "serve" functionality is not being used at all inside the project.

I think it would be beneficial to make the actix dependency (there might me more unneeded, but haven't checked anything else) optional and put the "serve" functionality behind a compile flag.

This can be done as follows (example):

In Cargo.toml

# ...

[features]
default = ["serve"]
serve = ["dep:actix-web", "dep:actix-files", "dep:portpicker"]

# ...

[dependencies]
# ... 
actix-web = { version = "4", optional = true }
actix-files = { version = "0.6", optional = true }
portpicker = { version = "0.1", optional = true }

In *.rs:

// ...
#[cfg(feature = "serve")] // +
mod serve;
// ...

I think it would be generally beneficial to try to trim down the binary size for use cases that don't require as many features as a standalone binary program. This serve feature seems like a low-hanging fruit to me, because it cuts down dependencies from 342 to 214.

Full git diff output: diff.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions