blob: ee1e8552571962402f62be4993e99ffbce4293ba [file] [log] [blame]
This file assembles a toolchain for a Mac host (either M1 or Intel) using the Clang Compiler
and a locally-installed XCode.
It downloads the necessary executables and creates symlinks in the external subfolder of the Bazel
cache (the same place third party deps are downloaded with http_archive or similar functions in
WORKSPACE.bazel). These will be able to be used via our
custom c++ toolchain configuration (see //toolchain/mac_toolchain_config.bzl)
The destination folder for these files and symlinks are:
[outputRoot (aka Bazel cache)]/[outputUserRoot]/[outputBase]/external/clang_mac
load(":clang_layering_check.bzl", "generate_system_module_map")
load(":utils.bzl", "gcs_mirror_url")
# From
# When updating this, don't forget to use //bazel/gcs_mirror to upload a new version.
# go run bazel/gcs_mirror/gcs_mirror.go --url [clang_url] --sha256 [clang_sha256]
clang_prefix_arm64 = "clang+llvm-15.0.1-arm64-apple-darwin21.0"
clang_sha256_arm64 = "858f86d96b5e4880f69f7a583daddbf97ee94e7cffce0d53aa05cba6967f13b8"
clang_url_arm64 = ""
clang_prefix_amd64 = "clang+llvm-15.0.1-x86_64-apple-darwin"
clang_sha256_amd64 = "0b2f1a811e68d011344103274733b7670c15bbe08b2a3a5140ccad8e19d9311e"
clang_url_amd64 = ""
def _download_mac_toolchain_impl(ctx):
if ctx.os.arch == "aarch64":
clang_url = clang_url_arm64
clang_sha256 = clang_sha256_arm64
clang_prefix = clang_prefix_arm64
clang_url = clang_url_amd64
clang_sha256 = clang_sha256_amd64
clang_prefix = clang_prefix_amd64
# Download the clang toolchain (the extraction can take a while)
url = gcs_mirror_url(clang_url, clang_sha256),
output = "",
stripPrefix = clang_prefix,
sha256 = clang_sha256,
# Some std library headers use #include_next to include system specific headers, and
# some skia source files require Xcode headers when compiling, (see SkTypes.h and look
# for TargetedConditionals.h)) All of these are located in Xcode, stopping the Mac
# builds from being purely hermetic.
# For now, we can grab the user's Xcode path by calling xcode-select and create a symlink in
# our toolchain directory to refer to during compilation.
# We also create a symlink in the user's home directory for linking.
ctx.execute(["rm", "-rf", "~/.skiabazel"])
ctx.execute(["mkdir", "-p", "~/.skiabazel/symlinks/xcode"])
res = ctx.execute(["xcode-select", "-p"])
# from =
res.stdout.rstrip() + "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr",
# to =
# from =
res.stdout.rstrip() + "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
# to =
# Global symlink for future toolchain configs
sdk_path = res.stdout.rstrip() + "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"
symlink_path = "~/.skiabazel/symlinks/xcode/MacSDK/"
ctx.execute(["ln -s", sdk_path, symlink_path])
# This list of files lines up with _make_default_flags() in mac_toolchain_config.bzl
# It is all locations that our toolchain could find a system header.
builtin_include_directories = [
module_file = "toolchain_system_headers.modulemap",
folders = builtin_include_directories,
# Create a BUILD.bazel file that makes the files necessary for compiling,
# linking and creating archive files visible to Bazel.
# The smaller the globs are, the more performant the sandboxed builds will be.
# Additionally, globs that are too wide can pick up infinite symlink loops,
# and be difficult to quash:
content = """
# Generated from ctx.file action in download_mac_toolchain.bzl
name = "generated_module_map",
srcs = ["toolchain_system_headers.modulemap"],
visibility = ["//visibility:public"],
name = "archive_files",
srcs = [
visibility = ["//visibility:public"],
name = "compile_files",
srcs = [
] + glob(
include = [
allow_empty = False,
visibility = ["//visibility:public"],
name = "link_files",
srcs = [
visibility = ["//visibility:public"],
executable = False,
download_mac_toolchain = repository_rule(
implementation = _download_mac_toolchain_impl,
attrs = {},
doc = "Downloads clang to build Skia with." +
"Assumes you have xcode located on your device and have" +
"xcode-select in your $PATH.",