dart-lang / dart-lang/language
Support for Rust like #[cfg()] attributes
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Maybe instead of adding [configurable URIs](https://github.com/dart-lang/language/blob/main/working/augmentation-libraries/parts_with_imports.md) for parts (in addition to imports and exports), we can add a more flexible feature?
As you can see below, it can be used not only for "part" (modules in Rust), and "imports"; but also can be used to conditionally compile statements. Which might be convenient - declare much platform specific logic in conditional parts, and then conditionally use it.
The main point here is that in Rust this is a universal feature - you can condition anything.
And in Dart currently we have push this feature into every directive separately.
```rust
#[cfg(target_os = "windows")]
mod my_windows;
#[cfg(target_os = "macos")]
mod my_macos;
fn main() {
#[cfg(target_os = "windows")]
my_windows::say_hello_windows();
#[cfg(target_os = "macos")]
my_macos::say_hello_macos();
}
```
`my_macos.rs`
```rust
pub fn say_hello_macos() {
println!("Hello, macOS!");
}
```
`my_windows.rs`
```rust
pub fn say_hello_windows() {
println!("Hello, Windows!");
}
```
Contributor guide
Assessment
This issue has not been assessed yet.