dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

#[cfg(platform)] for Feature Flags

Open itsezc opened this issue 9 months ago • 2 comments

Feature Request

Dioxus runs on many platforms and OS, and I'm sure with different versions of the same Operating Systems or in case of the web then multiple Browsers / Renderers, this creates alot of confusion when one has to chase caniuse.com for Web and other vendor specific docs to handle for specific OS

Implement Suggestion

Dixous can take this a bit further for help with DX.

We can easily have multiple platforms: "web", "blitz", "native", "desktop", "mobile", "xr" and so forth (similar to #[cfg(feature = "")])

Example API:

Web Browser / User Agent: #[cfg(platform = "web", browser = "<USER_AGENT>")] iOS: #[cfg(platform = "mobile", os = "ios", min_version = "18.3")] iPadOS: #[cfg(platform = "tablet", os = "ipados")] Desktop (i.e. Windows 8 to 11): #[cfg(platform = "desktop", os = "windows", min_version = "8", max_version = "10")]

Creating fine-grained cfg handling for platform specific features, we could also make the second and any consecutive attributes optional.

itsezc avatar Jun 01 '25 08:06 itsezc

cfg is a builtin macro, so we can't modify the behavior, but we do already support conditionally compiling blocks of code based on each dioxus platform with these macros in the dioxus-config-macro crate

ealmloff avatar Jun 02 '25 13:06 ealmloff

That's amazing, perhaps we can extend those macros to help achieve the functionality described in the original issue

itsezc avatar Jun 02 '25 18:06 itsezc