From d5f0fb8740fb6ccaf823e7edcc5e625900abdf48 Mon Sep 17 00:00:00 2001 From: Anton Bondarenko Date: Thu, 31 Oct 2024 13:01:44 +0100 Subject: [PATCH] Use local third party components instead of downloading ones Now when we have major third party components in repository there is no need to download them anymore. Signed-off-by: Anton Bondarenko --- WORKSPACE | 11 +++++------ cmake/FetchGBench.cmake | 4 ++-- cmake/FetchGTest.cmake | 4 ++-- kai_defs.bzl | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 0932cdc4..2a15d1be 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -7,6 +7,7 @@ workspace(name = "com_arm_kleidiai") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("kai_defs.bzl", "kai_local_archive") http_archive( name = "bazel_skylib", @@ -15,16 +16,14 @@ http_archive( urls = ["https://github.com/bazelbuild/bazel-skylib/archive/288731ef9f7f688932bd50e704a91a45ec185f9b.zip"], ) -http_archive( +kai_local_archive( name = "com_google_googletest", - sha256 = "1f357c27ca988c3f7c6b4bf68a9395005ac6761f034046e9dde0896e3aba00e4", + archive = "//:third_party/googletest-v1.14.0.zip", strip_prefix = "googletest-1.14.0", - urls = ["https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip"], ) -http_archive( +kai_local_archive( name = "com_google_benchmark", - sha256 = "84c49c4c07074f36fbf8b4f182ed7d75191a6fa72756ab4a17848455499f4286", + archive = "//:third_party/benchmark-v1.8.4.zip", strip_prefix = "benchmark-v1.8.4", - urls = ["https://github.com/google/benchmark/archive/refs/tags/v1.8.4.zip"], ) diff --git a/cmake/FetchGBench.cmake b/cmake/FetchGBench.cmake index b32c76a7..d317d497 100644 --- a/cmake/FetchGBench.cmake +++ b/cmake/FetchGBench.cmake @@ -11,8 +11,8 @@ if(POLICY CMP0135) endif() fetchcontent_declare(googlebench - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG v1.8.4 + URL ${CMAKE_SOURCE_DIR}/third_party/benchmark-v1.8.4.zip + URL_HASH SHA256=84c49c4c07074f36fbf8b4f182ed7d75191a6fa72756ab4a17848455499f4286 ) fetchcontent_makeavailable(googlebench) diff --git a/cmake/FetchGTest.cmake b/cmake/FetchGTest.cmake index 0ca94412..88eb639d 100644 --- a/cmake/FetchGTest.cmake +++ b/cmake/FetchGTest.cmake @@ -11,8 +11,8 @@ if(POLICY CMP0135) endif() fetchcontent_declare(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 + URL ${CMAKE_SOURCE_DIR}/third_party/googletest-v1.14.0.zip + URL_HASH SHA256=1f357c27ca988c3f7c6b4bf68a9395005ac6761f034046e9dde0896e3aba00e4 ) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) diff --git a/kai_defs.bzl b/kai_defs.bzl index dfa1f743..afac85b7 100644 --- a/kai_defs.bzl +++ b/kai_defs.bzl @@ -6,6 +6,12 @@ """Build definitions for KleidiAI""" +load( + "@bazel_tools//tools/build_defs/repo:utils.bzl", + "update_attrs", + "workspace_and_buildfile", +) + # Extra warnings for GCC/CLANG C/C++ def kai_gcc_warn_copts(): return [ @@ -129,3 +135,29 @@ def kai_cxx_library(name, **kwargs): name = name, **kwargs ) + +def _kai_local_archive_impl(ctx): + """Implementation of the kai_local_archive rule.""" + ctx.extract( + ctx.attr.archive, + stripPrefix = ctx.attr.strip_prefix, + ) + workspace_and_buildfile(ctx) + + return update_attrs(ctx.attr, _kai_local_archive_attrs.keys(), {}) + +_kai_local_archive_attrs = { + "archive": attr.label(mandatory = True, allow_single_file = True, doc = "Path to local archive relative to workspace"), + "strip_prefix": attr.string(doc = "Strip prefix from archive internal content"), + "build_file": attr.label(allow_single_file = True, doc = "Name of BUILD file for extracted repository"), + "build_file_content": attr.string(doc = "Content of BUILD file for extracted repository"), + "workspace_file": attr.label(doc = "Name of WORKSPACE file for extracted repository"), + "workspace_file_content": attr.string(doc = "Content of WORKSPACE file for extracted repository"), +} + +kai_local_archive = repository_rule( + implementation = _kai_local_archive_impl, + attrs = _kai_local_archive_attrs, + local = True, + doc = "Rule to use repository from compressed local archive", +) -- GitLab