From 7a20a4bbec0ad29684d16e7a2889b2ee8077aa13 Mon Sep 17 00:00:00 2001 From: Sambhav Jain Date: Thu, 19 Oct 2023 06:36:49 -0700 Subject: [PATCH] ability to test 3p deps checked out as local repos fix --- .bazelignore | 6 ++++ .gitignore | 14 +++++--- deps.bzl | 92 +++++++++++++++++++++++++++++++++---------------- local_repos.bzl | 36 +++++++++++++++++++ 4 files changed, 115 insertions(+), 33 deletions(-) create mode 100644 .bazelignore create mode 100644 local_repos.bzl diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000..6e1e2bd6 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,6 @@ +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# Also available under a BSD-style license. See LICENSE. + +third_party/ diff --git a/.gitignore b/.gitignore index 7c15a388..1c5de2d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,10 @@ -/bazel-bin -/bazel-out -/bazel-mlir-tcp -/bazel-testlogs +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# Also available under a BSD-style license. See LICENSE. + +bazel-bin +bazel-out +bazel-mlir-tcp +bazel-testlogs +third_party/ diff --git a/deps.bzl b/deps.bzl index 8e78fba5..8531c573 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,37 +1,71 @@ +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# Also available under a BSD-style license. See LICENSE. + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load( + ":local_repos.bzl", + "local_llvm_repo_path", + "local_stablehlo_repo_path", + "local_torch_mlir_repo_path", + "use_local_llvm_repo", + "use_local_stablehlo_repo", + "use_local_torch_mlir_repo", +) def third_party_deps(): - LLVM_COMMIT = "28b27c1b10ae8d1f5b4fb9df691e8cf0da9be3f6" - LLVM_SHA256 = "1f7a7ca5983801d671901644659c32d028e5e7316418fabcb6159454249aefa3" - http_archive( - name = "llvm-raw", - build_file_content = "# empty", - sha256 = LLVM_SHA256, - strip_prefix = "llvm-project-" + LLVM_COMMIT, - urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], - ) + if use_local_llvm_repo(): + native.new_local_repository( + name = "llvm-raw", + build_file_content = "# empty", + path = local_llvm_repo_path(), + ) + else: + LLVM_COMMIT = "28b27c1b10ae8d1f5b4fb9df691e8cf0da9be3f6" + LLVM_SHA256 = "1f7a7ca5983801d671901644659c32d028e5e7316418fabcb6159454249aefa3" + http_archive( + name = "llvm-raw", + build_file_content = "# empty", + sha256 = LLVM_SHA256, + strip_prefix = "llvm-project-" + LLVM_COMMIT, + urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], + ) - TORCH_MLIR_COMMIT = "52abae1526e51ae8c415ca98ce4a56b00782b68b" - TORCH_MLIR_SHA256 = "f9973f3519b4ba98475917eb700f447b65fee88e9dd60c61f174ce38335ccb3b" - http_archive( - name = "torch-mlir-raw", - sha256 = TORCH_MLIR_SHA256, - build_file_content = "# empty", - strip_prefix = "torch-mlir-" + TORCH_MLIR_COMMIT, - urls = ["https://github.com/llvm/torch-mlir/archive/{commit}.tar.gz".format(commit = TORCH_MLIR_COMMIT)], - ) + if use_local_torch_mlir_repo(): + native.new_local_repository( + name = "torch-mlir-raw", + build_file_content = "# empty", + path = local_torch_mlir_repo_path(), + ) + else: + TORCH_MLIR_COMMIT = "52abae1526e51ae8c415ca98ce4a56b00782b68b" + TORCH_MLIR_SHA256 = "f9973f3519b4ba98475917eb700f447b65fee88e9dd60c61f174ce38335ccb3b" + http_archive( + name = "torch-mlir-raw", + sha256 = TORCH_MLIR_SHA256, + build_file_content = "# empty", + strip_prefix = "torch-mlir-" + TORCH_MLIR_COMMIT, + urls = ["https://github.com/llvm/torch-mlir/archive/{commit}.tar.gz".format(commit = TORCH_MLIR_COMMIT)], + ) - STABLEHLO_COMMIT = "5a8bb985f50a679721292b14f97f270344ac64a3" - STABLEHLO_SHA256 = "abda3e8e029c1409b53b1eea080e5cfb4c4ef6705064d7cd954d8272d059567a" - http_archive( - name = "stablehlo", - sha256 = STABLEHLO_SHA256, - strip_prefix = "stablehlo-" + STABLEHLO_COMMIT, - urls = ["https://github.com/openxla/stablehlo/archive/{commit}.tar.gz".format(commit = STABLEHLO_COMMIT)], - # This patch allows testing stablehlo from mlir-tcp - patches = ["@//:stablehlo.patch"], - patch_args = ["-p1"], - ) + if use_local_stablehlo_repo(): + native.local_repository( + name = "stablehlo", + path = local_stablehlo_repo_path(), + ) + else: + STABLEHLO_COMMIT = "5a8bb985f50a679721292b14f97f270344ac64a3" + STABLEHLO_SHA256 = "abda3e8e029c1409b53b1eea080e5cfb4c4ef6705064d7cd954d8272d059567a" + http_archive( + name = "stablehlo", + sha256 = STABLEHLO_SHA256, + strip_prefix = "stablehlo-" + STABLEHLO_COMMIT, + urls = ["https://github.com/openxla/stablehlo/archive/{commit}.tar.gz".format(commit = STABLEHLO_COMMIT)], + # This patch allows testing stablehlo from mlir-tcp + patches = ["@//:stablehlo.patch"], + patch_args = ["-p1"], + ) SKYLIB_VERSION = "1.3.0" diff --git a/local_repos.bzl b/local_repos.bzl new file mode 100644 index 00000000..31b25847 --- /dev/null +++ b/local_repos.bzl @@ -0,0 +1,36 @@ +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# Also available under a BSD-style license. See LICENSE. + +# Modify this file to get bazel to use a local source checkout for the 3p deps +# (e.g. to quickly test out local changes). +# +# To avoid accidentally checking in modifications to this file, you can ask git +# to ignore changes to this file by running the following: +# +# $ git update-index --assume-unchanged local_repos.bzl + +def use_local_llvm_repo(): + # Change this to return True to have mlir-tcp use the source tree at + # `local_llvm_repo_path()` + return False + +def use_local_torch_mlir_repo(): + # Change this to return True to have mlir-tcp use the source tree at + # `local_torch_mlir_repo_path()` + return False + +def use_local_stablehlo_repo(): + # Change this to return True to have mlir-tcp use the source tree at + # `local_stablehlo_repo_path()` + return False + +def local_llvm_repo_path(): + return "./third_party/llvm-project" + +def local_torch_mlir_repo_path(): + return "./third_party/torch-mlir" + +def local_stablehlo_repo_path(): + return "./third_party/stablehlo"