Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warnings from dependencies with Swift Package Manager

Assuming I have a Package.swift like this below, and SomePackage from the dependencies produces warnings during swift build.

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "my-app",
    dependencies: [
        .package(url: "https://some-package.git", .upToNextMajor(from: "1.0"))
    ],
    targets: [
        .target(name: "Run", dependencies: ["SomePackage"]
    ]
)

How can I suppress those warnings from the dependencies, but keep the ones coming from my code?

like image 265
Dannie P Avatar asked Nov 16 '17 15:11

Dannie P


People also ask

How do I ignore a warning in Swift?

If you want to disable all warnings, you can pass the -suppress-warnings flag (or turn on "Suppress Warnings" under "Swift Compiler - Warning Policies" in Xcode build settings).

Where are swift package dependencies stored?

In order to cache the dependencies, they should be located in the project directory, but by default, SPM downloads the dependencies into the system folder: ~/Library/Developer/Xcode/DerivedData.


2 Answers

With Swift Tools Version 5 you may define compiler flags in the package file (see https://docs.swift.org/package-manager/PackageDescription/PackageDescription.html#swiftsetting). Here is an example for a Package.swift which suppresses compiler warnings during build:

// swift-tools-version:5.0

import PackageDescription

let package = Package(
    name: "Antlr4",
    products: [
        .library(
            name: "Antlr4",
            targets: ["Antlr4"]),
    ],
    targets: [
        .target(
            name: "Antlr4",
            dependencies: [],
            swiftSettings: [
                .unsafeFlags(["-suppress-warnings"]),
            ]),
        .testTarget(
            name: "Antlr4Tests",
            dependencies: ["Antlr4"]),
    ]
)

To suppress warnings only in foreign code you should split the code into two packages.

like image 56
clemens Avatar answered Oct 25 '22 08:10

clemens


For Objective-C modules, you can use the following to disable all warnings:

cSettings: [
   .unsafeFlags(["-w"])
]
like image 21
Patrick Avatar answered Oct 25 '22 07:10

Patrick