Skip to content

Commit 82d5603

Browse files
authored
Guard resource access header with __OBJC__ to exclude Foundation.h (#7962)
Guard resource access header with `__OBJC__` to avoid including `Foundation.h` in languages that do not support it, i.e. non-objc/c++ Add check the file extension for assembly files to not include `Foundation.h` there as well. Fixes: #7949
1 parent d0d4ecb commit 82d5603

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Fixtures/Resources/Simple/Sources/MixedClangResource/baz.S

Whitespace-only changes.

Fixtures/Resources/Simple/Sources/MixedClangResource/qux.cpp

Whitespace-only changes.

Sources/Build/BuildDescription/ClangModuleBuildDescription.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public final class ClangModuleBuildDescription {
253253
/// default value (possibly based on the filename suffix).
254254
public func basicArguments(
255255
isCXX isCXXOverride: Bool? = .none,
256-
isC: Bool = false
256+
isC: Bool = false,
257+
isAsm: Bool = false
257258
) throws -> [String] {
258259
// For now fall back on the hold semantics if the C++ nature isn't specified. This is temporary until clients
259260
// have been updated.
@@ -307,7 +308,7 @@ public final class ClangModuleBuildDescription {
307308
// Include the path to the resource header unless the arguments are
308309
// being evaluated for a C file. A C file cannot depend on the resource
309310
// accessor header due to it exporting a Foundation type (`NSBundle`).
310-
if let resourceAccessorHeaderFile, !isC {
311+
if let resourceAccessorHeaderFile, !isC && !isAsm {
311312
args += ["-include", resourceAccessorHeaderFile.pathString]
312313
}
313314

@@ -387,8 +388,9 @@ public final class ClangModuleBuildDescription {
387388

388389
let isCXX = path.source.extension.map { SupportedLanguageExtension.cppExtensions.contains($0) } ?? false
389390
let isC = path.source.extension.map { $0 == SupportedLanguageExtension.c.rawValue } ?? false
391+
let isAsm = path.source.extension.map { SupportedLanguageExtension.assemblyExtensions.contains($0) } ?? false
390392

391-
var args = try basicArguments(isCXX: isCXX, isC: isC)
393+
var args = try basicArguments(isCXX: isCXX, isC: isC, isAsm: isAsm)
392394

393395
args += ["-MD", "-MT", "dependencies", "-MF", path.deps.pathString]
394396

@@ -512,6 +514,7 @@ public final class ClangModuleBuildDescription {
512514

513515
let headerContent =
514516
"""
517+
#if __OBJC__
515518
#import <Foundation/Foundation.h>
516519
517520
#if __cplusplus
@@ -525,6 +528,7 @@ public final class ClangModuleBuildDescription {
525528
#if __cplusplus
526529
}
527530
#endif
531+
#endif
528532
"""
529533

530534
let headerFile = derivedSources.root.appending("resource_bundle_accessor.h")
@@ -549,4 +553,4 @@ extension ClangModuleBuildDescription {
549553
) -> [ModuleBuildDescription.Dependency] {
550554
ModuleBuildDescription.clang(self).recursiveDependencies(using: plan)
551555
}
552-
}
556+
}

0 commit comments

Comments
 (0)