Skip to content

Add general #if conditional compilation block (IfConfig) #140

@leogdion

Description

@leogdion

Summary

Currently IfConfig (formerly IfCanImport) only supports #if canImport(Module). It should be expanded into a general-purpose conditional compilation block covering all Swift #if condition types.

Conditions to Support

  • .canImport("UIKit")#if canImport(UIKit) (already works)
  • .flag("DEBUG")#if DEBUG
  • .os(.iOS) / .os(.macOS) / .os(.Linux) / .os(.Windows) etc.
  • .targetEnvironment(.simulator) / .targetEnvironment(.macCatalyst)
  • .swift(>=6.0) — Swift version check
  • .compiler(>=6.0) — compiler version check
  • .arch(.arm64) / .arch(.x86_64)
  • .hasFeature(...) / .hasAttribute(...)
  • Boolean combinations: &&, ||, !

Clauses

  • #elseif support (additional IfConfigClauseSyntax entries)
  • #else support

Related

  • #warning("message") and #error("message") could be added as separate CompilerWarning / CompilerError types using PoundDiagnosticDeclSyntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions