Unable to generate code coverage for Swift package on M1 Mac

I am developing a Swift package in Xcode and I would like to see code coverage for my tests.

My Package.swift looks like this:

// swift-tools-version:5.3
import PackageDescription

let package = Package(
  name: "MyPackage",
  products: [
    .library(
      name: "MyPackage",
      targets: ["MyPackage"]
    ),
  ],
  dependencies: [],
  targets: [
    .target(
      name: "MyPackage",
      dependencies: []
    ),
    .testTarget(
      name: "MyPackageTests",
      dependencies: ["MyPackage"]
    ),
  ]
)

I open it in Xcode, and I have "Gather coverage for all targets" selected in build scheme.

My tests run and succeed without an issue. However, the code coverage is not gathered. In logs I see such warning:

Failed to generate coverage for target 'MyPackageTests' at paths (
    "/Users/[...]/Library/Developer/Xcode/DerivedData/MyPackage-cfufflstgcguakceoeffzdilbbjq/Build/Products/Debug-iphonesimulator/MyPackageTests.xctest/MyPackageTests"
): No object file for requested architecture

My setup:

  • MacBook Pro M1
  • Xcode 12.4 (12D4e)

I tried to run tests on my old MacBook Pro (Late 2016) with Intel processor and the code coverage was gathered without an issue, so it looks like the problem is related to Apple Silicon architecture.

Is there something I can do to make the code coverage gathering work on M1 Mac?

Here is a link to zipped Swift package as a reference: http://darrarski.pl/files/MyPackage.zip.

2 Likes

Thanks for reporting, this is a known issue.

1 Like

Thanks @NeoNacho for confirming I am not the only one experiencing this issue. I couldn't find any reports of similar problems. I hope it will be fixed soon :slight_smile: Is there any resource I can follow to track the issue status?

Since this is an Xcode issue, not really. You could file your own bug, but since it would be a duplicate, updates would only be pull-based (you could manually ask for an update of the status of the dupe).

Do you know if they have an open radar for this one @NeoNacho? I'm still experiencing on Xcode 13 with silicon Macs. Is this because I have excluded arm-64 from the build?

Error occured while exporting xccovreport from xcresult
Terms of Service

Privacy Policy

Cookie Policy