Skip to content

Remove -index-store-path for clang vendor is not Apple #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,15 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
var commandLine = Array<String>()

// Add the arguments from the specification.
commandLine += self.commandLineFromOptions(producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext).map(\.asString)
commandLine += self.commandLineFromOptions(producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext,lookup: { declaration in
if declaration.name == "CLANG_INDEX_STORE_ENABLE" && optionContext is DiscoveredClangToolSpecInfo {
let clangToolInfo = optionContext as! DiscoveredClangToolSpecInfo
if !clangToolInfo.isAppleClang {
return BuiltinMacros.namespace.parseString("NO")
}
}
return nil
}).map(\.asString)

// Add the common header search paths.
let headerSearchPaths = GCCCompatibleCompilerSpecSupport.headerSearchPathArguments(producer, scope, usesModules: scope.evaluate(BuiltinMacros.CLANG_ENABLE_MODULES))
Expand Down
9 changes: 8 additions & 1 deletion Sources/SWBCore/ToolInfo/ClangToolInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
public let toolPath: Path
public let clangVersion: Version?
public let llvmVersion: Version?
public let isAppleClang: Bool

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

Expand Down Expand Up @@ -79,7 +80,7 @@ public func discoveredClangToolInfo(
) async throws -> DiscoveredClangToolSpecInfo {
// 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.
guard toolPath.basename.starts(with: "clang") else {
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, clangCachingBlocklist: nil, toolFeatures: .none)
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, isAppleClang: false, clangCachingBlocklist: nil, toolFeatures: .none)
}

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

var clangVersion: Version? = nil
var llvmVersion: Version? = nil
var isAppleClang = false

for line in outputString.components(separatedBy: "\n") {
if line.hasPrefix("#define ") {
Expand All @@ -123,6 +125,10 @@ public func discoveredClangToolInfo(
llvmVersion = try? Version(String(match.llvm))
}
}

if macroName == "__apple_build_version__" {
isAppleClang = true
}
}
}

Expand Down Expand Up @@ -157,6 +163,7 @@ public func discoveredClangToolInfo(
toolPath: toolPath,
clangVersion: clangVersion,
llvmVersion: llvmVersion,
isAppleClang: isAppleClang,
clangCachingBlocklist: getBlocklist(type: ClangCachingBlockListInfo.self, toolchainFilename: "clang-caching.json", delegate: delegate),
toolFeatures: getFeatures(at: toolPath)
)
Expand Down