From ca7c54fe288208db356db99ab58815c7e552cf8e Mon Sep 17 00:00:00 2001 From: James Sharpe Date: Fri, 17 Dec 2021 09:28:45 +0000 Subject: [PATCH] Initial bzlmod support --- foreign_cc/extensions.bzl | 6 + foreign_cc/private/framework/toolchain.bzl | 5 +- foreign_cc/repositories.bzl | 13 +- toolchains/built_toolchains.bzl | 39 +- toolchains/prebuilt_toolchains.bzl | 540 +++++++++++---------- toolchains/prebuilt_toolchains.py | 23 +- 6 files changed, 341 insertions(+), 285 deletions(-) create mode 100644 foreign_cc/extensions.bzl diff --git a/foreign_cc/extensions.bzl b/foreign_cc/extensions.bzl new file mode 100644 index 000000000..46abf1cd0 --- /dev/null +++ b/foreign_cc/extensions.bzl @@ -0,0 +1,6 @@ +load("//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") + +def _init(module_ctx): + rules_foreign_cc_dependencies(register_toolchains = False, register_preinstalled_tools = False) + +ext = module_extension(implementation = _init) diff --git a/foreign_cc/private/framework/toolchain.bzl b/foreign_cc/private/framework/toolchain.bzl index 5ca7b4091..8de64cbe6 100644 --- a/foreign_cc/private/framework/toolchain.bzl +++ b/foreign_cc/private/framework/toolchain.bzl @@ -86,7 +86,7 @@ framework_toolchain_repository = repository_rule( ) # buildifier: disable=unnamed-macro -def register_framework_toolchains(): +def register_framework_toolchains(register_toolchains = True): """Define and register the foreign_cc framework toolchains""" toolchains = [] @@ -103,4 +103,5 @@ def register_framework_toolchains(): toolchains.append("@{}//:toolchain".format(toolchain_name)) - native.register_toolchains(*toolchains) + if (register_toolchains): + native.register_toolchains(*toolchains) diff --git a/foreign_cc/repositories.bzl b/foreign_cc/repositories.bzl index ea8a4a71a..bffd3d89e 100644 --- a/foreign_cc/repositories.bzl +++ b/foreign_cc/repositories.bzl @@ -13,7 +13,8 @@ def rules_foreign_cc_dependencies( make_version = "4.3", ninja_version = "1.10.2", register_preinstalled_tools = True, - register_built_tools = True): + register_built_tools = True, + register_toolchains = True): """Call this function from the WORKSPACE file to initialize rules_foreign_cc \ dependencies and let neccesary code generation happen \ (Code generation is needed to support different variants of the C++ Starlark API.). @@ -41,20 +42,24 @@ def rules_foreign_cc_dependencies( installed on the exec host register_built_tools: If true, toolchains that build the tools from source are registered + + register_toolchains: If true, registers the toolchains via native.register_toolchains. Used by bzlmod """ - register_framework_toolchains() + register_framework_toolchains(register_toolchains = register_toolchains) - native.register_toolchains(*native_tools_toolchains) + if (register_toolchains): + native.register_toolchains(*native_tools_toolchains) if register_default_tools: - prebuilt_toolchains(cmake_version, ninja_version) + prebuilt_toolchains(cmake_version, ninja_version, register_toolchains) if register_built_tools: built_toolchains( cmake_version = cmake_version, make_version = make_version, ninja_version = ninja_version, + register_toolchains = register_toolchains, ) if register_preinstalled_tools: diff --git a/toolchains/built_toolchains.bzl b/toolchains/built_toolchains.bzl index 7eb164f84..1f26c94ca 100644 --- a/toolchains/built_toolchains.bzl +++ b/toolchains/built_toolchains.bzl @@ -24,16 +24,17 @@ _CMAKE_SRCS = { } # buildifier: disable=unnamed-macro -def built_toolchains(cmake_version, make_version, ninja_version): +def built_toolchains(cmake_version, make_version, ninja_version, register_toolchains): """Register toolchains for built tools that will be built from source""" - _cmake_toolchain(cmake_version) - _make_toolchain(make_version) - _ninja_toolchain(ninja_version) - -def _cmake_toolchain(version): - native.register_toolchains( - "@rules_foreign_cc//toolchains:built_cmake_toolchain", - ) + _cmake_toolchain(cmake_version, register_toolchains) + _make_toolchain(make_version, register_toolchains) + _ninja_toolchain(ninja_version, register_toolchains) + +def _cmake_toolchain(version, register_toolchains): + if (register_toolchains): + native.register_toolchains( + "@rules_foreign_cc//toolchains:built_cmake_toolchain", + ) if _CMAKE_SRCS.get(version): cmake_meta = _CMAKE_SRCS[version] @@ -403,16 +404,17 @@ def _cmake_toolchain(version): fail("Unsupported cmake version: " + str(version)) -def _make_toolchain(version): - native.register_toolchains( - "@rules_foreign_cc//toolchains:built_make_toolchain", - ) +def _make_toolchain(version, register_toolchains): + if (register_toolchains): + native.register_toolchains( + "@rules_foreign_cc//toolchains:built_make_toolchain", + ) if version == "4.3": maybe( http_archive, name = "gnumake_src", build_file_content = _ALL_CONTENT, - patches = ["@rules_foreign_cc//toolchains:make-reproducible-bootstrap.patch"], + patches = [str(Label("//toolchains:make-reproducible-bootstrap.patch"))], sha256 = "e05fdde47c5f7ca45cb697e973894ff4f5d79e13b750ed57d7b66d8defc78e19", strip_prefix = "make-4.3", urls = [ @@ -424,10 +426,11 @@ def _make_toolchain(version): fail("Unsupported make version: " + str(version)) -def _ninja_toolchain(version): - native.register_toolchains( - "@rules_foreign_cc//toolchains:built_ninja_toolchain", - ) +def _ninja_toolchain(version, register_toolchains): + if (register_toolchains): + native.register_toolchains( + "@rules_foreign_cc//toolchains:built_ninja_toolchain", + ) if version == "1.10.2": maybe( http_archive, diff --git a/toolchains/prebuilt_toolchains.bzl b/toolchains/prebuilt_toolchains.bzl index efbbf7d96..e7b3b9cb7 100644 --- a/toolchains/prebuilt_toolchains.bzl +++ b/toolchains/prebuilt_toolchains.bzl @@ -53,18 +53,18 @@ native_tool_toolchain( """ # buildifier: disable=unnamed-macro -def prebuilt_toolchains(cmake_version, ninja_version): +def prebuilt_toolchains(cmake_version, ninja_version, register_toolchains): """Register toolchains for pre-built cmake and ninja binaries Args: cmake_version (string): The target cmake version ninja_version (string): The target ninja-build version """ - _cmake_toolchains(cmake_version) - _ninja_toolchains(ninja_version) - _make_toolchains() + _cmake_toolchains(cmake_version, register_toolchains) + _ninja_toolchains(ninja_version, register_toolchains) + _make_toolchains(register_toolchains) -def _cmake_toolchains(version): +def _cmake_toolchains(version, register_toolchains): if "3.22.0" == version: maybe( http_archive, @@ -159,13 +159,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.22.0_toolchains//:cmake-3.22.0-linux-aarch64_toolchain", - "@cmake_3.22.0_toolchains//:cmake-3.22.0-linux-x86_64_toolchain", - "@cmake_3.22.0_toolchains//:cmake-3.22.0-macos-universal_toolchain", - "@cmake_3.22.0_toolchains//:cmake-3.22.0-windows-i386_toolchain", - "@cmake_3.22.0_toolchains//:cmake-3.22.0-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.22.0_toolchains//:cmake-3.22.0-linux-aarch64_toolchain", + "@cmake_3.22.0_toolchains//:cmake-3.22.0-linux-x86_64_toolchain", + "@cmake_3.22.0_toolchains//:cmake-3.22.0-macos-universal_toolchain", + "@cmake_3.22.0_toolchains//:cmake-3.22.0-windows-i386_toolchain", + "@cmake_3.22.0_toolchains//:cmake-3.22.0-windows-x86_64_toolchain", + ) return @@ -263,13 +264,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.21.4_toolchains//:cmake-3.21.4-linux-aarch64_toolchain", - "@cmake_3.21.4_toolchains//:cmake-3.21.4-linux-x86_64_toolchain", - "@cmake_3.21.4_toolchains//:cmake-3.21.4-macos-universal_toolchain", - "@cmake_3.21.4_toolchains//:cmake-3.21.4-windows-i386_toolchain", - "@cmake_3.21.4_toolchains//:cmake-3.21.4-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.21.4_toolchains//:cmake-3.21.4-linux-aarch64_toolchain", + "@cmake_3.21.4_toolchains//:cmake-3.21.4-linux-x86_64_toolchain", + "@cmake_3.21.4_toolchains//:cmake-3.21.4-macos-universal_toolchain", + "@cmake_3.21.4_toolchains//:cmake-3.21.4-windows-i386_toolchain", + "@cmake_3.21.4_toolchains//:cmake-3.21.4-windows-x86_64_toolchain", + ) return @@ -367,13 +369,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.21.3_toolchains//:cmake-3.21.3-linux-aarch64_toolchain", - "@cmake_3.21.3_toolchains//:cmake-3.21.3-linux-x86_64_toolchain", - "@cmake_3.21.3_toolchains//:cmake-3.21.3-macos-universal_toolchain", - "@cmake_3.21.3_toolchains//:cmake-3.21.3-windows-i386_toolchain", - "@cmake_3.21.3_toolchains//:cmake-3.21.3-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.21.3_toolchains//:cmake-3.21.3-linux-aarch64_toolchain", + "@cmake_3.21.3_toolchains//:cmake-3.21.3-linux-x86_64_toolchain", + "@cmake_3.21.3_toolchains//:cmake-3.21.3-macos-universal_toolchain", + "@cmake_3.21.3_toolchains//:cmake-3.21.3-windows-i386_toolchain", + "@cmake_3.21.3_toolchains//:cmake-3.21.3-windows-x86_64_toolchain", + ) return @@ -471,13 +474,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.21.2_toolchains//:cmake-3.21.2-linux-aarch64_toolchain", - "@cmake_3.21.2_toolchains//:cmake-3.21.2-linux-x86_64_toolchain", - "@cmake_3.21.2_toolchains//:cmake-3.21.2-macos-universal_toolchain", - "@cmake_3.21.2_toolchains//:cmake-3.21.2-windows-i386_toolchain", - "@cmake_3.21.2_toolchains//:cmake-3.21.2-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.21.2_toolchains//:cmake-3.21.2-linux-aarch64_toolchain", + "@cmake_3.21.2_toolchains//:cmake-3.21.2-linux-x86_64_toolchain", + "@cmake_3.21.2_toolchains//:cmake-3.21.2-macos-universal_toolchain", + "@cmake_3.21.2_toolchains//:cmake-3.21.2-windows-i386_toolchain", + "@cmake_3.21.2_toolchains//:cmake-3.21.2-windows-x86_64_toolchain", + ) return @@ -575,13 +579,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.21.1_toolchains//:cmake-3.21.1-linux-aarch64_toolchain", - "@cmake_3.21.1_toolchains//:cmake-3.21.1-linux-x86_64_toolchain", - "@cmake_3.21.1_toolchains//:cmake-3.21.1-macos-universal_toolchain", - "@cmake_3.21.1_toolchains//:cmake-3.21.1-windows-i386_toolchain", - "@cmake_3.21.1_toolchains//:cmake-3.21.1-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.21.1_toolchains//:cmake-3.21.1-linux-aarch64_toolchain", + "@cmake_3.21.1_toolchains//:cmake-3.21.1-linux-x86_64_toolchain", + "@cmake_3.21.1_toolchains//:cmake-3.21.1-macos-universal_toolchain", + "@cmake_3.21.1_toolchains//:cmake-3.21.1-windows-i386_toolchain", + "@cmake_3.21.1_toolchains//:cmake-3.21.1-windows-x86_64_toolchain", + ) return @@ -679,13 +684,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.21.0_toolchains//:cmake-3.21.0-linux-aarch64_toolchain", - "@cmake_3.21.0_toolchains//:cmake-3.21.0-linux-x86_64_toolchain", - "@cmake_3.21.0_toolchains//:cmake-3.21.0-macos-universal_toolchain", - "@cmake_3.21.0_toolchains//:cmake-3.21.0-windows-i386_toolchain", - "@cmake_3.21.0_toolchains//:cmake-3.21.0-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.21.0_toolchains//:cmake-3.21.0-linux-aarch64_toolchain", + "@cmake_3.21.0_toolchains//:cmake-3.21.0-linux-x86_64_toolchain", + "@cmake_3.21.0_toolchains//:cmake-3.21.0-macos-universal_toolchain", + "@cmake_3.21.0_toolchains//:cmake-3.21.0-windows-i386_toolchain", + "@cmake_3.21.0_toolchains//:cmake-3.21.0-windows-x86_64_toolchain", + ) return @@ -783,13 +789,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.20.5_toolchains//:cmake-3.20.5-linux-aarch64_toolchain", - "@cmake_3.20.5_toolchains//:cmake-3.20.5-linux-x86_64_toolchain", - "@cmake_3.20.5_toolchains//:cmake-3.20.5-macos-universal_toolchain", - "@cmake_3.20.5_toolchains//:cmake-3.20.5-windows-i386_toolchain", - "@cmake_3.20.5_toolchains//:cmake-3.20.5-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.20.5_toolchains//:cmake-3.20.5-linux-aarch64_toolchain", + "@cmake_3.20.5_toolchains//:cmake-3.20.5-linux-x86_64_toolchain", + "@cmake_3.20.5_toolchains//:cmake-3.20.5-macos-universal_toolchain", + "@cmake_3.20.5_toolchains//:cmake-3.20.5-windows-i386_toolchain", + "@cmake_3.20.5_toolchains//:cmake-3.20.5-windows-x86_64_toolchain", + ) return @@ -887,13 +894,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.20.4_toolchains//:cmake-3.20.4-linux-aarch64_toolchain", - "@cmake_3.20.4_toolchains//:cmake-3.20.4-linux-x86_64_toolchain", - "@cmake_3.20.4_toolchains//:cmake-3.20.4-macos-universal_toolchain", - "@cmake_3.20.4_toolchains//:cmake-3.20.4-windows-i386_toolchain", - "@cmake_3.20.4_toolchains//:cmake-3.20.4-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.20.4_toolchains//:cmake-3.20.4-linux-aarch64_toolchain", + "@cmake_3.20.4_toolchains//:cmake-3.20.4-linux-x86_64_toolchain", + "@cmake_3.20.4_toolchains//:cmake-3.20.4-macos-universal_toolchain", + "@cmake_3.20.4_toolchains//:cmake-3.20.4-windows-i386_toolchain", + "@cmake_3.20.4_toolchains//:cmake-3.20.4-windows-x86_64_toolchain", + ) return @@ -991,13 +999,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.20.3_toolchains//:cmake-3.20.3-linux-aarch64_toolchain", - "@cmake_3.20.3_toolchains//:cmake-3.20.3-linux-x86_64_toolchain", - "@cmake_3.20.3_toolchains//:cmake-3.20.3-macos-universal_toolchain", - "@cmake_3.20.3_toolchains//:cmake-3.20.3-windows-i386_toolchain", - "@cmake_3.20.3_toolchains//:cmake-3.20.3-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.20.3_toolchains//:cmake-3.20.3-linux-aarch64_toolchain", + "@cmake_3.20.3_toolchains//:cmake-3.20.3-linux-x86_64_toolchain", + "@cmake_3.20.3_toolchains//:cmake-3.20.3-macos-universal_toolchain", + "@cmake_3.20.3_toolchains//:cmake-3.20.3-windows-i386_toolchain", + "@cmake_3.20.3_toolchains//:cmake-3.20.3-windows-x86_64_toolchain", + ) return @@ -1095,13 +1104,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.20.2_toolchains//:cmake-3.20.2-linux-aarch64_toolchain", - "@cmake_3.20.2_toolchains//:cmake-3.20.2-linux-x86_64_toolchain", - "@cmake_3.20.2_toolchains//:cmake-3.20.2-macos-universal_toolchain", - "@cmake_3.20.2_toolchains//:cmake-3.20.2-windows-i386_toolchain", - "@cmake_3.20.2_toolchains//:cmake-3.20.2-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.20.2_toolchains//:cmake-3.20.2-linux-aarch64_toolchain", + "@cmake_3.20.2_toolchains//:cmake-3.20.2-linux-x86_64_toolchain", + "@cmake_3.20.2_toolchains//:cmake-3.20.2-macos-universal_toolchain", + "@cmake_3.20.2_toolchains//:cmake-3.20.2-windows-i386_toolchain", + "@cmake_3.20.2_toolchains//:cmake-3.20.2-windows-x86_64_toolchain", + ) return @@ -1199,13 +1209,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.20.1_toolchains//:cmake-3.20.1-linux-aarch64_toolchain", - "@cmake_3.20.1_toolchains//:cmake-3.20.1-linux-x86_64_toolchain", - "@cmake_3.20.1_toolchains//:cmake-3.20.1-macos-universal_toolchain", - "@cmake_3.20.1_toolchains//:cmake-3.20.1-windows-i386_toolchain", - "@cmake_3.20.1_toolchains//:cmake-3.20.1-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.20.1_toolchains//:cmake-3.20.1-linux-aarch64_toolchain", + "@cmake_3.20.1_toolchains//:cmake-3.20.1-linux-x86_64_toolchain", + "@cmake_3.20.1_toolchains//:cmake-3.20.1-macos-universal_toolchain", + "@cmake_3.20.1_toolchains//:cmake-3.20.1-windows-i386_toolchain", + "@cmake_3.20.1_toolchains//:cmake-3.20.1-windows-x86_64_toolchain", + ) return @@ -1303,13 +1314,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.20.0_toolchains//:cmake-3.20.0-linux-aarch64_toolchain", - "@cmake_3.20.0_toolchains//:cmake-3.20.0-linux-x86_64_toolchain", - "@cmake_3.20.0_toolchains//:cmake-3.20.0-macos-universal_toolchain", - "@cmake_3.20.0_toolchains//:cmake-3.20.0-windows-i386_toolchain", - "@cmake_3.20.0_toolchains//:cmake-3.20.0-windows-x86_64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.20.0_toolchains//:cmake-3.20.0-linux-aarch64_toolchain", + "@cmake_3.20.0_toolchains//:cmake-3.20.0-linux-x86_64_toolchain", + "@cmake_3.20.0_toolchains//:cmake-3.20.0-macos-universal_toolchain", + "@cmake_3.20.0_toolchains//:cmake-3.20.0-windows-i386_toolchain", + "@cmake_3.20.0_toolchains//:cmake-3.20.0-windows-x86_64_toolchain", + ) return @@ -1407,13 +1419,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.19.8_toolchains//:cmake-3.19.8-Linux-aarch64_toolchain", - "@cmake_3.19.8_toolchains//:cmake-3.19.8-Linux-x86_64_toolchain", - "@cmake_3.19.8_toolchains//:cmake-3.19.8-macos-universal_toolchain", - "@cmake_3.19.8_toolchains//:cmake-3.19.8-win32-x86_toolchain", - "@cmake_3.19.8_toolchains//:cmake-3.19.8-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.19.8_toolchains//:cmake-3.19.8-Linux-aarch64_toolchain", + "@cmake_3.19.8_toolchains//:cmake-3.19.8-Linux-x86_64_toolchain", + "@cmake_3.19.8_toolchains//:cmake-3.19.8-macos-universal_toolchain", + "@cmake_3.19.8_toolchains//:cmake-3.19.8-win32-x86_toolchain", + "@cmake_3.19.8_toolchains//:cmake-3.19.8-win64-x64_toolchain", + ) return @@ -1511,13 +1524,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.19.7_toolchains//:cmake-3.19.7-Linux-aarch64_toolchain", - "@cmake_3.19.7_toolchains//:cmake-3.19.7-Linux-x86_64_toolchain", - "@cmake_3.19.7_toolchains//:cmake-3.19.7-macos-universal_toolchain", - "@cmake_3.19.7_toolchains//:cmake-3.19.7-win32-x86_toolchain", - "@cmake_3.19.7_toolchains//:cmake-3.19.7-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.19.7_toolchains//:cmake-3.19.7-Linux-aarch64_toolchain", + "@cmake_3.19.7_toolchains//:cmake-3.19.7-Linux-x86_64_toolchain", + "@cmake_3.19.7_toolchains//:cmake-3.19.7-macos-universal_toolchain", + "@cmake_3.19.7_toolchains//:cmake-3.19.7-win32-x86_toolchain", + "@cmake_3.19.7_toolchains//:cmake-3.19.7-win64-x64_toolchain", + ) return @@ -1615,13 +1629,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.19.6_toolchains//:cmake-3.19.6-Linux-aarch64_toolchain", - "@cmake_3.19.6_toolchains//:cmake-3.19.6-Linux-x86_64_toolchain", - "@cmake_3.19.6_toolchains//:cmake-3.19.6-macos-universal_toolchain", - "@cmake_3.19.6_toolchains//:cmake-3.19.6-win32-x86_toolchain", - "@cmake_3.19.6_toolchains//:cmake-3.19.6-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.19.6_toolchains//:cmake-3.19.6-Linux-aarch64_toolchain", + "@cmake_3.19.6_toolchains//:cmake-3.19.6-Linux-x86_64_toolchain", + "@cmake_3.19.6_toolchains//:cmake-3.19.6-macos-universal_toolchain", + "@cmake_3.19.6_toolchains//:cmake-3.19.6-win32-x86_toolchain", + "@cmake_3.19.6_toolchains//:cmake-3.19.6-win64-x64_toolchain", + ) return @@ -1719,13 +1734,14 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.19.5_toolchains//:cmake-3.19.5-Linux-aarch64_toolchain", - "@cmake_3.19.5_toolchains//:cmake-3.19.5-Linux-x86_64_toolchain", - "@cmake_3.19.5_toolchains//:cmake-3.19.5-macos-universal_toolchain", - "@cmake_3.19.5_toolchains//:cmake-3.19.5-win32-x86_toolchain", - "@cmake_3.19.5_toolchains//:cmake-3.19.5-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.19.5_toolchains//:cmake-3.19.5-Linux-aarch64_toolchain", + "@cmake_3.19.5_toolchains//:cmake-3.19.5-Linux-x86_64_toolchain", + "@cmake_3.19.5_toolchains//:cmake-3.19.5-macos-universal_toolchain", + "@cmake_3.19.5_toolchains//:cmake-3.19.5-win32-x86_toolchain", + "@cmake_3.19.5_toolchains//:cmake-3.19.5-win64-x64_toolchain", + ) return @@ -1807,12 +1823,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.18.6_toolchains//:cmake-3.18.6-Darwin-x86_64_toolchain", - "@cmake_3.18.6_toolchains//:cmake-3.18.6-Linux-x86_64_toolchain", - "@cmake_3.18.6_toolchains//:cmake-3.18.6-win32-x86_toolchain", - "@cmake_3.18.6_toolchains//:cmake-3.18.6-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.18.6_toolchains//:cmake-3.18.6-Darwin-x86_64_toolchain", + "@cmake_3.18.6_toolchains//:cmake-3.18.6-Linux-x86_64_toolchain", + "@cmake_3.18.6_toolchains//:cmake-3.18.6-win32-x86_toolchain", + "@cmake_3.18.6_toolchains//:cmake-3.18.6-win64-x64_toolchain", + ) return @@ -1894,12 +1911,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.17.5_toolchains//:cmake-3.17.5-Darwin-x86_64_toolchain", - "@cmake_3.17.5_toolchains//:cmake-3.17.5-Linux-x86_64_toolchain", - "@cmake_3.17.5_toolchains//:cmake-3.17.5-win32-x86_toolchain", - "@cmake_3.17.5_toolchains//:cmake-3.17.5-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.17.5_toolchains//:cmake-3.17.5-Darwin-x86_64_toolchain", + "@cmake_3.17.5_toolchains//:cmake-3.17.5-Linux-x86_64_toolchain", + "@cmake_3.17.5_toolchains//:cmake-3.17.5-win32-x86_toolchain", + "@cmake_3.17.5_toolchains//:cmake-3.17.5-win64-x64_toolchain", + ) return @@ -1981,12 +1999,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.16.9_toolchains//:cmake-3.16.9-Darwin-x86_64_toolchain", - "@cmake_3.16.9_toolchains//:cmake-3.16.9-Linux-x86_64_toolchain", - "@cmake_3.16.9_toolchains//:cmake-3.16.9-win32-x86_toolchain", - "@cmake_3.16.9_toolchains//:cmake-3.16.9-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.16.9_toolchains//:cmake-3.16.9-Darwin-x86_64_toolchain", + "@cmake_3.16.9_toolchains//:cmake-3.16.9-Linux-x86_64_toolchain", + "@cmake_3.16.9_toolchains//:cmake-3.16.9-win32-x86_toolchain", + "@cmake_3.16.9_toolchains//:cmake-3.16.9-win64-x64_toolchain", + ) return @@ -2068,12 +2087,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.15.7_toolchains//:cmake-3.15.7-Darwin-x86_64_toolchain", - "@cmake_3.15.7_toolchains//:cmake-3.15.7-Linux-x86_64_toolchain", - "@cmake_3.15.7_toolchains//:cmake-3.15.7-win32-x86_toolchain", - "@cmake_3.15.7_toolchains//:cmake-3.15.7-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.15.7_toolchains//:cmake-3.15.7-Darwin-x86_64_toolchain", + "@cmake_3.15.7_toolchains//:cmake-3.15.7-Linux-x86_64_toolchain", + "@cmake_3.15.7_toolchains//:cmake-3.15.7-win32-x86_toolchain", + "@cmake_3.15.7_toolchains//:cmake-3.15.7-win64-x64_toolchain", + ) return @@ -2155,12 +2175,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.14.7_toolchains//:cmake-3.14.7-Darwin-x86_64_toolchain", - "@cmake_3.14.7_toolchains//:cmake-3.14.7-Linux-x86_64_toolchain", - "@cmake_3.14.7_toolchains//:cmake-3.14.7-win32-x86_toolchain", - "@cmake_3.14.7_toolchains//:cmake-3.14.7-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.14.7_toolchains//:cmake-3.14.7-Darwin-x86_64_toolchain", + "@cmake_3.14.7_toolchains//:cmake-3.14.7-Linux-x86_64_toolchain", + "@cmake_3.14.7_toolchains//:cmake-3.14.7-win32-x86_toolchain", + "@cmake_3.14.7_toolchains//:cmake-3.14.7-win64-x64_toolchain", + ) return @@ -2242,12 +2263,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.13.5_toolchains//:cmake-3.13.5-Darwin-x86_64_toolchain", - "@cmake_3.13.5_toolchains//:cmake-3.13.5-Linux-x86_64_toolchain", - "@cmake_3.13.5_toolchains//:cmake-3.13.5-win32-x86_toolchain", - "@cmake_3.13.5_toolchains//:cmake-3.13.5-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.13.5_toolchains//:cmake-3.13.5-Darwin-x86_64_toolchain", + "@cmake_3.13.5_toolchains//:cmake-3.13.5-Linux-x86_64_toolchain", + "@cmake_3.13.5_toolchains//:cmake-3.13.5-win32-x86_toolchain", + "@cmake_3.13.5_toolchains//:cmake-3.13.5-win64-x64_toolchain", + ) return @@ -2329,12 +2351,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.12.4_toolchains//:cmake-3.12.4-Darwin-x86_64_toolchain", - "@cmake_3.12.4_toolchains//:cmake-3.12.4-Linux-x86_64_toolchain", - "@cmake_3.12.4_toolchains//:cmake-3.12.4-win32-x86_toolchain", - "@cmake_3.12.4_toolchains//:cmake-3.12.4-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.12.4_toolchains//:cmake-3.12.4-Darwin-x86_64_toolchain", + "@cmake_3.12.4_toolchains//:cmake-3.12.4-Linux-x86_64_toolchain", + "@cmake_3.12.4_toolchains//:cmake-3.12.4-win32-x86_toolchain", + "@cmake_3.12.4_toolchains//:cmake-3.12.4-win64-x64_toolchain", + ) return @@ -2416,12 +2439,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.11.4_toolchains//:cmake-3.11.4-Darwin-x86_64_toolchain", - "@cmake_3.11.4_toolchains//:cmake-3.11.4-Linux-x86_64_toolchain", - "@cmake_3.11.4_toolchains//:cmake-3.11.4-win32-x86_toolchain", - "@cmake_3.11.4_toolchains//:cmake-3.11.4-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.11.4_toolchains//:cmake-3.11.4-Darwin-x86_64_toolchain", + "@cmake_3.11.4_toolchains//:cmake-3.11.4-Linux-x86_64_toolchain", + "@cmake_3.11.4_toolchains//:cmake-3.11.4-win32-x86_toolchain", + "@cmake_3.11.4_toolchains//:cmake-3.11.4-win64-x64_toolchain", + ) return @@ -2503,12 +2527,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.10.3_toolchains//:cmake-3.10.3-Darwin-x86_64_toolchain", - "@cmake_3.10.3_toolchains//:cmake-3.10.3-Linux-x86_64_toolchain", - "@cmake_3.10.3_toolchains//:cmake-3.10.3-win32-x86_toolchain", - "@cmake_3.10.3_toolchains//:cmake-3.10.3-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.10.3_toolchains//:cmake-3.10.3-Darwin-x86_64_toolchain", + "@cmake_3.10.3_toolchains//:cmake-3.10.3-Linux-x86_64_toolchain", + "@cmake_3.10.3_toolchains//:cmake-3.10.3-win32-x86_toolchain", + "@cmake_3.10.3_toolchains//:cmake-3.10.3-win64-x64_toolchain", + ) return @@ -2590,12 +2615,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.9.6_toolchains//:cmake-3.9.6-Darwin-x86_64_toolchain", - "@cmake_3.9.6_toolchains//:cmake-3.9.6-Linux-x86_64_toolchain", - "@cmake_3.9.6_toolchains//:cmake-3.9.6-win32-x86_toolchain", - "@cmake_3.9.6_toolchains//:cmake-3.9.6-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.9.6_toolchains//:cmake-3.9.6-Darwin-x86_64_toolchain", + "@cmake_3.9.6_toolchains//:cmake-3.9.6-Linux-x86_64_toolchain", + "@cmake_3.9.6_toolchains//:cmake-3.9.6-win32-x86_toolchain", + "@cmake_3.9.6_toolchains//:cmake-3.9.6-win64-x64_toolchain", + ) return @@ -2677,12 +2703,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.8.2_toolchains//:cmake-3.8.2-Darwin-x86_64_toolchain", - "@cmake_3.8.2_toolchains//:cmake-3.8.2-Linux-x86_64_toolchain", - "@cmake_3.8.2_toolchains//:cmake-3.8.2-win32-x86_toolchain", - "@cmake_3.8.2_toolchains//:cmake-3.8.2-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.8.2_toolchains//:cmake-3.8.2-Darwin-x86_64_toolchain", + "@cmake_3.8.2_toolchains//:cmake-3.8.2-Linux-x86_64_toolchain", + "@cmake_3.8.2_toolchains//:cmake-3.8.2-win32-x86_toolchain", + "@cmake_3.8.2_toolchains//:cmake-3.8.2-win64-x64_toolchain", + ) return @@ -2764,12 +2791,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.7.2_toolchains//:cmake-3.7.2-Darwin-x86_64_toolchain", - "@cmake_3.7.2_toolchains//:cmake-3.7.2-Linux-x86_64_toolchain", - "@cmake_3.7.2_toolchains//:cmake-3.7.2-win32-x86_toolchain", - "@cmake_3.7.2_toolchains//:cmake-3.7.2-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.7.2_toolchains//:cmake-3.7.2-Darwin-x86_64_toolchain", + "@cmake_3.7.2_toolchains//:cmake-3.7.2-Linux-x86_64_toolchain", + "@cmake_3.7.2_toolchains//:cmake-3.7.2-win32-x86_toolchain", + "@cmake_3.7.2_toolchains//:cmake-3.7.2-win64-x64_toolchain", + ) return @@ -2851,12 +2879,13 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.6.3_toolchains//:cmake-3.6.3-Darwin-x86_64_toolchain", - "@cmake_3.6.3_toolchains//:cmake-3.6.3-Linux-x86_64_toolchain", - "@cmake_3.6.3_toolchains//:cmake-3.6.3-win32-x86_toolchain", - "@cmake_3.6.3_toolchains//:cmake-3.6.3-win64-x64_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.6.3_toolchains//:cmake-3.6.3-Darwin-x86_64_toolchain", + "@cmake_3.6.3_toolchains//:cmake-3.6.3-Linux-x86_64_toolchain", + "@cmake_3.6.3_toolchains//:cmake-3.6.3-win32-x86_toolchain", + "@cmake_3.6.3_toolchains//:cmake-3.6.3-win64-x64_toolchain", + ) return @@ -2921,11 +2950,12 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.5.2_toolchains//:cmake-3.5.2-Darwin-x86_64_toolchain", - "@cmake_3.5.2_toolchains//:cmake-3.5.2-Linux-x86_64_toolchain", - "@cmake_3.5.2_toolchains//:cmake-3.5.2-win32-x86_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.5.2_toolchains//:cmake-3.5.2-Darwin-x86_64_toolchain", + "@cmake_3.5.2_toolchains//:cmake-3.5.2-Linux-x86_64_toolchain", + "@cmake_3.5.2_toolchains//:cmake-3.5.2-win32-x86_toolchain", + ) return @@ -2990,11 +3020,12 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.4.3_toolchains//:cmake-3.4.3-Darwin-x86_64_toolchain", - "@cmake_3.4.3_toolchains//:cmake-3.4.3-Linux-x86_64_toolchain", - "@cmake_3.4.3_toolchains//:cmake-3.4.3-win32-x86_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.4.3_toolchains//:cmake-3.4.3-Darwin-x86_64_toolchain", + "@cmake_3.4.3_toolchains//:cmake-3.4.3-Linux-x86_64_toolchain", + "@cmake_3.4.3_toolchains//:cmake-3.4.3-win32-x86_toolchain", + ) return @@ -3059,11 +3090,12 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.3.2_toolchains//:cmake-3.3.2-Darwin-x86_64_toolchain", - "@cmake_3.3.2_toolchains//:cmake-3.3.2-Linux-x86_64_toolchain", - "@cmake_3.3.2_toolchains//:cmake-3.3.2-win32-x86_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.3.2_toolchains//:cmake-3.3.2-Darwin-x86_64_toolchain", + "@cmake_3.3.2_toolchains//:cmake-3.3.2-Linux-x86_64_toolchain", + "@cmake_3.3.2_toolchains//:cmake-3.3.2-win32-x86_toolchain", + ) return @@ -3128,11 +3160,12 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.2.3_toolchains//:cmake-3.2.3-Darwin-x86_64_toolchain", - "@cmake_3.2.3_toolchains//:cmake-3.2.3-Linux-x86_64_toolchain", - "@cmake_3.2.3_toolchains//:cmake-3.2.3-win32-x86_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.2.3_toolchains//:cmake-3.2.3-Darwin-x86_64_toolchain", + "@cmake_3.2.3_toolchains//:cmake-3.2.3-Linux-x86_64_toolchain", + "@cmake_3.2.3_toolchains//:cmake-3.2.3-win32-x86_toolchain", + ) return @@ -3197,11 +3230,12 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.1.3_toolchains//:cmake-3.1.3-Darwin-x86_64_toolchain", - "@cmake_3.1.3_toolchains//:cmake-3.1.3-Linux-x86_64_toolchain", - "@cmake_3.1.3_toolchains//:cmake-3.1.3-win32-x86_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.1.3_toolchains//:cmake-3.1.3-Darwin-x86_64_toolchain", + "@cmake_3.1.3_toolchains//:cmake-3.1.3-Linux-x86_64_toolchain", + "@cmake_3.1.3_toolchains//:cmake-3.1.3-win32-x86_toolchain", + ) return @@ -3232,15 +3266,16 @@ def _cmake_toolchains(version): tool = "cmake", ) - native.register_toolchains( - "@cmake_3.0.2_toolchains//:cmake-3.0.2-win32-x86_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@cmake_3.0.2_toolchains//:cmake-3.0.2-win32-x86_toolchain", + ) return fail("Unsupported version: " + str(version)) -def _ninja_toolchains(version): +def _ninja_toolchains(version, register_toolchains): if "1.10.2" == version: maybe( http_archive, @@ -3302,11 +3337,12 @@ def _ninja_toolchains(version): tool = "ninja", ) - native.register_toolchains( - "@ninja_1.10.2_toolchains//:ninja_1.10.2_linux_toolchain", - "@ninja_1.10.2_toolchains//:ninja_1.10.2_mac_toolchain", - "@ninja_1.10.2_toolchains//:ninja_1.10.2_win_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@ninja_1.10.2_toolchains//:ninja_1.10.2_linux_toolchain", + "@ninja_1.10.2_toolchains//:ninja_1.10.2_mac_toolchain", + "@ninja_1.10.2_toolchains//:ninja_1.10.2_win_toolchain", + ) return @@ -3371,11 +3407,12 @@ def _ninja_toolchains(version): tool = "ninja", ) - native.register_toolchains( - "@ninja_1.10.1_toolchains//:ninja_1.10.1_linux_toolchain", - "@ninja_1.10.1_toolchains//:ninja_1.10.1_mac_toolchain", - "@ninja_1.10.1_toolchains//:ninja_1.10.1_win_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@ninja_1.10.1_toolchains//:ninja_1.10.1_linux_toolchain", + "@ninja_1.10.1_toolchains//:ninja_1.10.1_mac_toolchain", + "@ninja_1.10.1_toolchains//:ninja_1.10.1_win_toolchain", + ) return @@ -3440,11 +3477,12 @@ def _ninja_toolchains(version): tool = "ninja", ) - native.register_toolchains( - "@ninja_1.10.0_toolchains//:ninja_1.10.0_linux_toolchain", - "@ninja_1.10.0_toolchains//:ninja_1.10.0_mac_toolchain", - "@ninja_1.10.0_toolchains//:ninja_1.10.0_win_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@ninja_1.10.0_toolchains//:ninja_1.10.0_linux_toolchain", + "@ninja_1.10.0_toolchains//:ninja_1.10.0_mac_toolchain", + "@ninja_1.10.0_toolchains//:ninja_1.10.0_win_toolchain", + ) return @@ -3509,11 +3547,12 @@ def _ninja_toolchains(version): tool = "ninja", ) - native.register_toolchains( - "@ninja_1.9.0_toolchains//:ninja_1.9.0_linux_toolchain", - "@ninja_1.9.0_toolchains//:ninja_1.9.0_mac_toolchain", - "@ninja_1.9.0_toolchains//:ninja_1.9.0_win_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@ninja_1.9.0_toolchains//:ninja_1.9.0_linux_toolchain", + "@ninja_1.9.0_toolchains//:ninja_1.9.0_mac_toolchain", + "@ninja_1.9.0_toolchains//:ninja_1.9.0_win_toolchain", + ) return @@ -3578,16 +3617,17 @@ def _ninja_toolchains(version): tool = "ninja", ) - native.register_toolchains( - "@ninja_1.8.2_toolchains//:ninja_1.8.2_linux_toolchain", - "@ninja_1.8.2_toolchains//:ninja_1.8.2_mac_toolchain", - "@ninja_1.8.2_toolchains//:ninja_1.8.2_win_toolchain", - ) + if (register_toolchains): + native.register_toolchains( + "@ninja_1.8.2_toolchains//:ninja_1.8.2_linux_toolchain", + "@ninja_1.8.2_toolchains//:ninja_1.8.2_mac_toolchain", + "@ninja_1.8.2_toolchains//:ninja_1.8.2_win_toolchain", + ) return fail("Unsupported version: " + str(version)) -def _make_toolchains(): +def _make_toolchains(register_toolchains): # There are currently no prebuilt make binaries pass diff --git a/toolchains/prebuilt_toolchains.py b/toolchains/prebuilt_toolchains.py index 34c142c8d..60d00efc9 100755 --- a/toolchains/prebuilt_toolchains.py +++ b/toolchains/prebuilt_toolchains.py @@ -141,9 +141,10 @@ """ REGISTER_TOOLCHAINS = """\ -native.register_toolchains( +if (register_toolchains): + native.register_toolchains( {toolchains} -) + ) """ BZL_FILE_TEMPLATE = """\ @@ -202,24 +203,24 @@ \"\"\" # buildifier: disable=unnamed-macro -def prebuilt_toolchains(cmake_version, ninja_version): +def prebuilt_toolchains(cmake_version, ninja_version, register_toolchains): \"\"\"Register toolchains for pre-built cmake and ninja binaries Args: cmake_version (string): The target cmake version ninja_version (string): The target ninja-build version \"\"\" - _cmake_toolchains(cmake_version) - _ninja_toolchains(ninja_version) - _make_toolchains() + _cmake_toolchains(cmake_version, register_toolchains) + _ninja_toolchains(ninja_version, register_toolchains) + _make_toolchains(register_toolchains) -def _cmake_toolchains(version): +def _cmake_toolchains(version, register_toolchains): {cmake_definitions} -def _ninja_toolchains(version): +def _ninja_toolchains(version, register_toolchains): {ninja_definitions} -def _make_toolchains(): +def _make_toolchains(register_toolchains): {make_definitions} """ @@ -303,7 +304,7 @@ def get_cmake_definitions() -> str: [indent("\"@cmake_{}_toolchains//:{}_toolchain\",".format( version, repo - ), " " * 4) for repo in toolchains_repos]) + ), " " * 8) for repo in toolchains_repos]) ), " " * 8)) archives.extend([ @@ -388,7 +389,7 @@ def get_ninja_definitions() -> str: [indent("\"@ninja_{}_toolchains//:{}_toolchain\",".format( version, repo - ), " " * 4) for repo in toolchains_repos]) + ), " " * 8) for repo in toolchains_repos]) ), " " * 8)) archives.extend([