Skip to content

SwiftPM plugin doesn't work when integrated in the build phases of an Xcode project that contains nested SwiftPM packages #4628

@nkristek

Description

@nkristek

New Issue Checklist

Describe the bug

I have an Xcode project for an iOS app that contains nested SwiftPM packages. Until now SwiftLint was configured to run as a build phase that uses the installed version of the system, now I want to use the new SwiftPM plugin integration instead (to benefit from easier versioning control across multiple developers).

When using the SwiftLint plugin in the nested SwiftPM packages using the following code in the corresponding Package.swift:

dependencies: [
    .package(url: "https://github.com/realm/SwiftLint.git", branch: "main")
]
// ...
plugins: [
    .plugin(name: "SwiftLintPlugin", package: "SwiftLint")
]

the plugin works as intended.

However, when I try to integrate the plugin in the project (in order to lint the main app target) using the instructions here (adding the plugin in the Run Build Tool Plug-ins build phase), building the project fails with the error:

ld: entry point (_main) undefined. for architecture arm64

I'm building the project on an Apple Silicon based machine, but running Xcode under Rosetta2 results in the same error, but listing the Intel architecture instead. I've tried this in multiple codebases including a fresh iOS app (using the Xcode template) and I found out it always occurs once the project has a nested SwiftPM package.

Steps to reproduce

  • Using Xcode 14.1
  • Create a new project using the App template in the iOS category
    • Select Storyboard and Swift without Core Data or Tests
  • Now we'll add the nested SwiftPM package
  • Using Finder create a new folder called NestedModule inside the project folder
  • In that folder create a new file called Package.swift with these contents:
// swift-tools-version:5.7

import PackageDescription

let package = Package(
    name: "NestedModule",
    platforms: [
        .iOS(.v14),
    ],
    products: [
        .library(name: "Nested", targets: ["Nested"])
    ],
    targets: [
        .target(name: "Nested")
    ]
)
  • In the same folder create a new folder called Sources
  • Inside Sources create a folder called Nested
  • Inside Nested create an empty file called File.swift (to silence the warning about no source files)
  • Drag the folder NestedModule into Xcode directly below the project
    • Instead of having a normal folder icon, the icon should be that of a SwiftPM package, if it doesn't, please restart Xcode
  • In the project file > target > Frameworks, Libraries, and Embedded Content: press + to add the Nested module
  • Try to build the project -> succeeds
  • In the project file > project > SwiftPM dependencies: add SwiftLint (https://github.com/realm/SwiftLint.git targeting the main branch) without ticking any boxes when being asked if it should be included in the app
  • In the project file > target > build phases tab > Run Build Tool Plug-ins: press + to add the SwiftLint plug-in
  • Try to build the project -> fails with error ld: entry point (_main) undefined. for architecture arm64

Environment

  • SwiftLint version (run swiftlint version to be sure)?

    • main branch (which currently uses a prebuilt binary of 0.50.1 under the hood)
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?

    • SwiftPM
  • Paste your configuration file:

    • Default
  • Are you using nested configurations?

    • No
  • Which Xcode version are you using (check xcodebuild -version)?

    • 14.1
  • Do you have a sample that shows the issue?

    • Reproducible with the steps above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions