bazel-ios / rules_ios

Bazel rules for building iOS applications and frameworks
Apache License 2.0
276 stars 84 forks source link

rules_ios fails to build using rules_swift 2.x #875

Closed tymurmustafaiev closed 1 month ago

tymurmustafaiev commented 2 months ago

In my project I need to use latest changes from rules_swift. I'm trying to build framework using apple_framework rule for this target from test samples folder:

apple_framework(
    name = "SwiftIntentConsumer",
    srcs = [
        "Intents.intentdefinition",
        "SwiftIntent.swift",
    ],
    platforms = {"ios": "12.0"},
    visibility = ["//visibility:public"],
)

When I try to build it - I got this error: 👇 ❌

ERROR: /Users/timur.mustafaev/Documents/Projects/rules_ios/tests/ios/frameworks/intentdefinition/BUILD.bazel:13:16: Compiling Swift module //tests/ios/frameworks/intentdefinition:SwiftIntentConsumer_swift failed: (Exit 1): worker failed: error executing SwiftCompile command (from target //tests/ios/frameworks/intentdefinition:SwiftIntentConsumer_swift) 
  (cd /private/var/tmp/_bazel_timur.mustafaev/c9dc236d29c4f9c416201cbfa4d380ce/execroot/build_bazel_rules_ios && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneSimulator \
    APPLE_SDK_VERSION_OVERRIDE=17.2 \
    PATH='/Users/timur.mustafaev/Library/Caches/bazelisk/downloads/sha256/fb5e7bc62fc3c8f2511e3b64d795296444129b26f13d8dece4d4cee1845b758f/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/timur.mustafaev/Library/Application Support/JetBrains/Toolbox/scripts' \
    SWIFT_AVOID_WARNING_USING_OLD_DRIVER=1 \
    XCODE_VERSION_OVERRIDE=15.2.0.15C500b \
  bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min12.0-applebin_ios-ST-2d34d443f7fd/bin/tests/ios/frameworks/intentdefinition/SwiftIntentConsumer.swiftmodule-0.params)
# Configuration: 591135ff330ad16e507f1e10a984f2fc9bcd492427ee403ea58d45b278d056e3
# Execution platform: @@local_config_platform//:host
error: emit-module command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: cannot open file '/private/var/tmp/_bazel_timur.mustafaev/c9dc236d29c4f9c416201cbfa4d380ce/execroot/build_bazel_rules_ios/bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min12.0-applebin_ios-ST-2d34d443f7fd/bin/tests/ios/frameworks/intentdefinition/SwiftIntentConsumer_swift_vfs.yaml' (No such file or directory)
<unknown>:0: error: cannot open file '/private/var/tmp/_bazel_timur.mustafaev/c9dc236d29c4f9c416201cbfa4d380ce/execroot/build_bazel_rules_ios/bazel-out/ios_sim_arm64-dbg-ios-sim_arm64-min12.0-applebin_ios-ST-2d34d443f7fd/bin/tests/ios/frameworks/intentdefinition/SwiftIntentConsumer_swift_vfs.yaml' (No such file or directory)
error: fatalError
Target //tests/ios/frameworks/intentdefinition:SwiftIntentConsumer failed to build

However, building mixed language framework works fine ✅

apple_framework(
    name = "MixedIntentConsumer",
    srcs = [
        "Intents.intentdefinition",
        "MixedIntent.m",
        "SwiftIntent.swift",
    ],
    platforms = {"ios": "12.0"},
    visibility = ["//visibility:public"],
)

How to reproduce

  1. Disable bzlmod in .bazelrc file: common --noenable_bzlmod
  2. Use latest commit from bazel_rules_swift repo:
    
    load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
    load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe( git_repository, name = "build_bazel_rules_swift", commit = "8c144a2c28af3af7b78b5fd679550e6783a19194", remote = "https://github.com/bazelbuild/rules_swift.git", shallow_since = "1716513695 -0700", )


3. Run `bazelisk build //tests/ios/frameworks/intentdefinition:SwiftIntentConsumer`

I've iterated commits one by one and [this one](https://github.com/bazelbuild/rules_swift/commit/d68b21471e4e9d922b75e2b0621082b8ce017d11) seems to be the breaking commit
luispadron commented 2 months ago

We dont support rules_swift at master yet (it will be a major version bump soon). I'll start working on fixing rules_ios to be compatible with it

luispadron commented 2 months ago

Running a bisect shows this rules_swift commit as being first bad commit:

d68b21471e4e9d922b75e2b0621082b8ce017d11 is the first bad commit
commit d68b21471e4e9d922b75e2b0621082b8ce017d11 (HEAD, refs/bisect/bad)
Author: Tony Allevato <allevato@google.com>
Date:   Mon Jan 24 08:30:10 2022 -0800

    Copy `strict_includes` into `SwiftInfo` provider's Clang module descriptor in `swift_clang_module_aspect`.

    This makes it so that the `apple_common.Objc` provider no longer needs to be handled separately for compilation by Swift build APIs. (It is still used for linking until that is migrated entirely onto `CcInfo`.)

    PiperOrigin-RevId: 423822059
    (cherry picked from commit 8ce95959d19334ce53963c6cbce3ac6eb40cd28c)

 doc/api.md                                   |  33 ++++++++-------------------------
 swift/internal/compiling.bzl                 | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------
 swift/internal/providers.bzl                 |  34 ++++++++++++----------------------
 swift/internal/swift_clang_module_aspect.bzl |  27 ++++++++++++++++++++++-----
 swift/internal/utils.bzl                     |  31 +++++++++++++++++--------------
 5 files changed, 120 insertions(+), 158 deletions(-)