Skip to content

Commit

Permalink
Fix private header support in experimental_mixed_language_library (#…
Browse files Browse the repository at this point in the history
…2422)

I was running into an issue where an
`experimental_mixed_language_library` declared a private header via
`srcs`. A type from this header was used in the Swift module part of the
mixed library leading to not found errors.

This adds the private headers to the module map we create for the
`swift_library` allowing it to find the types in the those headers. Note
that because this is not the "umbrella" modulemap, the private headers
do not end up being exposed publicly to dependencies of this mixed
library and are only available within the mixed library as intended.
  • Loading branch information
luispadron authored Mar 8, 2024
1 parent 824fc38 commit 3a46721
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apple/internal/experimental_mixed_language_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ target only contains Objective-C files.""")
swift_copts += header_map_ctx.swift_copts

# Generate module map for the underlying Obj-C module
# This is the modulemap used exclusively by the swift_library
# as such we export all the headers including the private ones so they can be found in the Swift module.
objc_module_map_name = name + ".internal.objc"
textual_hdrs = kwargs.get("textual_hdrs", [])
_module_map(
name = objc_module_map_name,
hdrs = hdrs,
hdrs = hdrs + private_hdrs,
module_name = module_name,
textual_hdrs = textual_hdrs,
testonly = testonly,
Expand Down
1 change: 1 addition & 0 deletions examples/multi_platform/MixedLib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ experimental_mixed_language_library(
srcs = [
"MixedAnswer.m",
"MixedAnswer.swift",
"MixedAnswerPrivate.h", # private header support
],
hdrs = ["MixedAnswer.h"],
enable_modules = True,
Expand Down
5 changes: 5 additions & 0 deletions examples/multi_platform/MixedLib/MixedAnswer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public class MixedAnswerSwift: NSObject {
"\(MixedAnswerObjc.mixedAnswerObjc() ?? "invalid")_swiftMixedAnswer"
}

public
static func swiftMixedAnswerPrivate() -> String {
"\(MixedAnswerPrivateObjc.mixedAnswerPrivateObjc() ?? "invalid")_swiftPrivateMixedAnswer"
}

@objc
public
static func swiftToObjcMixedAnswer() -> String {
Expand Down
7 changes: 7 additions & 0 deletions examples/multi_platform/MixedLib/MixedAnswerPrivate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import Foundation;

@interface MixedAnswerPrivateObjc : NSObject

+ (NSString *)mixedAnswerPrivateObjc;

@end

0 comments on commit 3a46721

Please sign in to comment.