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?
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).
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.
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.
For Objective-C modules, you can use the following to disable all warnings:
cSettings: [
.unsafeFlags(["-w"])
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With