Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

conditional compilation

Choosing which code to compile for each target, with #[cfg], cfg! and cfg_select!.

#[cfg(pred)] and cfg_select! remove code whose predicate is false before type checking; cfg!(pred) is a bool expression, so every branch must compile on every target.

Examples

  • #[cfg(unix)] fn home() and #[cfg(windows)] fn home() give one version per target; if cfg!(windows) { .. } keeps both branches, so both must compile everywhere.

Read the full section →