Skip to content

Commit 6976671

Browse files
authored
Remove -index-store-path for clang vendor is not Apple (#142)
* Remove -index-store-path if not clang vendor not Apple * Fix Apple Clang Detection * Update: Overriding COMPILER_INDEX_STORE_ENABLE to NO for non-Apple Clangs
1 parent 8012c0b commit 6976671

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,15 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
612612
var commandLine = Array<String>()
613613

614614
// Add the arguments from the specification.
615-
commandLine += self.commandLineFromOptions(producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext).map(\.asString)
615+
commandLine += self.commandLineFromOptions(producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext,lookup: { declaration in
616+
if declaration.name == "CLANG_INDEX_STORE_ENABLE" && optionContext is DiscoveredClangToolSpecInfo {
617+
let clangToolInfo = optionContext as! DiscoveredClangToolSpecInfo
618+
if !clangToolInfo.isAppleClang {
619+
return BuiltinMacros.namespace.parseString("NO")
620+
}
621+
}
622+
return nil
623+
}).map(\.asString)
616624

617625
// Add the common header search paths.
618626
let headerSearchPaths = GCCCompatibleCompilerSpecSupport.headerSearchPathArguments(producer, scope, usesModules: scope.evaluate(BuiltinMacros.CLANG_ENABLE_MODULES))

Sources/SWBCore/ToolInfo/ClangToolInfo.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
1616
public let toolPath: Path
1717
public let clangVersion: Version?
1818
public let llvmVersion: Version?
19+
public let isAppleClang: Bool
1920

2021
public var toolVersion: Version? { return self.clangVersion }
2122

@@ -79,7 +80,7 @@ public func discoveredClangToolInfo(
7980
) async throws -> DiscoveredClangToolSpecInfo {
8081
// Check that we call a clang variant, 'clang', 'clang++' etc. Note that a test sets `CC` to `/usr/bin/yes` so avoid calling that here.
8182
guard toolPath.basename.starts(with: "clang") else {
82-
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, clangCachingBlocklist: nil, toolFeatures: .none)
83+
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, isAppleClang: false, clangCachingBlocklist: nil, toolFeatures: .none)
8384
}
8485

8586
// Construct the command line to invoke.
@@ -102,6 +103,7 @@ public func discoveredClangToolInfo(
102103

103104
var clangVersion: Version? = nil
104105
var llvmVersion: Version? = nil
106+
var isAppleClang = false
105107

106108
for line in outputString.components(separatedBy: "\n") {
107109
if line.hasPrefix("#define ") {
@@ -123,6 +125,10 @@ public func discoveredClangToolInfo(
123125
llvmVersion = try? Version(String(match.llvm))
124126
}
125127
}
128+
129+
if macroName == "__apple_build_version__" {
130+
isAppleClang = true
131+
}
126132
}
127133
}
128134

@@ -157,6 +163,7 @@ public func discoveredClangToolInfo(
157163
toolPath: toolPath,
158164
clangVersion: clangVersion,
159165
llvmVersion: llvmVersion,
166+
isAppleClang: isAppleClang,
160167
clangCachingBlocklist: getBlocklist(type: ClangCachingBlockListInfo.self, toolchainFilename: "clang-caching.json", delegate: delegate),
161168
toolFeatures: getFeatures(at: toolPath)
162169
)

0 commit comments

Comments
 (0)