When you add Tokio to a Rust command-line tool or service, Cargo features determine which Tokio capabilities your code can use. Start by identifying what the program does: run async tasks, wait on timers, or use the network and other I/O. A runtime is the part of Tokio that schedules async work and provides drivers for resources such as timers and I/O.
For a small binary, turn off Tokio’s default features when you know which capabilities you need. Check two things separately: Cargo must expose the APIs your code calls, and your runtime must enable the drivers those APIs need. A shorter feature list gives you more control over what Tokio compiles. The available documentation does not say how much this changes the final binary’s size.
Start with the APIs your code calls
Before editing Cargo.toml, check which Tokio APIs the program calls. Code that creates a runtime with tokio::runtime::Builder needs the rt feature. If the program uses tokio::spawn, timers, or networking, check those APIs’ feature requirements for the Tokio version in your dependency declaration. The Tokio runtime notes show one configuration that selects rt and net. Use it as a starting point, not as a complete feature map for every API.
For example, a program that constructs its own runtime and uses Tokio networking could start with:
[dependencies]
tokio = { version = "1", default-features = false, features = ["rt", "net"] }
Add time when the program uses Tokio timers. If the code creates a runtime that runs tasks on multiple threads with Builder::new_multi_thread, add rt-multi-thread. The rt feature alone does not provide that constructor. Tokio’s Builder documentation says Builder requires rt and new_multi_thread requires rt-multi-thread.
If the program uses #[tokio::main], check the macro’s requirements and runtime configuration for your Tokio version. The macro creates a runtime, so the program still needs a compatible runtime setup even if its code does not call Builder.
Enable the runtime drivers your async work needs
Cargo features make APIs available when the code compiles. Runtime drivers are separate settings that let a running Tokio runtime handle resources such as timers and I/O. A successful compile does not confirm that a manually created runtime enables the drivers the code uses.
When you create a runtime with Builder, enable_all turns on both I/O and time drivers. You can also turn on each driver separately with enable_io and enable_time. For timers, include the time feature and make sure the runtime enables the time driver. For networking, include the feature required by the network API and make sure the runtime enables I/O. The Tokio runtime notes connect time with enable_time and describe net as one condition for enable_io. Check the documentation for your Tokio version and APIs; the notes do not map every feature to every API.
A current-thread runtime suits a program that does not need Tokio’s multi-thread scheduler. It runs async work on the current thread. The caller must drive it with Runtime::block_on. Selecting this scheduler does not change which Cargo features the program needs to expose its APIs and drivers.
Check the choice in the build
After changing Cargo.toml, compile the binary and run the code paths that use Tokio. If a feature is missing, compilation reports that an API is unavailable. If the runtime cannot initialize an operating-system resource it needs, Builder can return an error from Builder::build. Check the result to confirm that runtime creation succeeded. A successful compile does not prove that the runtime has the driver needed for every later timer or I/O operation.
To compare binary sizes, build release binaries for the same target with the same settings, changing only Tokio’s features. This lets you test whether selecting fewer features changes the binary size, but it does not guarantee a specific reduction. Also review the dependency graph, because other crates in the program can affect which Tokio features Cargo enables.