From bf1a70a6a2511e4b47b12298e40bbbd2b5b0e08a Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Wed, 10 Apr 2024 22:02:12 -0700 Subject: [PATCH] chore: bring in llvm toolchain so we can update //js/private/test/image snapshots on darwin (#1638) --- .bazelrc | 5 +++ WORKSPACE | 33 ++++++++++++++++ WORKSPACE.bzlmod | 83 +++++++++++++++++++++++++++++++++++++++++ js/dev_repositories.bzl | 50 +++++++++++++++++++++++++ 4 files changed, 171 insertions(+) diff --git a/.bazelrc b/.bazelrc index 6c9812dfd..9a4138673 100644 --- a/.bazelrc +++ b/.bazelrc @@ -11,6 +11,11 @@ import %workspace%/.aspect/bazelrc/performance.bazelrc # We have some empty globs in rules_js common --noincompatible_disallow_empty_glob +# Don't try and auto detect the cc toolchain, as we use our llvm. +build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 +build --incompatible_strict_action_env=true +build --incompatible_enable_cc_toolchain_resolution + # Disable lockfile for now. It is unstable. # https://github.com/bazelbuild/bazel/issues/19026 # https://github.com/bazelbuild/bazel/issues/19621 diff --git a/WORKSPACE b/WORKSPACE index 737c2d3ea..9412115b6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -221,3 +221,36 @@ load( fetch_shfmt() fetch_terraform() + +load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies") + +bazel_toolchain_dependencies() + +load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain") + +llvm_toolchain( + name = "llvm_toolchain", + llvm_version = "14.0.0", + sha256 = { + "darwin-aarch64": "1b8975db6b638b308c1ee437291f44cf8f67a2fb926eb2e6464efd180e843368", + "linux-x86_64": "564fcbd79c991e93fdf75f262fa7ac6553ec1dd04622f5d7db2a764c5dc7fac6", + }, + strip_prefix = { + "darwin-aarch64": "clang+llvm-14.0.0-arm64-apple-darwin", + "linux-x86_64": "clang+llvm-14.0.0-x86_64-linux-gnu", + }, + sysroot = { + "linux-aarch64": "@org_chromium_sysroot_linux_arm64//:sysroot", + "linux-x86_64": "@org_chromium_sysroot_linux_x86_64//:sysroot", + "darwin-aarch64": "@sysroot_darwin_universal//:sysroot", + "darwin-x86_64": "@sysroot_darwin_universal//:sysroot", + }, + urls = { + "darwin-aarch64": ["https://github.com/aspect-forks/llvm-project/releases/download/aspect-release-14.0.0/clang+llvm-14.0.0-arm64-apple-darwin.tar.xz"], + "linux-x86_64": ["https://github.com/aspect-forks/llvm-project/releases/download/aspect-release-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu.tar.xz"], + }, +) + +load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains") + +llvm_register_toolchains() diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index 03e4a2764..233dc29e7 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -18,3 +18,86 @@ http_archive( integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", ) + +http_archive( + name = "com_grail_bazel_toolchain", + sha256 = "a9fc7cf01d0ea0a935bd9e3674dd3103766db77dfc6aafcb447a7ddd6ca24a78", + strip_prefix = "toolchains_llvm-c65ef7a45907016a754e5bf5bfabac76eb702fd3", + urls = ["https://github.com/bazel-contrib/toolchains_llvm/archive/c65ef7a45907016a754e5bf5bfabac76eb702fd3.tar.gz"], +) + +_SYSROOT_LINUX_BUILD_FILE = """ +filegroup( + name = "sysroot", + srcs = glob(["*/**"]), + visibility = ["//visibility:public"], +) +""" + +_SYSROOT_DARWIN_BUILD_FILE = """ +filegroup( + name = "sysroot", + srcs = glob( + include = ["**"], + exclude = ["**/*:*"], + ), + visibility = ["//visibility:public"], +) +""" + +http_archive( + name = "org_chromium_sysroot_linux_arm64", + build_file_content = _SYSROOT_LINUX_BUILD_FILE, + sha256 = "cf2fefded0449f06d3cf634bfa94ffed60dbe47f2a14d2900b00eb9bcfb104b8", + urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/80fc74e431f37f590d0c85f16a9d8709088929e8/debian_bullseye_arm64_sysroot.tar.xz"], +) + +http_archive( + name = "org_chromium_sysroot_linux_x86_64", + build_file_content = _SYSROOT_LINUX_BUILD_FILE, + sha256 = "04b94ba1098b71f8543cb0ba6c36a6ea2890d4d417b04a08b907d96b38a48574", + urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/f5f68713249b52b35db9e08f67184cac392369ab/debian_bullseye_amd64_sysroot.tar.xz"], +) + +http_archive( + name = "sysroot_darwin_universal", + build_file_content = _SYSROOT_DARWIN_BUILD_FILE, + # The ruby header has an infinite symlink that we need to remove. + patch_cmds = ["rm System/Library/Frameworks/Ruby.framework/Versions/Current/Headers/ruby/ruby"], + sha256 = "71ae00a90be7a8c382179014969cec30d50e6e627570af283fbe52132958daaf", + strip_prefix = "MacOSX11.3.sdk", + urls = ["https://s3.us-east-2.amazonaws.com/static.aspect.build/sysroots/MacOSX11.3.sdk.tar.xz"], +) + +load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies") + +bazel_toolchain_dependencies() + +load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain") + +llvm_toolchain( + name = "llvm_toolchain", + llvm_version = "14.0.0", + sha256 = { + "darwin-aarch64": "1b8975db6b638b308c1ee437291f44cf8f67a2fb926eb2e6464efd180e843368", + "linux-x86_64": "564fcbd79c991e93fdf75f262fa7ac6553ec1dd04622f5d7db2a764c5dc7fac6", + }, + strip_prefix = { + "darwin-aarch64": "clang+llvm-14.0.0-arm64-apple-darwin", + "linux-x86_64": "clang+llvm-14.0.0-x86_64-linux-gnu", + }, + sysroot = { + "linux-aarch64": "@org_chromium_sysroot_linux_arm64//:sysroot", + "linux-x86_64": "@org_chromium_sysroot_linux_x86_64//:sysroot", + "darwin-aarch64": "@sysroot_darwin_universal//:sysroot", + "darwin-x86_64": "@sysroot_darwin_universal//:sysroot", + }, + urls = { + "darwin-aarch64": ["https://github.com/aspect-forks/llvm-project/releases/download/aspect-release-14.0.0/clang+llvm-14.0.0-arm64-apple-darwin.tar.xz"], + "linux-x86_64": ["https://github.com/aspect-forks/llvm-project/releases/download/aspect-release-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu.tar.xz"], + }, +) + +load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains") + +llvm_register_toolchains() diff --git a/js/dev_repositories.bzl b/js/dev_repositories.bzl index 63b95b80c..6a1911990 100644 --- a/js/dev_repositories.bzl +++ b/js/dev_repositories.bzl @@ -59,3 +59,53 @@ def rules_js_dev_dependencies(): url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", build_file = "//npm/private/test:vendored/chalk-5.0.1.BUILD", ) + + http_archive( + name = "com_grail_bazel_toolchain", + sha256 = "a9fc7cf01d0ea0a935bd9e3674dd3103766db77dfc6aafcb447a7ddd6ca24a78", + strip_prefix = "toolchains_llvm-c65ef7a45907016a754e5bf5bfabac76eb702fd3", + urls = ["https://github.com/bazel-contrib/toolchains_llvm/archive/c65ef7a45907016a754e5bf5bfabac76eb702fd3.tar.gz"], + ) + + http_archive( + name = "org_chromium_sysroot_linux_arm64", + build_file_content = _SYSROOT_LINUX_BUILD_FILE, + sha256 = "cf2fefded0449f06d3cf634bfa94ffed60dbe47f2a14d2900b00eb9bcfb104b8", + urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/80fc74e431f37f590d0c85f16a9d8709088929e8/debian_bullseye_arm64_sysroot.tar.xz"], + ) + + http_archive( + name = "org_chromium_sysroot_linux_x86_64", + build_file_content = _SYSROOT_LINUX_BUILD_FILE, + sha256 = "04b94ba1098b71f8543cb0ba6c36a6ea2890d4d417b04a08b907d96b38a48574", + urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/f5f68713249b52b35db9e08f67184cac392369ab/debian_bullseye_amd64_sysroot.tar.xz"], + ) + + http_archive( + name = "sysroot_darwin_universal", + build_file_content = _SYSROOT_DARWIN_BUILD_FILE, + # The ruby header has an infinite symlink that we need to remove. + patch_cmds = ["rm System/Library/Frameworks/Ruby.framework/Versions/Current/Headers/ruby/ruby"], + sha256 = "71ae00a90be7a8c382179014969cec30d50e6e627570af283fbe52132958daaf", + strip_prefix = "MacOSX11.3.sdk", + urls = ["https://s3.us-east-2.amazonaws.com/static.aspect.build/sysroots/MacOSX11.3.sdk.tar.xz"], + ) + +_SYSROOT_LINUX_BUILD_FILE = """ +filegroup( + name = "sysroot", + srcs = glob(["*/**"]), + visibility = ["//visibility:public"], +) +""" + +_SYSROOT_DARWIN_BUILD_FILE = """ +filegroup( + name = "sysroot", + srcs = glob( + include = ["**"], + exclude = ["**/*:*"], + ), + visibility = ["//visibility:public"], +) +"""