Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Module Aliases Bug with Conditional Products. #7412

Open
1 task done
furby-tm opened this issue Mar 20, 2024 · 0 comments
Open
1 task done

Swift Module Aliases Bug with Conditional Products. #7412

furby-tm opened this issue Mar 20, 2024 · 0 comments
Labels

Comments

@furby-tm
Copy link

furby-tm commented Mar 20, 2024

Is it reproducible with SwiftPM command-line tools

(swift build, swift test, swift package, etc)?

  • Confirmed reproduction steps with SwiftPM CLI.

Description

Note

I have provided an example project with CI hooked up to help aid in reproducing this issue.

I have discovered a very odd issue that's very hard to pinpoint in the (non-xcode) swift toolchain, here is where I ran into the bug(view the raw log for this build) and then search for the following text: error: failed to build module 'SwiftUI', even more insane is that this error caused the build time to swell up to nearly 4x over:

  • typical build time for this project is 29m 11s
  • however this bug induced a 1h 44m 58s build 😅

It appears on the non-xcode swift toolchain, if a Swift .target() has a .product() dependency which attempts to make a module alias, in my case, from SwiftCrossUISwiftUI, the condition clause is entirely ignored and the module is aliased on all platforms regardless of what is listed in the .when(platforms: [.linux, .windows]) array, which means macOS is for some reason experiencing the module aliasing seen here in the SwiftPM package manifest:

.product(
  name: "SwiftCrossUI",
  package: "swift-cross-ui",
  moduleAliases: ["SwiftCrossUI": "SwiftUI"], // < macOS breakage
  condition: .when(platforms: [.linux, .windows]) // < but why?
),

It then errors about failing to build the SwiftUI module, reporting that this SDK is suddenly not supported by the compiler, due to the existence of this single offending line in the package manifest:

moduleAliases: ["SwiftCrossUI": "SwiftUI"]

Expected behavior

I expected the usage of moduleAliases: ["SwiftCrossUI": "SwiftUI"]:

  • to create a module alias from SwiftCrossUISwiftUI.
  • when used in conjunction with condition: .when(platforms: [.linux, .windows])
    • only for the Linux and Windows platforms.

So that in my swift code I could write code like the following:

// SomeFile.swift
import SwiftUI

// do cross platform UI things...

Actual behavior

The usage of moduleAliases: ["SwiftCrossUI": "SwiftUI"]:

  • to create a module alias from SwiftCrossUISwiftUI.
  • when used in conjunction with condition: .when(platforms: [.linux, .windows])
    • somehow broke macOS.
// SomeFile.swift
import SwiftUI
       ^~~~~~~
error: failed to build module 'SwiftUI'

// do cross platform UI things...

Steps to reproduce

  1. In a terminal window, clone this package.
    git clone https://github.com/wabiverse/SwiftUIToolchainBug.git
  2. Then, "cd" into this newly cloned directory.
    cd SwiftUIToolchainBug
  3. Now build the SwiftPM package.
    swift build
  4. Notice there are no issues 👍🏻.
  5. Now, open the package up in your code editor.
    code .
  6. And make the following tiny revision.
    // swift-tools-version: 5.9
    import PackageDescription
    
    #if os(macOS)
    - let swiftUIToolChainBug: [String: String]? = nil
    + let swiftUIToolChainBug: [String: String]? = ["SwiftCrossUI": "SwiftUI"]
    #else /* os(macOS) */
      let swiftUIToolChainBug: [String: String]? = ["SwiftCrossUI": "SwiftUI"]
    #endif /* !os(macOS) */
  7. Now, attempt to build the package again:
    swift build
  8. Experience the issue.

Swift Package Manager version/commit hash

Swift 5.9.2

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
@furby-tm furby-tm added the bug label Mar 20, 2024
@furby-tm furby-tm changed the title Swift (non-xcode) Toolchain Bug with Module Aliases on Conditional Products. Swift Module Aliases Bug with Conditional Products. Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant