diff --git a/MODULE.bazel b/MODULE.bazel index cbe635e0c..da990d8ac 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -20,17 +20,11 @@ use_repo( "ninja_1.11.1_toolchains", "ninja_build_src", "pkgconfig_src", - "rules_foreign_cc_framework_toolchain_freebsd", - "rules_foreign_cc_framework_toolchain_linux", - "rules_foreign_cc_framework_toolchain_macos", - "rules_foreign_cc_framework_toolchain_windows", + "rules_foreign_cc_framework_toolchains", ) register_toolchains( - "@rules_foreign_cc_framework_toolchain_freebsd//:toolchain", - "@rules_foreign_cc_framework_toolchain_linux//:toolchain", - "@rules_foreign_cc_framework_toolchain_macos//:toolchain", - "@rules_foreign_cc_framework_toolchain_windows//:toolchain", + "@rules_foreign_cc_framework_toolchains//:all", "@rules_foreign_cc//toolchains:built_make_toolchain", "@rules_foreign_cc//toolchains:built_meson_toolchain", "@rules_foreign_cc//toolchains:built_pkgconfig_toolchain", diff --git a/README.md b/README.md index ecfae32aa..3ca220d94 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ The following flags are required in Bazel 4.x but not Bazel 5.x or newer: Note that the rules may be compatible with older versions of Bazel but support may break in future changes as these older versions are not tested. +Note also that the `runnable_binary` macro requires bazel 5.4.0, for the `rlocationpath` [path +variable](https://bazel.build/reference/be/make-variables) + ## News For more generalized updates, please see [NEWS.md](./NEWS.md) or checkout the diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index 51d4f1c9c..2b6a3ca22 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -14,7 +14,7 @@ use_repo( bazel_dep(name = "platforms", version = "0.0.6") bazel_dep(name = "rules_swift", version = "1.6.0", repo_name = "build_bazel_rules_swift") -bazel_dep(name = "rules_apple", version = "2.1.0", repo_name = "build_bazel_rules_apple") +bazel_dep(name = "rules_apple", version = "3.0.0-rc1", repo_name = "build_bazel_rules_apple") bazel_dep(name = "apple_support", version = "1.4.1", repo_name = "build_bazel_apple_support") bazel_dep(name = "rules_python", version = "0.22.0") diff --git a/examples/WORKSPACE.bazel b/examples/WORKSPACE.bazel index c090d09a5..df3b36ac3 100644 --- a/examples/WORKSPACE.bazel +++ b/examples/WORKSPACE.bazel @@ -85,6 +85,14 @@ rbe_preconfig( toolchain = "ubuntu1804-bazel-java11", ) +# TODO: Remove once bazel 4.x is no longer supported +http_archive( + name = "rules_proto", + sha256 = "20b240eba17a36be4b0b22635aca63053913d5c1ee36e16be36499d167a2f533", + strip_prefix = "rules_proto-11bf7c25e666dd7ddacbcd4d4c4a9de7a25175f8", + urls = ["https://github.com/bazelbuild/rules_proto/archive/11bf7c25e666dd7ddacbcd4d4c4a9de7a25175f8.tar.gz"], +) + http_archive( name = "build_bazel_apple_support", patches = ["//deps:apple_support.patch"], @@ -94,8 +102,8 @@ http_archive( http_archive( name = "build_bazel_rules_apple", - sha256 = "12865e5944f09d16364aa78050366aca9dc35a32a018fa35f5950238b08bf744", - url = "https://github.com/bazelbuild/rules_apple/releases/download/0.34.2/rules_apple.0.34.2.tar.gz", + sha256 = "62b24b9c3c1eb5bdb6fe1a3f4bf541d6e61eac8997e87c25a50c821f85bf8ff2", + url = "https://github.com/bazelbuild/rules_apple/releases/download/3.0.0-rc1/rules_apple.3.0.0-rc1.tar.gz", ) load( diff --git a/examples/platform_mappings b/examples/platform_mappings new file mode 100644 index 000000000..d31b6f119 --- /dev/null +++ b/examples/platform_mappings @@ -0,0 +1,120 @@ +platforms: + @build_bazel_apple_support//platforms:macos_x86_64 + --cpu=darwin_x86_64 + + @build_bazel_apple_support//platforms:macos_arm64 + --cpu=darwin_arm64 + + @build_bazel_apple_support//platforms:darwin_arm64e + --cpu=darwin_arm64e + + @build_bazel_apple_support//platforms:ios_i386 + --cpu=ios_i386 + + @build_bazel_apple_support//platforms:ios_x86_64 + --cpu=ios_x86_64 + + @build_bazel_apple_support//platforms:ios_sim_arm64 + --cpu=ios_sim_arm64 + + @build_bazel_apple_support//platforms:ios_armv7 + --cpu=ios_armv7 + + @build_bazel_apple_support//platforms:ios_arm64 + --cpu=ios_arm64 + + @build_bazel_apple_support//platforms:ios_arm64e + --cpu=ios_arm64e + + @build_bazel_apple_support//platforms:tvos_x86_64 + --cpu=tvos_x86_64 + + @build_bazel_apple_support//platforms:tvos_sim_arm64 + --cpu=tvos_sim_arm64 + + @build_bazel_apple_support//platforms:tvos_arm64 + --cpu=tvos_arm64 + + @build_bazel_apple_support//platforms:watchos_i386 + --cpu=watchos_i386 + + @build_bazel_apple_support//platforms:watchos_x86_64 + --cpu=watchos_x86_64 + + @build_bazel_apple_support//platforms:watchos_arm64 + --cpu=watchos_arm64 + + @build_bazel_apple_support//platforms:watchos_armv7k + --cpu=watchos_armv7k + + @build_bazel_apple_support//platforms:watchos_arm64_32 + --cpu=watchos_arm64_32 + +flags: + --cpu=darwin_x86_64 + --apple_platform_type=macos + @build_bazel_apple_support//platforms:macos_x86_64 + + --cpu=darwin_arm64 + --apple_platform_type=macos + @build_bazel_apple_support//platforms:macos_arm64 + + --cpu=darwin_arm64e + --apple_platform_type=macos + @build_bazel_apple_support//platforms:darwin_arm64e + + --cpu=ios_i386 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_i386 + + --cpu=ios_x86_64 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_x86_64 + + --cpu=ios_sim_arm64 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_sim_arm64 + + --cpu=ios_armv7 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_armv7 + + --cpu=ios_arm64 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_arm64 + + --cpu=ios_arm64e + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_arm64e + + --cpu=tvos_x86_64 + --apple_platform_type=tvos + @build_bazel_apple_support//platforms:tvos_x86_64 + + --cpu=tvos_sim_arm64 + --apple_platform_type=tvos + @build_bazel_apple_support//platforms:tvos_sim_arm64 + + --cpu=tvos_arm64 + --apple_platform_type=tvos + @build_bazel_apple_support//platforms:tvos_arm64 + + --cpu=watchos_i386 + --apple_platform_type=watchos + @build_bazel_apple_support//platforms:watchos_i386 + + --cpu=watchos_x86_64 + --apple_platform_type=watchos + @build_bazel_apple_support//platforms:watchos_x86_64 + + --cpu=watchos_arm64 + --apple_platform_type=watchos + @build_bazel_apple_support//platforms:watchos_arm64 + + --cpu=watchos_armv7k + --apple_platform_type=watchos + @build_bazel_apple_support//platforms:watchos_armv7k + + --cpu=watchos_arm64_32 + --apple_platform_type=watchos + @build_bazel_apple_support//platforms:watchos_arm64_32 diff --git a/foreign_cc/boost_build.bzl b/foreign_cc/boost_build.bzl index 89c0c5509..d8e489f39 100644 --- a/foreign_cc/boost_build.bzl +++ b/foreign_cc/boost_build.bzl @@ -54,6 +54,7 @@ boost_build = rule( attrs = _attrs(), fragments = CC_EXTERNAL_RULE_FRAGMENTS, output_to_genfiles = True, + provides = [CcInfo], implementation = _boost_build_impl, toolchains = [ "@rules_foreign_cc//foreign_cc/private/framework:shell_toolchain", diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index abbdaf363..d781dcdc5 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -148,6 +148,7 @@ load("//foreign_cc/private:transitions.bzl", "foreign_cc_rule_variant") load( "//foreign_cc/private/framework:platform.bzl", "os_name", + "target_arch_name", "target_os_name", ) load( @@ -253,6 +254,8 @@ def _create_configure_script(configureParameters): configure_script = create_cmake_script( workspace_name = ctx.workspace_name, target_os = target_os_name(ctx), + target_arch = target_arch_name(ctx), + host_os = os_name(ctx), generator = attrs.generator, cmake_path = attrs.cmake_path, tools = tools, @@ -415,6 +418,7 @@ cmake = rule( "@rules_foreign_cc//foreign_cc/private/framework:shell_toolchain", "@bazel_tools//tools/cpp:toolchain_type", ], + provides = [CcInfo], # TODO: Remove once https://github.com/bazelbuild/bazel/issues/11584 is closed and the min supported # version is updated to a release of Bazel containing the new default for this setting. incompatible_use_toolchain_transition = True, diff --git a/foreign_cc/make.bzl b/foreign_cc/make.bzl index 0691e0fbe..fcdd8a5cf 100644 --- a/foreign_cc/make.bzl +++ b/foreign_cc/make.bzl @@ -125,6 +125,7 @@ make = rule( attrs = _attrs(), fragments = CC_EXTERNAL_RULE_FRAGMENTS, output_to_genfiles = True, + provides = [CcInfo], implementation = _make, toolchains = [ "@rules_foreign_cc//toolchains:make_toolchain", diff --git a/foreign_cc/meson.bzl b/foreign_cc/meson.bzl index ee489bf13..7b26f75bd 100644 --- a/foreign_cc/meson.bzl +++ b/foreign_cc/meson.bzl @@ -149,6 +149,7 @@ meson = rule( attrs = _attrs(), fragments = CC_EXTERNAL_RULE_FRAGMENTS, output_to_genfiles = True, + provides = [CcInfo], implementation = _meson_impl, toolchains = [ "@rules_foreign_cc//toolchains:meson_toolchain", diff --git a/foreign_cc/ninja.bzl b/foreign_cc/ninja.bzl index b59b2d130..9b872e622 100644 --- a/foreign_cc/ninja.bzl +++ b/foreign_cc/ninja.bzl @@ -111,6 +111,7 @@ ninja = rule( attrs = _attrs(), fragments = CC_EXTERNAL_RULE_FRAGMENTS, output_to_genfiles = True, + provides = [CcInfo], implementation = _ninja_impl, toolchains = [ "@rules_foreign_cc//toolchains:ninja_toolchain", diff --git a/foreign_cc/private/cmake_script.bzl b/foreign_cc/private/cmake_script.bzl index e2d134660..bfe21bd23 100644 --- a/foreign_cc/private/cmake_script.bzl +++ b/foreign_cc/private/cmake_script.bzl @@ -17,9 +17,30 @@ def _escape_dquote_bash_crosstool(text): # We use a starlark raw string to prevent the need to escape backslashes for starlark as well. return text.replace('"', r'\\\\\\\"') +_TARGET_OS_PARAMS = { + "android": { + "ANDROID": "YES", + "CMAKE_SYSTEM_NAME": "Linux", + }, + "linux": { + "CMAKE_SYSTEM_NAME": "Linux", + }, +} + +_TARGET_ARCH_PARAMS = { + "aarch64": { + "CMAKE_SYSTEM_PROCESSOR": "aarch64", + }, + "x86_64": { + "CMAKE_SYSTEM_PROCESSOR": "x86_64", + }, +} + def create_cmake_script( workspace_name, target_os, + target_arch, + host_os, generator, cmake_path, tools, @@ -39,6 +60,8 @@ def create_cmake_script( Args: workspace_name: current workspace name target_os: The target OS for the build + target_arch: The target arch for the build + host_os: The execution OS for the build generator: The generator target for cmake to use cmake_path: The path to the cmake executable tools: cc_toolchain tools (CxxToolsInfo) @@ -93,13 +116,13 @@ def create_cmake_script( if not params.cache.get("CMAKE_RANLIB"): params.cache.update({"CMAKE_RANLIB": ""}) - # Avoid cmake passing wrong linker flags when targeting android on macOS - # https://github.com/bazelbuild/rules_foreign_cc/issues/289 - if target_os == "android": - params.cache.update({ - "ANDROID": "YES", - "CMAKE_SYSTEM_NAME": "Linux", - }) + # Avoid CMake passing the wrong linker flags when cross compiling + # by setting CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR, + # see https://github.com/bazelbuild/rules_foreign_cc/issues/289, + # and https://github.com/bazelbuild/rules_foreign_cc/pull/1062 + if target_os != host_os and target_os != "unknown": + params.cache.update(_TARGET_OS_PARAMS.get(target_os, {})) + params.cache.update(_TARGET_ARCH_PARAMS.get(target_arch, {})) set_env_vars = [ "export {}=\"{}\"".format(key, _escape_dquote_bash(params.env[key])) diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl index f165f5d72..9c263c083 100644 --- a/foreign_cc/private/framework.bzl +++ b/foreign_cc/private/framework.bzl @@ -209,6 +209,7 @@ CC_EXTERNAL_RULE_ATTRIBUTES = { cfg = "exec", default = [], ), + "_aarch64_constraint": attr.label(default = Label("@platforms//cpu:aarch64")), "_android_constraint": attr.label(default = Label("@platforms//os:android")), # we need to declare this attribute to access cc_toolchain "_cc_toolchain": attr.label( @@ -219,6 +220,8 @@ CC_EXTERNAL_RULE_ATTRIBUTES = { cfg = "exec", default = Label("@rules_foreign_cc//foreign_cc/private/framework:platform_info"), ), + "_linux_constraint": attr.label(default = Label("@platforms//os:linux")), + "_x86_64_constraint": attr.label(default = Label("@platforms//cpu:x86_64")), } # A list of common fragments required by rules using this framework diff --git a/foreign_cc/private/framework/platform.bzl b/foreign_cc/private/framework/platform.bzl index 9cc196ebb..8c9fc9ae3 100644 --- a/foreign_cc/private/framework/platform.bzl +++ b/foreign_cc/private/framework/platform.bzl @@ -66,6 +66,23 @@ def os_name(ctx): return platform_info[ForeignCcPlatformInfo].os +def target_arch_name(ctx): + """A helper function for getting the target architecture name based on the constraints + + Args: + ctx (ctx): The current rule's context object + + Returns: + str: The string of the current platform + """ + archs = ["x86_64", "aarch64"] + for arch in archs: + constraint = getattr(ctx.attr, "_{}_constraint".format(arch)) + if constraint and ctx.target_platform_has_constraint(constraint[platform_common.ConstraintValueInfo]): + return arch + + return "unknown" + def target_os_name(ctx): """A helper function for getting the target operating system name based on the constraints @@ -75,7 +92,7 @@ def target_os_name(ctx): Returns: str: The string of the current platform """ - operating_systems = ["android"] + operating_systems = ["android", "linux"] for os in operating_systems: constraint = getattr(ctx.attr, "_{}_constraint".format(os)) if constraint and ctx.target_platform_has_constraint(constraint[platform_common.ConstraintValueInfo]): diff --git a/foreign_cc/private/framework/toolchain.bzl b/foreign_cc/private/framework/toolchain.bzl index 81efcc593..8198faa70 100644 --- a/foreign_cc/private/framework/toolchain.bzl +++ b/foreign_cc/private/framework/toolchain.bzl @@ -12,14 +12,6 @@ exports_files(["defs.bzl"]) foreign_cc_framework_toolchain( name = "commands" ) - -toolchain( - name = "toolchain", - toolchain_type = "@rules_foreign_cc//foreign_cc/private/framework:shell_toolchain", - toolchain = ":commands", - exec_compatible_with = {exec_compat}, - target_compatible_with = {target_compat}, -) """ _DEFS_BZL_CONTENT = """\ @@ -52,7 +44,6 @@ def _framework_toolchain_repository_impl(repository_ctx): repository_ctx.file("BUILD.bazel", _BUILD_FILE_CONTENT.format( exec_compat = repository_ctx.attr.exec_compatible_with, - target_compat = repository_ctx.attr.target_compatible_with, )) framework_toolchain_repository = repository_rule( @@ -65,8 +56,38 @@ framework_toolchain_repository = repository_rule( "exec_compatible_with": attr.string_list( doc = "A list of constraint_values that must be present in the execution platform for this target.", ), - "target_compatible_with": attr.string_list( - doc = "A list of constraint_values that must be present in the target platform for this target to be considered compatible.", + }, +) + +_HUB_BUILD_FILE_CONTENT = """\ +toolchain( + name = "{item}", + toolchain_type = "@rules_foreign_cc//foreign_cc/private/framework:shell_toolchain", + toolchain = "@{item}//:commands", + exec_compatible_with = {exec_compat}, +) + +""" + +def _framework_toolchain_repository_hub_impl(repository_ctx): + """The implementation of `framework_toolchain_repository_hub` + + Args: + repository_ctx (repository_ctx): The rule's context object + """ + + hub_build_content = "" + for item in TOOLCHAIN_MAPPINGS: + hub_build_content += _HUB_BUILD_FILE_CONTENT.format(item = item.repo_name, exec_compat = item.exec_compatible_with) + + repository_ctx.file("BUILD.bazel", hub_build_content) + +framework_toolchain_repository_hub = repository_rule( + doc = "A repository rule which defines a `@rules_foreign_cc//foreign_cc/private/framework:shell_toolchain` hub which holds all the shell toolchains generated by `@rules_foreign_cc`.", + implementation = _framework_toolchain_repository_hub_impl, + attrs = { + "exec_compatible_with": attr.string_list( + doc = "A list of constraint_values that must be present in the execution platform for this target.", ), }, ) @@ -78,17 +99,15 @@ def register_framework_toolchains(register_toolchains = True): Args: register_toolchains: Whether to call native.register_toolchains or not """ - toolchains = [] for item in TOOLCHAIN_MAPPINGS: framework_toolchain_repository( name = item.repo_name, commands_src = item.file, exec_compatible_with = item.exec_compatible_with, - target_compatible_with = item.target_compatible_with, ) - toolchains.append("@{}//:toolchain".format(item.repo_name)) + framework_toolchain_repository_hub(name = "rules_foreign_cc_framework_toolchains") if register_toolchains: - native.register_toolchains(*toolchains) + native.register_toolchains("@rules_foreign_cc_framework_toolchains//:all") diff --git a/foreign_cc/private/framework/toolchains/mappings.bzl b/foreign_cc/private/framework/toolchains/mappings.bzl index ac1a4ea45..d614102b1 100644 --- a/foreign_cc/private/framework/toolchains/mappings.bzl +++ b/foreign_cc/private/framework/toolchains/mappings.bzl @@ -1,13 +1,12 @@ """A module defining default toolchain info for the foreign_cc framework""" -def _toolchain_mapping(file, repo_name, exec_compatible_with = [], target_compatible_with = []): +def _toolchain_mapping(file, repo_name, exec_compatible_with = []): """Mapping of toolchain definition files to platform constraints Args: file (str): Toolchain definition file repo_name (str): name of repository to create for this toolchain exec_compatible_with (list): A list of compatible execution platform constraints. - target_compatible_with (list): Compatible target platform constraints Returns: struct: A collection of toolchain data @@ -16,7 +15,6 @@ def _toolchain_mapping(file, repo_name, exec_compatible_with = [], target_compat file = file, repo_name = repo_name, exec_compatible_with = exec_compatible_with, - target_compatible_with = target_compatible_with, ) # This list is the single entrypoint for all foreign_cc framework toolchains. diff --git a/foreign_cc/repositories.bzl b/foreign_cc/repositories.bzl index d8ca2fae6..4c4931915 100644 --- a/foreign_cc/repositories.bzl +++ b/foreign_cc/repositories.bzl @@ -12,7 +12,7 @@ def rules_foreign_cc_dependencies( cmake_version = "3.23.2", make_version = "4.4", ninja_version = "1.11.1", - meson_version = "0.63.0", + meson_version = "1.1.1", pkgconfig_version = "0.29.2", register_preinstalled_tools = True, register_built_tools = True, diff --git a/foreign_cc/utils.bzl b/foreign_cc/utils.bzl index 2e87e9418..95532b094 100644 --- a/foreign_cc/utils.bzl +++ b/foreign_cc/utils.bzl @@ -9,7 +9,7 @@ def runnable_binary(name, binary, foreign_cc_target, match_binary_name = False, The wrapper script also facilitates the running of binaries that are dynamically linked to shared libraries also built by rules_foreign_cc. The runnable bin could be used as a tool in a dependent bazel target - Note that this macro only works on foreign_cc_targets in external repositories, not in the main repository. This is due to the issue described here: https://github.com/bazelbuild/bazel/issues/10923 + Note that this macro requires bazel 5.4.0 due to the use of the rlocationpath variable (see https://github.com/bazelbuild/bazel/issues/10923 for context) Also note that the macro requires the `--enable_runfiles` option to be set on Windows. Args: @@ -22,9 +22,11 @@ def runnable_binary(name, binary, foreign_cc_target, match_binary_name = False, tags = kwargs.pop("tags", []) + config_setting_name = name + "_windows_config_setting" + # filegroups cannot select on constraint_values in before Bazel 5.1. Add this config_setting as a workaround. See https://github.com/bazelbuild/bazel/issues/13047 native.config_setting( - name = "windows_config_setting", + name = config_setting_name, constraint_values = [ "@platforms//os:windows", ], @@ -35,13 +37,13 @@ def runnable_binary(name, binary, foreign_cc_target, match_binary_name = False, srcs = [foreign_cc_target], tags = tags + ["manual"], output_group = select({ - ":windows_config_setting": binary + ".exe", + ":" + config_setting_name: binary + ".exe", "//conditions:default": binary, }), ) wrapper_cmd = """ - sed s@EXECUTABLE@$(rootpath {name})@g $(location @rules_foreign_cc//foreign_cc/private:runnable_binary_wrapper.sh) > tmp + sed s@EXECUTABLE@$(rlocationpath {name})@g $(location @rules_foreign_cc//foreign_cc/private:runnable_binary_wrapper.sh) > tmp sed s@SH_BINARY_FILENAME@{sh_binary_filename}@g tmp > $@ """ diff --git a/test/cmake_text_tests.bzl b/test/cmake_text_tests.bzl index eb6ed2638..105faf5e4 100644 --- a/test/cmake_text_tests.bzl +++ b/test/cmake_text_tests.bzl @@ -243,6 +243,8 @@ def _merge_flag_values_no_toolchain_file_test(ctx): script = create_cmake_script( "ws", "unknown", + "unknown", + "unknown", "Unix Makefiles", "cmake", tools, @@ -293,6 +295,8 @@ def _create_min_cmake_script_no_toolchain_file_test(ctx): script = create_cmake_script( "ws", "unknown", + "unknown", + "unknown", "Ninja", "cmake", tools, @@ -347,6 +351,8 @@ def _create_min_cmake_script_wipe_toolchain_test(ctx): script = create_cmake_script( "ws", "unknown", + "unknown", + "unknown", "Ninja", "cmake", tools, @@ -397,6 +403,8 @@ def _create_min_cmake_script_toolchain_file_test(ctx): script = create_cmake_script( "ws", "unknown", + "unknown", + "unknown", "Ninja", "cmake", tools, @@ -475,6 +483,8 @@ def _create_cmake_script_no_toolchain_file_test(ctx): script = create_cmake_script( "ws", "unknown", + "unknown", + "unknown", "Ninja", "cmake", tools, @@ -540,6 +550,75 @@ def _create_cmake_script_android_test(ctx): script = create_cmake_script( "ws", "android", + "x86_64", + "unknown", + "Ninja", + "cmake", + tools, + flags, + "test_rule", + "external/test_rule", + True, + user_cache, + user_env, + ["--debug-output", "-Wdev"], + cmake_commands = [], + ) + expected = r"""export CC="sink-cc-value" +export CXX="sink-cxx-value" +export CFLAGS="-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag" +export CXXFLAGS="--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain" +export ASMFLAGS="assemble assemble-user" +export CUSTOM_ENV="YES" +##enable_tracing## +cmake -DCMAKE_AR="/cxx_linker_static" -DCMAKE_CXX_LINK_EXECUTABLE="became" -DCMAKE_SHARED_LINKER_FLAGS="shared1 shared2" -DCMAKE_EXE_LINKER_FLAGS="executable" -DCMAKE_BUILD_TYPE="user_type" -DCUSTOM_CACHE="YES" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$$EXT_BUILD_DEPS$$" -DCMAKE_RANLIB="" -DANDROID="YES" -DCMAKE_SYSTEM_NAME="Linux" -DCMAKE_SYSTEM_PROCESSOR="x86_64" --debug-output -Wdev -G 'Ninja' $$EXT_BUILD_ROOT$$/external/test_rule +##disable_tracing## +""" + asserts.equals(env, expected.splitlines(), script) + + return unittest.end(env) + +def _create_cmake_script_linux_test(ctx): + env = unittest.begin(ctx) + + tools = CxxToolsInfo( + cc = "/some-cc-value", + cxx = "external/cxx-value", + cxx_linker_static = "/cxx_linker_static", + cxx_linker_executable = "ws/cxx_linker_executable", + ) + flags = CxxFlagsInfo( + cc = ["-cc-flag", "-gcc_toolchain", "cc-toolchain"], + cxx = [ + "--quoted=\"abc def\"", + "--sysroot=/abc/sysroot", + "--gcc_toolchain", + "cxx-toolchain", + ], + cxx_linker_shared = ["shared1", "shared2"], + cxx_linker_static = ["static"], + cxx_linker_executable = ["executable"], + assemble = ["assemble"], + ) + user_env = { + "CC": "sink-cc-value", + "CFLAGS": "--from-env", + "CUSTOM_ENV": "YES", + "CXX": "sink-cxx-value", + } + user_cache = { + "CMAKE_ASM_FLAGS": "assemble-user", + "CMAKE_BUILD_TYPE": "user_type", + "CMAKE_CXX_LINK_EXECUTABLE": "became", + "CMAKE_C_FLAGS": "--additional-flag", + "CUSTOM_CACHE": "YES", + } + + script = create_cmake_script( + "ws", + "linux", + "aarch64", + "unknown", "Ninja", "cmake", tools, @@ -559,7 +638,7 @@ export CXXFLAGS="--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain export ASMFLAGS="assemble assemble-user" export CUSTOM_ENV="YES" ##enable_tracing## -cmake -DCMAKE_AR="/cxx_linker_static" -DCMAKE_CXX_LINK_EXECUTABLE="became" -DCMAKE_SHARED_LINKER_FLAGS="shared1 shared2" -DCMAKE_EXE_LINKER_FLAGS="executable" -DCMAKE_BUILD_TYPE="user_type" -DCUSTOM_CACHE="YES" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$$EXT_BUILD_DEPS$$" -DCMAKE_RANLIB="" -DANDROID="YES" -DCMAKE_SYSTEM_NAME="Linux" --debug-output -Wdev -G 'Ninja' $$EXT_BUILD_ROOT$$/external/test_rule +cmake -DCMAKE_AR="/cxx_linker_static" -DCMAKE_CXX_LINK_EXECUTABLE="became" -DCMAKE_SHARED_LINKER_FLAGS="shared1 shared2" -DCMAKE_EXE_LINKER_FLAGS="executable" -DCMAKE_BUILD_TYPE="user_type" -DCUSTOM_CACHE="YES" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$$EXT_BUILD_DEPS$$" -DCMAKE_RANLIB="" -DCMAKE_SYSTEM_NAME="Linux" -DCMAKE_SYSTEM_PROCESSOR="aarch64" --debug-output -Wdev -G 'Ninja' $$EXT_BUILD_ROOT$$/external/test_rule ##disable_tracing## """ asserts.equals(env, expected.splitlines(), script) @@ -604,6 +683,8 @@ def _create_cmake_script_toolchain_file_test(ctx): script = create_cmake_script( "ws", "unknown", + "unknown", + "unknown", "Ninja", "cmake", tools, @@ -664,6 +745,7 @@ create_min_cmake_script_toolchain_file_test = unittest.make(_create_min_cmake_sc create_cmake_script_no_toolchain_file_test = unittest.make(_create_cmake_script_no_toolchain_file_test) create_cmake_script_toolchain_file_test = unittest.make(_create_cmake_script_toolchain_file_test) create_cmake_script_android_test = unittest.make(_create_cmake_script_android_test) +create_cmake_script_linux_test = unittest.make(_create_cmake_script_linux_test) merge_flag_values_no_toolchain_file_test = unittest.make(_merge_flag_values_no_toolchain_file_test) create_min_cmake_script_wipe_toolchain_test = unittest.make(_create_min_cmake_script_wipe_toolchain_test) @@ -682,6 +764,7 @@ def cmake_script_test_suite(): create_cmake_script_no_toolchain_file_test, create_cmake_script_toolchain_file_test, create_cmake_script_android_test, + create_cmake_script_linux_test, merge_flag_values_no_toolchain_file_test, create_min_cmake_script_wipe_toolchain_test, ) diff --git a/toolchains/built_toolchains.bzl b/toolchains/built_toolchains.bzl index 8b9c16a90..4f3225252 100644 --- a/toolchains/built_toolchains.bzl +++ b/toolchains/built_toolchains.bzl @@ -161,6 +161,15 @@ def _meson_toolchain(version, register_toolchains): native.register_toolchains( "@rules_foreign_cc//toolchains:built_meson_toolchain", ) + if version == "1.1.1": + maybe( + http_archive, + name = "meson_src", + build_file_content = _MESON_BUILD_FILE_CONTENT, + strip_prefix = "meson-1.1.1", + url = "https://github.com/mesonbuild/meson/releases/download/1.1.1/meson-1.1.1.tar.gz", + ) + return if version == "0.63.0": maybe( http_archive, diff --git a/toolchains/cmake_versions.bzl b/toolchains/cmake_versions.bzl index e103b63fd..1d65c875c 100644 --- a/toolchains/cmake_versions.bzl +++ b/toolchains/cmake_versions.bzl @@ -384,6 +384,13 @@ CMAKE_SRCS = { "cmake-3.26.3", "bbd8d39217509d163cb544a40d6428ac666ddc83e22905d3e52c925781f0f659", ], + "3.26.4": [ + [ + "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4.tar.gz", + ], + "cmake-3.26.4", + "313b6880c291bd4fe31c0aa51d6e62659282a521e695f30d5cc0d25abbd5c208", + ], "3.3.2": [ [ "https://github.com/Kitware/CMake/releases/download/v3.3.2/cmake-3.3.2.tar.gz", diff --git a/toolchains/prebuilt_toolchains.bzl b/toolchains/prebuilt_toolchains.bzl index ab826b9b8..0a7eaece2 100644 --- a/toolchains/prebuilt_toolchains.bzl +++ b/toolchains/prebuilt_toolchains.bzl @@ -66,6 +66,116 @@ def prebuilt_toolchains(cmake_version, ninja_version, register_toolchains): _ninja_toolchains(ninja_version, register_toolchains) def _cmake_toolchains(version, register_toolchains): + if "3.26.4" == version: + maybe( + http_archive, + name = "cmake-3.26.4-linux-aarch64", + urls = [ + "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-aarch64.tar.gz", + ], + sha256 = "1c9843c92f40bee1a16baa12871693d3e190c9a222259a89e406d4d9aae6cf74", + strip_prefix = "cmake-3.26.4-linux-aarch64", + build_file_content = _CMAKE_BUILD_FILE.format( + bin = "cmake", + env = "{}", + ), + ) + + maybe( + http_archive, + name = "cmake-3.26.4-linux-x86_64", + urls = [ + "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-x86_64.tar.gz", + ], + sha256 = "ba1e0dcc710e2f92be6263f9617510b3660fa9dc409ad2fb8190299563f952a0", + strip_prefix = "cmake-3.26.4-linux-x86_64", + build_file_content = _CMAKE_BUILD_FILE.format( + bin = "cmake", + env = "{}", + ), + ) + + maybe( + http_archive, + name = "cmake-3.26.4-macos-universal", + urls = [ + "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-macos-universal.tar.gz", + ], + sha256 = "5417fb979c1f82aaffe4420112e2c84562c024b6683161afb520c9e378161340", + strip_prefix = "cmake-3.26.4-macos-universal/CMake.app/Contents", + build_file_content = _CMAKE_BUILD_FILE.format( + bin = "cmake", + env = "{}", + ), + ) + + maybe( + http_archive, + name = "cmake-3.26.4-windows-i386", + urls = [ + "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-windows-i386.zip", + ], + sha256 = "342ca44f494985f8ef43676eb8a0404b2c68321036e28aa221ceab51d377b158", + strip_prefix = "cmake-3.26.4-windows-i386", + build_file_content = _CMAKE_BUILD_FILE.format( + bin = "cmake.exe", + env = "{}", + ), + ) + + maybe( + http_archive, + name = "cmake-3.26.4-windows-x86_64", + urls = [ + "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-windows-x86_64.zip", + ], + sha256 = "62c35427104a4f8205226f72708d71334bd36a72cf72c60d0e3a766d71dcc78a", + strip_prefix = "cmake-3.26.4-windows-x86_64", + build_file_content = _CMAKE_BUILD_FILE.format( + bin = "cmake.exe", + env = "{}", + ), + ) + + # buildifier: leave-alone + maybe( + prebuilt_toolchains_repository, + name = "cmake_3.26.4_toolchains", + repos = { + "cmake-3.26.4-linux-aarch64": [ + "@platforms//cpu:aarch64", + "@platforms//os:linux", + ], + "cmake-3.26.4-linux-x86_64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "cmake-3.26.4-macos-universal": [ + "@platforms//os:macos", + ], + "cmake-3.26.4-windows-i386": [ + "@platforms//cpu:x86_32", + "@platforms//os:windows", + ], + "cmake-3.26.4-windows-x86_64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + tool = "cmake", + ) + + if register_toolchains: + native.register_toolchains( + "@cmake_3.26.4_toolchains//:cmake-3.26.4-linux-aarch64_toolchain", + "@cmake_3.26.4_toolchains//:cmake-3.26.4-linux-x86_64_toolchain", + "@cmake_3.26.4_toolchains//:cmake-3.26.4-macos-universal_toolchain", + "@cmake_3.26.4_toolchains//:cmake-3.26.4-windows-i386_toolchain", + "@cmake_3.26.4_toolchains//:cmake-3.26.4-windows-x86_64_toolchain", + ) + + return + if "3.26.3" == version: maybe( http_archive, diff --git a/toolchains/prebuilt_toolchains.py b/toolchains/prebuilt_toolchains.py index deb63ee9d..e8bd9b14f 100755 --- a/toolchains/prebuilt_toolchains.py +++ b/toolchains/prebuilt_toolchains.py @@ -10,6 +10,7 @@ CMAKE_URL_TEMPLATE = "https://github.com/Kitware/CMake/releases/download/v{full}/{file}" CMAKE_VERSIONS = [ + "3.26.4", "3.26.3", "3.26.2", "3.26.1",