Skip to content

jextract: Evaluate IfConfigDecl for simple patterns #633

@sidepelican

Description

@sidepelican

When generating .swiftinterface files using the -emit-module-interface flag, unexpected #if blocks are often generated. For example:

  • Original .swift
public struct AppStore: Sendable, Codable {
  public var storeURL: URL?
  public init(storeURL: URL?) {
    self.storeURL = storeURL
  }
}
  • Generated .swiftinterface
public struct AppStore : Swift.Sendable, Swift.Codable {
  public var storeURL: Foundation.URL?
  #if compiler(>=5.3) && $NonescapableTypes
  public init(storeURL: Foundation.URL?)
  #endif
  public func encode(to encoder: any Swift.Encoder) throws
  public init(from decoder: any Swift.Decoder) throws
}

The Problem

The exact reason for this behavior is unclear, but expressions like #if compiler(>=5.3) && $NonescapableTypes appear in various places within generated interfaces.

Currently, Swift2JavaVisitor ignores IfConfigDecl entirely.
As a result, any method or property signatures wrapped in these #if blocks are lost.

Proposed Solution

We could potentially use SwiftIfConfig to evaluate these blocks.

Although providing a full BuildConfiguration might be complex, it would be highly beneficial to at least support simple, common patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:jextractIssues related to jextract-swift

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions