Higher deployment target in built for distribution libraries

Greetings swift users!

Just noticed that if some library was built with BUILD_FOR_DISTRIBUTION and has a higher deployment target than the app – app can import that library and it compiles fine. You can even call any api from that lib without guarding the availability.

Code to reproduce:

// MyApp.swift, deployment target iOS 15:
import SwiftUI
import Lib

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            viewFromLib()
        }
    }
}

// Lib.swift, deployment target iOS 16:
public func viewFromLib() -> some View {
  // calling random api available from iOS 16
  NavigationStack {
    EmptyView()
  }
}

If you try to build library without library evolution there will be an error:

error: compiling for iOS 15.0, but module 'Lib' 
has a minimum deployment target of iOS 16.0

Adding BUILD_LIBRARY_FOR_DISTRIBUTION = YES setting makes the error disappear, but it will crash in runtime on iOS 15.

It looks like a bug, but may be that was a deliberate decision?

And if some will actually use this behaviour to import libraries with higher deployment target, will it cause any problems other than necessity to carefully guard all api usages from that library?

Thanks!

1 Like