Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift package manager conditional compile not respecting flags

I have a Package.swift file with the following structure

var package = Package(
  name: "MyProject",
  targets: [
    Target(name: "MyProject")
  ],
  dependencies: [],
  exclude: ["Exclude"]
)

#if DEBUG
  package.dependencies.append(Package.Dependency.Package(url: "Dependency-One.git", majorVersion: 0, minor: 0))
#else
  package.dependencies.append(Package.Dependency.Package(url: "Dependency-Two.git", majorVersion: 0, minor: 0))
#endif

When I build this with any of the following:

swift build
swift build -c release
swift build -c debug
swift build -c RELEASE
swift build -c DEBUG

It still always downloads Dependency-Two.git. This remains true if I prepend all of the above with

rm -rf .build/ && rm -rf Packages/

So I don't think it's because it's reusing some cache. Is it possible to do what I'm intending here?

like image 741
Ethan Kay Avatar asked Oct 20 '25 15:10

Ethan Kay


1 Answers

Still not available. My workaround has been to create multiple Package.swift files, named like Package-DEBUG.swift and have a script copy the appropriate one to Package.swift at build time.

This is a really mindless workaround and the SPM developers really need to implement command-line flags.

like image 187
Reid Ellis Avatar answered Oct 23 '25 01:10

Reid Ellis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!