mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Detect if there's a built version of clang within the workspace (#260)
This commit is contained in:
@@ -17,8 +17,8 @@ http_archive(
|
||||
# Add Bazel's python rules.
|
||||
http_archive(
|
||||
name = "rules_python",
|
||||
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
|
||||
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
|
||||
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
|
||||
)
|
||||
|
||||
# Set up necessary dependencies for working with the foreign C++ rules.
|
||||
@@ -29,7 +29,10 @@ rules_foreign_cc_dependencies()
|
||||
# Detect and configure a Clang and LLVM based toolchain.
|
||||
load("//bazel/cc_toolchains:clang_detection.bzl", "detect_clang_toolchain")
|
||||
|
||||
detect_clang_toolchain(name = "bazel_cc_toolchain")
|
||||
detect_clang_toolchain(
|
||||
name = "bazel_cc_toolchain",
|
||||
workspace_dir = __workspace_dir__,
|
||||
)
|
||||
|
||||
local_repository(
|
||||
name = "llvm_bazel",
|
||||
|
||||
@@ -37,19 +37,22 @@ def _find_clang(repository_ctx):
|
||||
This assumes the `CC` environment variable points to a Clang binary or
|
||||
looks for one on the path.
|
||||
"""
|
||||
cc_env = repository_ctx.os.environ.get("CC")
|
||||
if not cc_env:
|
||||
# Without a specified `CC` name, simply look for `clang`.
|
||||
clang = repository_ctx.which("clang")
|
||||
elif "/" not in cc_env:
|
||||
# Lookup relative `CC` names according to the system `PATH`.
|
||||
clang = repository_ctx.which(cc_env)
|
||||
else:
|
||||
# An absolute `CC` path is simply be used directly.
|
||||
clang = repository_ctx.path(cc_env)
|
||||
if not clang.exists:
|
||||
fail(("The `CC` environment variable is set to a path (`%s`) " +
|
||||
"that doesn't exist.") % cc_env)
|
||||
clang = repository_ctx.path("%s/third_party/llvm-project/build/bin/clang" %
|
||||
repository_ctx.attr.workspace_dir)
|
||||
if not clang.exists:
|
||||
cc_env = repository_ctx.os.environ.get("CC")
|
||||
if not cc_env:
|
||||
# Without a specified `CC` name, simply look for `clang`.
|
||||
clang = repository_ctx.which("clang")
|
||||
elif "/" not in cc_env:
|
||||
# Lookup relative `CC` names according to the system `PATH`.
|
||||
clang = repository_ctx.which(cc_env)
|
||||
else:
|
||||
# An absolute `CC` path is simply be used directly.
|
||||
clang = repository_ctx.path(cc_env)
|
||||
if not clang.exists:
|
||||
fail(("The `CC` environment variable is set to a path (`%s`) " +
|
||||
"that doesn't exist.") % cc_env)
|
||||
|
||||
# Check if either of the `which` invocations fail.
|
||||
if not clang:
|
||||
@@ -152,6 +155,7 @@ detect_clang_toolchain = repository_rule(
|
||||
configure = True,
|
||||
local = True,
|
||||
attrs = {
|
||||
"workspace_dir": attr.string(mandatory = True),
|
||||
"_clang_toolchain_build": attr.label(
|
||||
default = Label("//bazel/cc_toolchains:clang_toolchain.BUILD"),
|
||||
allow_single_file = True,
|
||||
|
||||
@@ -117,11 +117,16 @@ Our recommended way of installing is:
|
||||
### Clang and LLVM
|
||||
|
||||
[Clang](https://clang.llvm.org/) and [LLVM](https://llvm.org/) are used to
|
||||
compile and link Carbon. It's currently recommended to build LLVM from head in
|
||||
order to avoid compatibility issues in many distributions.
|
||||
compile and link Carbon.
|
||||
|
||||
Please refer to
|
||||
[LLVM's build instructions](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm).
|
||||
If the `CC` environment variable is set to `clang`, or if `clang` is in the
|
||||
path, it can be used without building LLVM from head. However, it's currently
|
||||
recommended to build LLVM from head in order to avoid compatibility issues in
|
||||
many distributions. Once `third_party/llvm-project/build/bin/clang` exists, it
|
||||
will automatically be used instead of `CC`.
|
||||
|
||||
In order to build `third_party/llvm-project/build/bin/clang`, please refer to
|
||||
[LLVM's instructions](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm).
|
||||
Tips:
|
||||
|
||||
- When `carbon-lang` is checked out with submodules, the LLVM submodule is at
|
||||
|
||||
Reference in New Issue
Block a user