Skip to content

[Toolchain] Lookup clang in the toolchain #2159

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
merged 1 commit into from
Jun 13, 2019
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
29 changes: 17 additions & 12 deletions Sources/Workspace/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,35 @@ public final class UserToolchain: Toolchain {
return toolPath
}

// Otherwise, lookup the tool on the system.
// Then, check the toolchain.
do {
let toolPath = destination.binDir.appending(component: "clang" + hostExecutableSuffix)
if localFileSystem.exists(toolPath) {
_clangCompiler = toolPath
return toolPath
}
}

// Otherwise, lookup it up on the system.
let arguments = whichArgs + ["clang"]
let foundPath = try Process.checkNonZeroExit(arguments: arguments, environment: processEnvironment).spm_chomp()
guard !foundPath.isEmpty else {
throw InvalidToolchainDiagnostic("could not find clang")
}
let toolPath = try AbsolutePath(validating: foundPath)

// If we found clang using xcrun, assume the vendor is Apple.
// FIXME: This might not be the best way to determine this.
#if os(macOS)
__isClangCompilerVendorApple = true
#endif

_clangCompiler = toolPath
return toolPath
}
private var _clangCompiler: AbsolutePath?
private var __isClangCompilerVendorApple: Bool?

public func _isClangCompilerVendorApple() throws -> Bool? {
// The boolean gets computed as a side-effect of lookup for clang compiler.
_ = try getClangCompiler()
return __isClangCompilerVendorApple
// Assume the vendor is Apple on macOS.
// FIXME: This might not be the best way to determine this.
#if os(macOS)
return true
#else
return false
#endif
}

/// Returns the path to llvm-cov tool.
Expand Down
18 changes: 17 additions & 1 deletion Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class Target(object):

link_input_nodes.append(object_path)

args = ["clang"]
args = [args.clang_path]
args.extend(common_args)
args.extend([deps_path, "-c", source,"-o", object_path])

Expand Down Expand Up @@ -733,6 +733,20 @@ def get_llbuild_source_path():
note("clone llbuild next to swiftpm directory; see development docs: https://github.com/apple/swift-package-manager/blob/master/Documentation/Development.md#using-trunk-snapshot")
error("unable to find llbuild source directory at %s" % llbuild_path)

def get_clang_path():
try:
if os.getenv("CC"):
clang_path=os.path.realpath(os.getenv("CC"))
return clang_path
elif platform.system() == 'Darwin':
return subprocess.check_output(["xcrun", "--find", "clang"],
stderr=subprocess.PIPE, universal_newlines=True).strip()
else:
return subprocess.check_output(["which", "clang"],
universal_newlines=True).strip()
except:
error("unable to find 'clang' tool for bootstrap build")

def get_swiftc_path():
try:
if os.getenv("SWIFT_EXEC"):
Expand Down Expand Up @@ -978,6 +992,7 @@ def main():

if not args.swiftc_path:
args.swiftc_path = get_swiftc_path()
args.clang_path = get_clang_path()

args.swift_stdlib_path = os.path.normpath(
os.path.join(os.path.dirname(os.path.realpath(args.swiftc_path)), "..",
Expand Down Expand Up @@ -1128,6 +1143,7 @@ def main():
def make_fake_toolchain():
symlink_force(args.swiftc_path, os.path.join(bindir, "swift"))
symlink_force(args.swiftc_path, os.path.join(bindir, "swiftc"))
symlink_force(args.clang_path, os.path.join(bindir, "clang"))
symlink_force(args.sbt_path, os.path.join(bindir, "swift-build-tool"))
symlink_force(os.path.join(sandbox_path, "bin", "swift-build"),
bootstrapped_product)
Expand Down