From c2df13eb6d0661c77bb3ed54c65a8b911fbb949d Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Wed, 4 Jun 2025 14:10:38 -0400 Subject: [PATCH 1/2] [repro] module maps created for or on objc_library do not propagate to transitive objc_library this is a repro of an issue i've identified while trying to move to `mixed_language_library` from our custom macro. Regardless of how `module_map` is hinted in `swift_interop_info`, generated, or otherwise attached to an `objc_library`, out-of-the-box these module maps are not propagated to downstream `objc_library` in a `objc -> swift -> objc` arrangement. this is especially problematic in scenarios where PrintAsClang, going by its own uncontrollable heuristics, inserts an `@import` line for the upstream objc library in a generated header. this is something that needs to change in either `swift_clang_module_aspect` or `objc_library` to discover or otherwise propagate the upstream module maps, as this simple example does not work without customization of the rules or introducing manual dependencies on modulemaps (which isn't possible if relying on the generated modulemaps from the aspect). --- examples/apple/objc_interop_modulemap/OIPrintStream.h | 7 ++++++- examples/apple/objc_interop_modulemap/OIPrintStream.m | 3 +++ examples/apple/objc_interop_modulemap/Printer.swift | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/apple/objc_interop_modulemap/OIPrintStream.h b/examples/apple/objc_interop_modulemap/OIPrintStream.h index 2873ba84f..a4f0acb4c 100644 --- a/examples/apple/objc_interop_modulemap/OIPrintStream.h +++ b/examples/apple/objc_interop_modulemap/OIPrintStream.h @@ -14,11 +14,16 @@ #import +@protocol Stupid +@end + /** A very contrived interface for writing strings to a file handle. */ -@interface OIPrintStream : NSObject +@interface OIPrintStream : NSObject - (nonnull instancetype)initWithFileHandle:(nonnull NSFileHandle *)fileHandle; +- (void)print:(nonnull PrintType)message; + - (void)printString:(nonnull NSString *)message; @end diff --git a/examples/apple/objc_interop_modulemap/OIPrintStream.m b/examples/apple/objc_interop_modulemap/OIPrintStream.m index 76f8b9278..ccd8ec7b5 100644 --- a/examples/apple/objc_interop_modulemap/OIPrintStream.m +++ b/examples/apple/objc_interop_modulemap/OIPrintStream.m @@ -25,6 +25,9 @@ - (instancetype)initWithFileHandle:(nonnull NSFileHandle *)fileHandle { return self; } +- (void)print:(nonnull id)message { +} + - (void)printString:(nonnull NSString *)message { NSData *data = [message dataUsingEncoding:NSUTF8StringEncoding]; [_fileHandle writeData:data]; diff --git a/examples/apple/objc_interop_modulemap/Printer.swift b/examples/apple/objc_interop_modulemap/Printer.swift index bba520a3b..c1534ac8f 100644 --- a/examples/apple/objc_interop_modulemap/Printer.swift +++ b/examples/apple/objc_interop_modulemap/Printer.swift @@ -15,10 +15,13 @@ import Foundation import examples_apple_objc_interop_modulemap_PrintStream +@objc public protocol MyStupid { +} + @objc(OIPrinter) public class Printer: NSObject { - private let stream: OIPrintStream + private let stream: OIPrintStream private let prefix: String @objc public init(prefix: NSString) { @@ -26,6 +29,10 @@ public class Printer: NSObject { self.prefix = prefix as String } + @objc public func stream(_ thing: MyStupid) -> OIPrintStream { + return stream + } + @objc public func print(_ message: NSString) { stream.print("\(prefix)\(message)") } From 50e44f2248b50ce8946435c99ac61c05394e9ee1 Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Wed, 4 Jun 2025 14:20:38 -0400 Subject: [PATCH 2/2] simplify repro --- examples/apple/objc_interop/OIPrintStream.h | 4 +++- examples/apple/objc_interop/OIPrintStream.m | 3 +++ examples/apple/objc_interop/Printer.swift | 9 ++++++++- examples/apple/objc_interop_modulemap/OIPrintStream.h | 3 --- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/apple/objc_interop/OIPrintStream.h b/examples/apple/objc_interop/OIPrintStream.h index 2873ba84f..481e44ab7 100644 --- a/examples/apple/objc_interop/OIPrintStream.h +++ b/examples/apple/objc_interop/OIPrintStream.h @@ -15,10 +15,12 @@ #import /** A very contrived interface for writing strings to a file handle. */ -@interface OIPrintStream : NSObject +@interface OIPrintStream : NSObject - (nonnull instancetype)initWithFileHandle:(nonnull NSFileHandle *)fileHandle; +- (void)print:(nonnull PrintType)message; + - (void)printString:(nonnull NSString *)message; @end diff --git a/examples/apple/objc_interop/OIPrintStream.m b/examples/apple/objc_interop/OIPrintStream.m index 1e1428509..82f9d4013 100644 --- a/examples/apple/objc_interop/OIPrintStream.m +++ b/examples/apple/objc_interop/OIPrintStream.m @@ -25,6 +25,9 @@ - (instancetype)initWithFileHandle:(nonnull NSFileHandle *)fileHandle { return self; } +- (void)print:(nonnull id)message { +} + - (void)printString:(nonnull NSString *)message { NSData *data = [message dataUsingEncoding:NSUTF8StringEncoding]; [_fileHandle writeData:data]; diff --git a/examples/apple/objc_interop/Printer.swift b/examples/apple/objc_interop/Printer.swift index 3d65eb508..526d70ed3 100644 --- a/examples/apple/objc_interop/Printer.swift +++ b/examples/apple/objc_interop/Printer.swift @@ -15,10 +15,13 @@ import Foundation import examples_apple_objc_interop_PrintStream +@objc public protocol MyStupid { +} + @objc(OIPrinter) public class Printer: NSObject { - private let stream: OIPrintStream + private let stream: OIPrintStream private let prefix: String @objc public init(prefix: NSString) { @@ -26,6 +29,10 @@ public class Printer: NSObject { self.prefix = prefix as String } + @objc public func stream(_ thing: MyStupid) -> OIPrintStream { + return stream + } + @objc public func print(_ message: NSString) { stream.print("\(prefix)\(message)") } diff --git a/examples/apple/objc_interop_modulemap/OIPrintStream.h b/examples/apple/objc_interop_modulemap/OIPrintStream.h index a4f0acb4c..481e44ab7 100644 --- a/examples/apple/objc_interop_modulemap/OIPrintStream.h +++ b/examples/apple/objc_interop_modulemap/OIPrintStream.h @@ -14,9 +14,6 @@ #import -@protocol Stupid -@end - /** A very contrived interface for writing strings to a file handle. */ @interface OIPrintStream : NSObject