Skip to content

Commit 76c5303

Browse files
committed
Fix resource issue with mixed Clang sources
1 parent 6429af2 commit 76c5303

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ public final class ClangTargetBuildDescription {
407407

408408
/// Builds up basic compilation arguments for a source file in this target; these arguments may be different for C++ vs non-C++.
409409
/// NOTE: The parameter to specify whether to get C++ semantics is currently optional, but this is only for revlock avoidance with clients. Callers should always specify what they want based either the user's indication or on a default value (possibly based on the filename suffix).
410-
public func basicArguments(isCXX isCXXOverride: Bool? = .none) throws -> [String] {
410+
public func basicArguments(
411+
isCXX isCXXOverride: Bool? = .none,
412+
isC isCOverride: Bool = false
413+
) throws -> [String] {
411414
// For now fall back on the hold semantics if the C++ nature isn't specified. This is temporary until clients have been updated.
412415
let isCXX = isCXXOverride ?? clangTarget.isCXX
413416

@@ -470,7 +473,10 @@ public final class ClangTargetBuildDescription {
470473
// Add arguments from declared build settings.
471474
args += try self.buildSettingsFlags()
472475

473-
if let resourceAccessorHeaderFile = self.resourceAccessorHeaderFile {
476+
// Include the path to the resource header unless the arguments are
477+
// being evaluated for a C file. A C file cannot depend on the resource
478+
// accessor header due to it exporting a Foundation type (`NSBundle`).
479+
if let resourceAccessorHeaderFile = self.resourceAccessorHeaderFile, !isCOverride {
474480
args += ["-include", resourceAccessorHeaderFile.pathString]
475481
}
476482

Sources/Build/LLBuildManifestBuilder.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,9 @@ extension LLBuildManifestBuilder {
823823

824824
for path in try target.compilePaths() {
825825
let isCXX = path.source.extension.map{ SupportedLanguageExtension.cppExtensions.contains($0) } ?? false
826-
var args = try target.basicArguments(isCXX: isCXX)
826+
let isC = path.source.extension.map { $0 == SupportedLanguageExtension.c.rawValue } ?? false
827+
828+
var args = try target.basicArguments(isCXX: isCXX, isC: isC)
827829

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

0 commit comments

Comments
 (0)