diff --git a/.bazelrc b/.bazelrc index 21ca904cfe2..8f01cc8531c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,10 +1,8 @@ # Global options -common - build -c opt \ --incompatible_enable_cc_toolchain_resolution \ - --incompatible_require_linker_input_cc_api + --incompatible_require_linker_input_cc_api # Aliases for user-defined flags build --flag_alias=backend_config=@config//:backend_config diff --git a/MODULE.bazel b/MODULE.bazel index 7f641e6aaaf..7b243a683de 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -32,12 +32,6 @@ sh_config_ext = use_extension("@onedal//dev/bazel/toolchains:cc_toolchain_extens use_repo(sh_config_ext, "onedal_cc_toolchain") register_toolchains("@{}//:all".format("onedal_cc_toolchain")) - -extra_toolchain_ext = use_extension("@onedal//dev/bazel/toolchains:extra_toolchain_extension.bzl", "onedal_extra_toolchain_extension") -use_repo(extra_toolchain_ext, "onedal_extra_toolchain") -register_toolchains("@{}//:all".format("onedal_extra_toolchain")) - - http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "catch2", diff --git a/dev/bazel/README.md b/dev/bazel/README.md index 4463f536fdf..d1ea5e35e3b 100644 --- a/dev/bazel/README.md +++ b/dev/bazel/README.md @@ -16,7 +16,8 @@ *******************************************************************************/--> # Bazel Guide ## Install Bazel on Linux -1. Download Bazelisk +1. Download Bazelisk. `.ci/env/bazelisk.sh` does the same with a pinned + version and a checksum check, and is what CI runs. ```sh wget -O bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/bazelisk-linux-amd64 ``` @@ -52,9 +53,10 @@ validation. 1. Install Visual Studio 2022 Build Tools with the MSVC x64 C++ toolchain. 2. Download Bazelisk for Windows and put it into a directory on `PATH`, or keep - it in the repository root as `bazelisk.exe`. + it in the repository root as `bazelisk.exe`. `.ci/env/bazelisk.ps1` does this + with a pinned version and a checksum check, and is what CI runs. ```bat - set BAZELISK_VERSION=v1.28.1 + set BAZELISK_VERSION=v1.29.0 curl.exe -L -o bazelisk.exe https://github.com/bazelbuild/bazelisk/releases/download/%BAZELISK_VERSION%/bazelisk-windows-amd64.exe bazelisk.exe version ``` @@ -225,18 +227,19 @@ The most used Bazel commands are `build`, `test` and `run`. - `--cpu` CPU instruction sets to compile library for. \ Possible values: - - `auto` _(default)_ Automatically detects highest available instruction set - on the local machine. If detection failed, uses `avx2`. + - `auto` _(default)_ Automatically detects the highest instruction set + available on the local machine and builds it together with the `sse2` + dispatch baseline, which is always included on x86. - `modern` Compiles for `sse2`, `avx2`, `avx512`. - `all` Compiles for all instruction sets listed below. - - Any comma-separated combination of the following values: + - Any space-separated combination of the following values: - `sse2` - `avx2` - `avx512` Example: ```sh - bazel test --cpu="avx2,avx512" //cpp/oneapi/dal:tests + bazel test --cpu="avx2 avx512" //cpp/oneapi/dal:tests ``` - `--test_external_datasets` A switch that enables @@ -407,7 +410,10 @@ driver in DPC++ link actions while moving large object lists to a response file. Each script contains detailed usage and maintenance comments. When package contents change, update the Bazel packaging rules or the common -comparator rather than hiding differences in a platform wrapper. +comparator rather than hiding differences in a platform wrapper. The same goes +for the build itself: prefer a Bazel action to a helper script. The scripts that +remain are listed in `dev/bazel/TODO.md` together with what each of them is +waiting on. ### Run oneAPI examples - To run all oneAPI C++ example use the following commands: @@ -561,9 +567,6 @@ dal_test_suite( bazel test --test_link_mode=release_dynamic //cpp/oneapi/dal:tests ``` -## What is missing in this guide -- How to get make-like release structure - ## Standard-library allocator For Linux DAAL core objects, this is equivalent to the allocator-selection diff --git a/dev/bazel/TODO.md b/dev/bazel/TODO.md index 4a81faf5a5b..dcc7902511f 100644 --- a/dev/bazel/TODO.md +++ b/dev/bazel/TODO.md @@ -15,22 +15,71 @@ * limitations under the License. *******************************************************************************/--> -### TODO: -- [ ] **Windows support.** Bazel shall provide toolchain implementation for - Windows. +### Done: + +- [x] **Windows support.** `toolchains/cc_toolchain_win.bzl` configures Intel + `icx` and, when it is not on `PATH`, MSVC `cl` through rules_cc's + auto-configuration. `//:release` and `//:release_all` build on Windows in both + CRT flavours and are covered by CI. Running DPC++ examples and tests there is + still open, see below. -- [ ] **Release to oneAPI structure.** Bazel shall write headers, binaries, - examples and scripts to oneAPI release structure as the current make does. +- [x] **Release to oneAPI structure.** `//:release` writes headers, libraries, + examples, environment scripts, pkg-config and CMake metadata to + `bazel-bin/release/daal/latest`. Nightly CI compares that tree against the + Make one with `dev/release_tests/compare_release_trees.py`. + +- [x] **Automatic host architecture identification.** `--cpu=auto`, the default, + detects the highest instruction set available on the host and adds the `sse2` + baseline. + +### TODO: - [ ] **Extend compiler support matrix.** Current status: | | Intel | DPC++ | GCC | Clang | MSVC | |---------|:------------------:|:------------------:|:------------------:|:------------------:|:------------------:| - | Linux | :x: | :x: | :heavy_check_mark: | | | - | Windows | :x: | :x: | | | :x: | + | Linux | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | + | Windows | :heavy_check_mark: | :heavy_check_mark: | | :x: | :heavy_check_mark: | + + Intel `icx`/`icpx` is preferred whenever it is on `PATH`; `CC` overrides the + choice. Linux Clang builds `//:release`, but no CI job selects it, so + regressions in that flag set are only found by hand. Windows Clang + (`clang-cl`) is added by #3795. + +- [ ] **Windows DPC++ execution.** Windows release artifacts can include the + DPC++ libraries, but the examples and tests that create a SYCL queue are not + run there yet; that needs device and runtime validation on the CI images. -- [ ] **Automatic host architecture identification.** Bazel shall detect host - machine architecture and configure best CPU id automatically. +- [ ] **Toolchain flag tables as data.** The Linux and Windows + `cc_toolchain_config` rules now share their action groups, their + attribute-driven features and their rule attributes through + `toolchains/cc_toolchain_config_common.bzl`. What is left in the two files is + not duplication: no same-named feature emits the same flags on both + platforms, so folding them together would put a per-platform branch inside + every factory. The duplication that is real sits in `toolchains/common.bzl`, + where the per-compiler, per-OS, per-ISA flag lists are spelled out in + Starlark control flow and would read better as a table. -- [ ] **Toolchain code unification.** There is logic duplication for toolchain - configuration on Linux/Windows. +- [ ] **Hermetic toolchain.** The compiler, archiver, linker and strip tool are + absolute paths found with `repo_ctx.which()` at configure time. A build + therefore depends on the host `PATH`, and nothing invalidates the action cache + when the compiler behind that path changes. Registering a downloaded toolchain + would fix both. +- [ ] **Remove the remaining helper scripts.** Four are left, and each waits on + something Bazel or rules_cc does not expose: + - `toolchains/tools/dll_to_implib.bat` — `cc_common.link()` does not register + `supports_interface_shared_libraries` for this toolchain config and cannot + declare `-IMPLIB:`'s side-effect file as an output, so the import library is + derived from `dumpbin` output after the link. + - `toolchains/tools/copy_crlf.bat` — the release tree needs CRLF text files + and no Bazel action rewrites line endings. + - `toolchains/tools/dpc_link_win.ps1` and its `.tpl.bat` launcher — keeps the + Intel driver in DPC++ link actions while spilling long object lists into a + response file, which the driver needs and Bazel's own param-file support + does not provide for a wrapped tool. + - `toolchains/tools/tool_not_found.tpl.sh` and `.tpl.bat` — stand in for an + optional tool that is not installed, today only the DPC++ compiler, and + fail the action that reaches them. The failure belongs in analysis instead: + `@config` already knows whether DPC++ was found, so a DPC++ target could + `select()` onto an error target the way `daal_module` does for `--stdalloc` + on non-Linux. diff --git a/dev/bazel/cc.bzl b/dev/bazel/cc.bzl index 93ca0c1109b..6ee502067ba 100644 --- a/dev/bazel/cc.bzl +++ b/dev/bazel/cc.bzl @@ -15,7 +15,6 @@ #=============================================================================== load("@onedal//dev/bazel:utils.bzl", - "utils", "paths", "sets", ) @@ -317,31 +316,39 @@ cc_static_lib = rule( ) -def _copy_dynamic_release_file(ctx, src, out_name, is_windows = False, extra_inputs = []): +def _copy_windows_release_file(ctx, src, out_name, extra_inputs = []): + """Copy a linker output under the file name the release layout expects. + + Windows only: the Linux release names come straight out of the link action, + while a DLL and its import library have to be renamed afterwards (see + `_cc_dynamic_lib_impl`). A symlink is not enough, because creating one + requires developer mode on Windows. + + Args: + ctx: rule context. + src: the file produced by the link action. + out_name: base name of the copy, declared in the current package. + extra_inputs: further link outputs to declare as inputs, so that the + copy cannot run before the whole link action has completed. + + Returns: + The declared copy. + """ out = ctx.actions.declare_file(out_name) - if is_windows: - ctx.actions.run( - executable = "cmd.exe", - inputs = [src] + extra_inputs, - outputs = [out], - arguments = [ - "/d", - "/c", - 'copy /Y "{}" "{}"'.format( - src.path.replace("/", "\\"), - out.path.replace("/", "\\"), - ), - ], - use_default_shell_env = True, - ) - else: - ctx.actions.run( - executable = "cp", - inputs = [src] + extra_inputs, - outputs = [out], - arguments = [src.path, out.path], - use_default_shell_env = True, - ) + ctx.actions.run( + executable = "cmd.exe", + inputs = [src] + extra_inputs, + outputs = [out], + arguments = [ + "/d", + "/c", + 'copy /Y "{}" "{}"'.format( + src.path.replace("/", "\\"), + out.path.replace("/", "\\"), + ), + ], + use_default_shell_env = True, + ) return out @@ -407,19 +414,17 @@ def _cc_dynamic_lib_impl(ctx): if dynamic_outputs.dynamic_library.basename == dynamic_release_name: default_files.append(dynamic_outputs.dynamic_library) else: - default_files.append(_copy_dynamic_release_file( + default_files.append(_copy_windows_release_file( ctx, dynamic_outputs.dynamic_library, dynamic_release_name, - is_windows = is_windows, extra_inputs = [dynamic_outputs.interface_library] if dynamic_outputs.interface_library else [], )) if dynamic_outputs.interface_library: - default_files.append(_copy_dynamic_release_file( + default_files.append(_copy_windows_release_file( ctx, dynamic_outputs.interface_library, "{}_dll.lib".format(rt_name), - is_windows = is_windows, )) default_info = DefaultInfo( files = depset(default_files), diff --git a/dev/bazel/cc/common.bzl b/dev/bazel/cc/common.bzl index d02c0f34b4a..64e56954f1e 100644 --- a/dev/bazel/cc/common.bzl +++ b/dev/bazel/cc/common.bzl @@ -19,7 +19,6 @@ load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("@onedal//dev/bazel:utils.bzl", "utils", - "paths", "sets", ) diff --git a/dev/bazel/cc/link.bzl b/dev/bazel/cc/link.bzl index 9cf40cf8077..f22c56e480b 100644 --- a/dev/bazel/cc/link.bzl +++ b/dev/bazel/cc/link.bzl @@ -20,12 +20,8 @@ load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") load("@onedal//dev/bazel:utils.bzl", "utils", "paths", - "sets", ) -load("@onedal//dev/bazel/toolchains:action_names.bzl", - "CPP_MERGE_STATIC_LIBRARIES" -) load("@onedal//dev/bazel/cc:common.bzl", onedal_cc_common = "common", ) @@ -45,12 +41,39 @@ def _filter_user_link_flags(feature_configuration, user_link_flags): def _merge_static_libs(filename, actions, cc_toolchain, feature_configuration, static_libs, is_windows = False): + """Archive whole static libraries into a single library. + + `cc_common` has no API for this: its archiving action adds an input + archive as a member instead of copying the members out of it, so the + archiver has to be driven directly. + + On Windows `lib` takes the inputs on its command line, and loose object + files can go in alongside the archives. GNU `ar` instead needs an MRI + script on stdin, which `actions.write` produces and the shell redirects; + that keeps the archiver the toolchain's own, tracked + `cpp_link_static_library` tool rather than a wrapper script generated by + the repository rule. On Linux `static_libs` holds archives only, since + object files go through `cc_common` first. + + Args: + filename: basename of the library to produce. + actions: the rule context's `actions`. + cc_toolchain: the resolved `CcToolchainInfo`. + feature_configuration: the configured features, used to look up the + archiver. + static_libs: static libraries to merge, plus loose object files on + Windows. + is_windows: whether the target platform is Windows. + + Returns: + The merged library `File`. + """ output_file = actions.declare_file(filename) + archiver_path = cc_common.get_tool_for_action( + feature_configuration = feature_configuration, + action_name = ACTION_NAMES.cpp_link_static_library, + ) if is_windows: - merger_path = cc_common.get_tool_for_action( - feature_configuration = feature_configuration, - action_name = ACTION_NAMES.cpp_link_static_library, - ) args = actions.args() args.use_param_file("@%s", use_always = True) args.set_param_file_format("multiline") @@ -58,7 +81,7 @@ def _merge_static_libs(filename, actions, cc_toolchain, args.add("/OUT:" + output_file.path) args.add_all(static_libs) actions.run( - executable = merger_path, + executable = archiver_path, arguments = [args], inputs = static_libs, outputs = [output_file], @@ -66,40 +89,26 @@ def _merge_static_libs(filename, actions, cc_toolchain, use_default_shell_env = True, ) return output_file - merger_path = cc_common.get_tool_for_action( - feature_configuration = feature_configuration, - action_name = CPP_MERGE_STATIC_LIBRARIES, - ) - merger_variables = cc_common.create_link_variables( - feature_configuration = feature_configuration, - cc_toolchain = cc_toolchain, - is_using_linker = False, - ) - command_line = cc_common.get_memory_inefficient_command_line( - feature_configuration = feature_configuration, - action_name = CPP_MERGE_STATIC_LIBRARIES, - variables = merger_variables, - ) - args = actions.args() - args.add_all(command_line) - args.add(output_file) - args.add_all(static_libs) - env = cc_common.get_environment_variables( - feature_configuration = feature_configuration, - action_name = CPP_MERGE_STATIC_LIBRARIES, - variables = merger_variables, + mri_script = actions.declare_file(filename + ".mri") + actions.write( + output = mri_script, + content = "\n".join( + ["CREATE " + output_file.path] + + ["ADDLIB " + lib.path for lib in static_libs] + + ["SAVE", ""] + ), ) - actions.run( - executable = merger_path, - arguments = [args], - env = env, + actions.run_shell( + command = '"{}" -M < "{}"'.format(archiver_path, mri_script.path), inputs = depset( - direct = static_libs, + direct = static_libs + [mri_script], transitive = [ cc_toolchain.all_files, ], ), outputs = [output_file], + mnemonic = "MergeStaticLibraries", + progress_message = "Merging static libraries into %{output}", ) return output_file @@ -298,8 +307,13 @@ def _link(owner, name, actions, cc_toolchain, # @file spelling is a response file, not a DEF file, and causes the # Windows linker to export symbols discovered from whole archives # instead of the explicit Make-compatible export surface. - def_file_link_flags = (["/DEF:" + def_file.path] if is_windows else - ["@" + def_file.path]) + # + # A module-definition file has no counterpart in the GNU toolchain; a + # version script (`-Wl,--version-script=`) is the equivalent there and + # is a different file format, so a `.def` cannot be forwarded. + if not is_windows: + fail("'{}': def_file is supported on Windows only".format(name)) + def_file_link_flags = ["/DEF:" + def_file.path] linking_outputs = cc_common.link( name = name, actions = actions, diff --git a/dev/bazel/daal.bzl b/dev/bazel/daal.bzl index 24863a55a69..3a442651a3f 100644 --- a/dev/bazel/daal.bzl +++ b/dev/bazel/daal.bzl @@ -162,10 +162,6 @@ daal_generate_version = rule( }, ) -def _get_tool_for_kernel_defines_patching(ctx): - return ctx.toolchains["@onedal//dev/bazel/toolchains:extra"] \ - .extra_toolchain_info.patch_daal_kernel_defines - def _get_disabled_cpus(ctx): cpu_info = ctx.attr._cpus[CpuInfo] all_cpus = sets.make(cpu_info.allowed) @@ -178,17 +174,39 @@ def _declare_patched_kernel_defines(ctx): return ctx.actions.declare_file(patched_path) def _daal_patch_kernel_defines_impl(ctx): - disabled_cpus = _get_disabled_cpus(ctx) + """Comment out the `DAAL_KERNEL_` defines of the disabled ISAs. + + `cpp/daal/include/services/internal/daal_kernel_defines.h` enables every + CPU dispatch variant oneDAL can build; the ones `--cpu` leaves out have to + be removed from the header before it is compiled or released. The Makefile + does it with + + sed -b -i -E -e 's/^#define DAAL_KERNEL_\\b/$(sed.eol)/' + + where `sed.eol` is empty on Linux and a lone CR on Windows, so that a + disabled define leaves behind an empty line with the platform's own line + ending while every other line is untouched. `expand_template` does exactly + that substitution, without a helper script: it rewrites the file at + execution time, so nothing has to read its contents during analysis. + + The key spans the whole line, newlines included, so that it matches only a + bare `#define DAAL_KERNEL_` like sed's `^...\\b` and never a longer + macro name or a comment. The header is `eol=lf` (see `.gitattributes`) and + no define sits on its first line. Each substitution keeps the trailing + newline, so adjacent disabled defines still match one after another. + """ + disabled_cpus = sets.to_list(_get_disabled_cpus(ctx)) kernel_defines = _declare_patched_kernel_defines(ctx) - ctx.actions.run( - executable = _get_tool_for_kernel_defines_patching(ctx), - arguments = [ - ctx.file.src.path, - kernel_defines.path, - " ".join(sets.to_list(disabled_cpus)), - ], - inputs = [ctx.file.src], - outputs = [kernel_defines], + is_windows = ctx.target_platform_has_constraint( + ctx.attr._windows_constraint[platform_common.ConstraintValueInfo], + ) + ctx.actions.expand_template( + template = ctx.file.src, + output = kernel_defines, + substitutions = { + "\n#define DAAL_KERNEL_{}\n".format(cpu.upper()): "\n\r\n" if is_windows else "\n\n" + for cpu in disabled_cpus + }, ) return [ DefaultInfo(files=depset([ kernel_defines ])) ] @@ -200,6 +218,8 @@ daal_patch_kernel_defines = rule( "_cpus": attr.label( default = "@config//:cpu", ), + "_windows_constraint": attr.label( + default = "@platforms//os:windows", + ), }, - toolchains = ["@onedal//dev/bazel/toolchains:extra"], ) diff --git a/dev/bazel/flags.bzl b/dev/bazel/flags.bzl index d5199c9696f..e5bbbc1be93 100644 --- a/dev/bazel/flags.bzl +++ b/dev/bazel/flags.bzl @@ -147,7 +147,10 @@ def get_default_flags(arch_id, os_id, compiler_id, category = "common"): # `pass-failed` report there is a real problem worth failing on. "-Wno-pass-failed", ] - if compiler_id not in ["icx", "icpx"]: + if compiler_id == "gcc": + # Matches COMPILER.all.gnu in dev/make/compiler_definitions/gnu.32e.mk, + # which pairs it with `-fwrapv`. Clang treats it as implied by + # `-fwrapv` above and reports it unused, which `-Werror` makes fatal. flags = flags + ["-fno-strict-overflow"] if arch_id in ["arm", "riscv64"]: # ARM/RISC-V ship a single fixed ISA variant (see cpu_type.h), diff --git a/dev/bazel/release.bzl b/dev/bazel/release.bzl index 04cd2ee0653..c20ab023388 100644 --- a/dev/bazel/release.bzl +++ b/dev/bazel/release.bzl @@ -558,7 +558,6 @@ def _copy_data(ctx, prefix): return dst_files def _copy_to_release_impl(ctx): - extra_toolchain = ctx.toolchains["@onedal//dev/bazel/toolchains:extra"] prefix = ctx.attr.name + "/daal/latest" version_info = ctx.attr._version_info[VersionInfo] if ctx.attr._version_info else None files = [] @@ -641,9 +640,6 @@ _release = rule( default = "@bazel_tools//tools/allowlists/function_transition_allowlist", ), }, - toolchains = [ - "@onedal//dev/bazel/toolchains:extra" - ], ) def _headers_filter_impl(ctx): diff --git a/dev/bazel/toolchains/BUILD b/dev/bazel/toolchains/BUILD index 8ad934e9842..275769800fc 100644 --- a/dev/bazel/toolchains/BUILD +++ b/dev/bazel/toolchains/BUILD @@ -15,5 +15,3 @@ #=============================================================================== package(default_visibility = ["//visibility:public"]) - -toolchain_type(name = "extra") diff --git a/dev/bazel/toolchains/action_names.bzl b/dev/bazel/toolchains/action_names.bzl deleted file mode 100644 index 5ee55536bb8..00000000000 --- a/dev/bazel/toolchains/action_names.bzl +++ /dev/null @@ -1,21 +0,0 @@ -#=============================================================================== -# Copyright 2020 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -CPP_MERGE_STATIC_LIBRARIES = "cpp_merge_static_libraries" - -ACTION_NAMES = struct( - cpp_merge_static_libraries = CPP_MERGE_STATIC_LIBRARIES, -) diff --git a/dev/bazel/toolchains/cc_toolchain_config_common.bzl b/dev/bazel/toolchains/cc_toolchain_config_common.bzl new file mode 100644 index 00000000000..b18ef88cc00 --- /dev/null +++ b/dev/bazel/toolchains/cc_toolchain_config_common.bzl @@ -0,0 +1,339 @@ +#=============================================================================== +# Copyright contributors to the oneDAL project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#=============================================================================== + +"""Parts shared by the Linux and Windows `cc_toolchain_config` implementations. + +`cc_toolchain_config_lnx.bzl` and `cc_toolchain_config_win.bzl` describe two +different compiler drivers, so most of their features differ in the flags they +emit (`-I` against `/I`, `-MD -MF` against `/clang:-MD /clang:-MF`, and so on) +and have to stay apart. What does not differ is collected here: + +* the action groups the flag sets are attached to, which are simply lists of + `ACTION_NAMES` and were identical in both files; +* the features whose flags come entirely from rule attributes or from Bazel + build variables, and therefore contain nothing platform specific; +* the rule attributes both `cc_toolchain_config` rules declare. + +Anything added here must hold for both platforms. A feature that needs even one +different flag belongs in the platform file instead -- a shared factory with a +per-platform branch inside would be harder to follow than the duplicate it +replaces. +""" + +load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") +load("@rules_cc//cc:cc_toolchain_config_lib.bzl", + "action_config", + "feature", + "flag_group", + "flag_set", + "tool", + "with_feature_set", +) + +all_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ACTION_NAMES.lto_backend, +] + +all_cpp_compile_actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, +] + +all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +lto_index_actions = [ + ACTION_NAMES.lto_index_for_executable, + ACTION_NAMES.lto_index_for_dynamic_library, + ACTION_NAMES.lto_index_for_nodeps_dynamic_library, +] + +def _cpp_link_static_library_action(ar_path): + """Describe the static library archiving action. + + Args: + ar_path: path to the archiver, `ar` or `xilib`. + + Returns: + The `action_config`. + """ + return action_config( + action_name = ACTION_NAMES.cpp_link_static_library, + implies = [ + "archiver_flags", + "linker_param_file", + ], + tools = [ + tool(path = ar_path), + ], + ) + +def _supports_dynamic_linker_feature(): + """Declare that the toolchain can link shared libraries.""" + return feature( + name = "supports_dynamic_linker", + enabled = True, + ) + +def _do_not_link_dynamic_dependencies_feature(): + """Declare the opt-in feature that drops dynamic libraries from a link. + + Nothing enables it by default; see the comment in `_cc_dynamic_lib_impl` + (`dev/bazel/cc.bzl`) for why the released libraries must keep their + DT_NEEDED entries. It stays defined so that it remains reachable through + `--features`. + """ + return feature( + name = "do_not_link_dynamic_dependencies", + enabled = False, + ) + +def _compiler_input_flags_feature(): + """Pass the source file to the compiler. + + `-c` is spelled the same way by gcc and by icx on Windows, which accepts + both the GNU and the MSVC spelling, so this needs no platform variant. + """ + return feature( + name = "compiler_input_flags", + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["-c", "%{source_file}"], + expand_if_available = "source_file", + ), + ], + ), + ], + ) + +def _linker_param_file_feature(): + """Let the linker and the archiver read their inputs from a param file.""" + return feature( + name = "linker_param_file", + flag_sets = [ + flag_set( + actions = all_link_actions + + [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group( + flags = ["@%{linker_param_file}"], + expand_if_available = "linker_param_file", + ), + ], + ), + ], + ) + +def _user_compile_flags_feature(): + """Append the flags a target asks for through `copts`.""" + return feature( + name = "user_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = ["%{user_compile_flags}"], + iterate_over = "user_compile_flags", + expand_if_available = "user_compile_flags", + ), + ], + ), + ], + ) + +def _user_link_flags_feature(): + """Append the flags a target asks for through `linkopts`.""" + return feature( + name = "user_link_flags", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + flags = ["%{user_link_flags}"], + iterate_over = "user_link_flags", + expand_if_available = "user_link_flags", + ), + ], + ), + ], + ) + +def _default_link_flags_feature(link_flags_cc, link_flags_dpcc, opt_link_flags): + """Apply the toolchain's own link flags, picked by compiler and by mode. + + Args: + link_flags_cc: flags for the host compiler. + link_flags_dpcc: flags for the DPC++ compiler, used when the `dpc++` + feature is on. + opt_link_flags: flags added on top in the `opt` compilation mode. + + Returns: + The `feature`. + """ + return feature( + name = "default_link_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = link_flags_cc, + ), + ] if link_flags_cc else []), + with_features = [with_feature_set(not_features = ["dpc++"])], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = link_flags_dpcc, + ), + ] if link_flags_dpcc else []), + with_features = [with_feature_set(features = ["dpc++"])], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ([ + flag_group( + flags = opt_link_flags, + ), + ] if opt_link_flags else []), + with_features = [with_feature_set(features = ["opt"])], + ), + ], + ) + +def _default_dynamic_libraries_feature(dynamic_link_libs): + """Link the runtime libraries every oneDAL shared library needs. + + Args: + dynamic_link_libs: the libraries, e.g. `-lstdc++ -lm` on Linux. + + Returns: + The `feature`. + """ + return feature( + name = "default_dynamic_libraries", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = ( + [flag_group(flags = dynamic_link_libs)] + if dynamic_link_libs else [] + ), + with_features = [ + with_feature_set( + not_features = ["do_not_link_dynamic_dependencies"], + ), + ], + ), + ], + ) + +def _cpu_opt_feature(cpu_id, cpu_flags_cc, cpu_flags_dpcc): + """Describe the per-ISA compile flags of a single CPU dispatch variant. + + Args: + cpu_id: the ISA identifier, e.g. `avx2`; names the feature. + cpu_flags_cc: flags for the host compiler. + cpu_flags_dpcc: flags for the DPC++ compiler. + + Returns: + The `feature`, named `_flags`. + """ + return feature( + name = "{}_flags".format(cpu_id), + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = cpu_flags_cc)], + with_features = [with_feature_set(not_features = ["dpc++"])], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = cpu_flags_dpcc)], + with_features = [with_feature_set(features = ["dpc++"])], + ), + ], + ) + +# Attributes declared by both `cc_toolchain_config` rules. Each platform adds +# its own on top, see the `rule()` calls in the two files. +COMMON_ATTRS = { + "cpu": attr.string(mandatory = True), + "compiler": attr.string(mandatory = True), + "toolchain_identifier": attr.string(mandatory = True), + "host_system_name": attr.string(mandatory = True), + "target_system_name": attr.string(mandatory = True), + "target_libc": attr.string(mandatory = True), + "abi_version": attr.string(mandatory = True), + "abi_libc_version": attr.string(mandatory = True), + "cc_path": attr.string(mandatory = True), + "dpcc_path": attr.string(mandatory = True), + "ar_path": attr.string(mandatory = True), + "cxx_builtin_include_directories": attr.string_list(), + "compile_flags_cc": attr.string_list(), + "compile_flags_dpcc": attr.string_list(), + "compile_flags_pedantic_cc": attr.string_list(), + "compile_flags_pedantic_dpcc": attr.string_list(), + "dbg_compile_flags": attr.string_list(), + "opt_compile_flags": attr.string_list(), + "cxx_flags": attr.string_list(), + "link_flags_cc": attr.string_list(), + "link_flags_dpcc": attr.string_list(), + "dynamic_link_libs": attr.string_list(), + "opt_link_flags": attr.string_list(), + "deterministic_compile_flags": attr.string_list(), + "cpu_flags_cc": attr.string_list_dict(), + "cpu_flags_dpcc": attr.string_list_dict(), +} + +common = struct( + cpp_link_static_library_action = _cpp_link_static_library_action, + supports_dynamic_linker_feature = _supports_dynamic_linker_feature, + do_not_link_dynamic_dependencies_feature = + _do_not_link_dynamic_dependencies_feature, + compiler_input_flags_feature = _compiler_input_flags_feature, + linker_param_file_feature = _linker_param_file_feature, + user_compile_flags_feature = _user_compile_flags_feature, + user_link_flags_feature = _user_link_flags_feature, + default_link_flags_feature = _default_link_flags_feature, + default_dynamic_libraries_feature = _default_dynamic_libraries_feature, + cpu_opt_feature = _cpu_opt_feature, +) diff --git a/dev/bazel/toolchains/cc_toolchain_config_lnx.bzl b/dev/bazel/toolchains/cc_toolchain_config_lnx.bzl index 031cdda74ec..eb5611197b5 100644 --- a/dev/bazel/toolchains/cc_toolchain_config_lnx.bzl +++ b/dev/bazel/toolchains/cc_toolchain_config_lnx.bzl @@ -18,73 +18,23 @@ load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") load("@rules_cc//cc:cc_toolchain_config_lib.bzl", "feature", - "feature_set", "flag_group", "flag_set", - "tool_path", "variable_with_value", "with_feature_set", "action_config", "tool", - "artifact_name_pattern", ) -load("@onedal//dev/bazel/toolchains:action_names.bzl", "CPP_MERGE_STATIC_LIBRARIES") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") - -all_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, -] - -preprocessor_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.clif_match, -] - -codegen_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.lto_backend, -] - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -lto_index_actions = [ - ACTION_NAMES.lto_index_for_executable, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, -] +load("@onedal//dev/bazel/toolchains:cc_toolchain_config_common.bzl", + "common", + "all_compile_actions", + "all_cpp_compile_actions", + "all_link_actions", + "lto_index_actions", + "COMMON_ATTRS", +) def _impl(ctx): cc_tool = tool( @@ -101,20 +51,6 @@ def _impl(ctx): ], ) - cc_link_tool = tool( - path = ctx.attr.cc_link_path, - with_features = [ - with_feature_set(not_features = ["dpc++"]) - ] - ) - - dpcc_link_tool = tool( - path = ctx.attr.dpcc_link_path, - with_features = [ - with_feature_set(features = ["dpc++"]), - ], - ) - assemble_action = action_config( action_name = ACTION_NAMES.assemble, implies = [ @@ -195,7 +131,7 @@ def _impl(ctx): "sysroot", "default_dynamic_libraries", ], - tools = [ cc_link_tool, dpcc_link_tool ], + tools = [ cc_tool, dpcc_tool ], ) cpp_link_nodeps_dynamic_library_action = action_config( @@ -211,7 +147,7 @@ def _impl(ctx): "strip_debug_symbols", "sysroot", ], - tools = [ cc_link_tool, dpcc_link_tool ], + tools = [ cc_tool, dpcc_tool ], ) cpp_link_dynamic_library_action = action_config( @@ -229,26 +165,10 @@ def _impl(ctx): "sysroot", "default_dynamic_libraries", ], - tools = [ cc_link_tool, dpcc_link_tool ], + tools = [ cc_tool, dpcc_tool ], ) - cpp_link_static_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - implies = [ - "archiver_flags", - "linker_param_file", - ], - tools = [ - tool(path = ctx.attr.ar_path) - ], - ) - - cpp_merge_static_libraries_action = action_config( - action_name = CPP_MERGE_STATIC_LIBRARIES, - tools = [ - tool(path = ctx.attr.ar_merge_path) - ], - ) + cpp_link_static_library_action = common.cpp_link_static_library_action(ctx.attr.ar_path) strip_action = action_config( action_name = ACTION_NAMES.strip, @@ -292,7 +212,6 @@ def _impl(ctx): cpp_link_nodeps_dynamic_library_action, cpp_link_dynamic_library_action, cpp_link_static_library_action, - cpp_merge_static_libraries_action, strip_action, ] @@ -334,30 +253,11 @@ def _impl(ctx): enabled = True, ) - supports_dynamic_linker_feature = feature( - name = "supports_dynamic_linker", - enabled = True - ) + supports_dynamic_linker_feature = common.supports_dynamic_linker_feature() - do_not_link_dynamic_dependencies_feature = feature( - name = "do_not_link_dynamic_dependencies", - enabled = False - ) + do_not_link_dynamic_dependencies_feature = common.do_not_link_dynamic_dependencies_feature() - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = [ "-c", "%{source_file}" ], - expand_if_available = "source_file", - ), - ], - ), - ], - ) + compiler_input_flags_feature = common.compiler_input_flags_feature() compiler_output_flags_feature = feature( name = "compiler_output_flags", @@ -412,21 +312,7 @@ def _impl(ctx): ], ) - linker_param_file_feature = feature( - name = "linker_param_file", - flag_sets = [ - flag_set( - actions = all_link_actions + - [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = [ "@%{linker_param_file}" ], - expand_if_available = "linker_param_file", - ), - ], - ), - ], - ) + linker_param_file_feature = common.linker_param_file_feature() default_compile_flags_feature = feature( name = "default_compile_flags", @@ -525,38 +411,10 @@ def _impl(ctx): ], ) - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.link_flags_cc, - ), - ] if ctx.attr.link_flags_cc else []), - with_features = [with_feature_set(not_features = ["dpc++"])], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.link_flags_dpcc, - ), - ] if ctx.attr.link_flags_dpcc else []), - with_features = [with_feature_set(features = ["dpc++"])], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.opt_link_flags, - ), - ] if ctx.attr.opt_link_flags else []), - with_features = [with_feature_set(features = ["opt"])], - ), - ], + default_link_flags_feature = common.default_link_flags_feature( + ctx.attr.link_flags_cc, + ctx.attr.link_flags_dpcc, + ctx.attr.opt_link_flags, ) sysroot_feature = feature( @@ -585,55 +443,12 @@ def _impl(ctx): ], ) - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) + user_compile_flags_feature = common.user_compile_flags_feature() - user_link_flags_feature = feature( - name = "user_link_flags", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - expand_if_available = "user_link_flags", - ), - ], - ), - ], - ) + user_link_flags_feature = common.user_link_flags_feature() - default_dynamic_libraries_feature = feature( - name = "default_dynamic_libraries", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ( - [flag_group(flags = ctx.attr.dynamic_link_libs)] - if ctx.attr.dynamic_link_libs else [] - ), - with_features = [ - with_feature_set( - not_features = ["do_not_link_dynamic_dependencies"], - ), - ], - ), - ], + default_dynamic_libraries_feature = common.default_dynamic_libraries_feature( + ctx.attr.dynamic_link_libs, ) unfiltered_compile_flags_feature = feature( @@ -1114,20 +929,10 @@ def _impl(ctx): features.append(force_pic_flags_feature) features.append(pic_feature) for cpu_id, flag_list in ctx.attr.cpu_flags_cc.items(): - cpu_opt_feature = feature( - name = "{}_flags".format(cpu_id), - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ flag_group(flags = flag_list) ], - with_features = [with_feature_set(not_features = ["dpc++"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ flag_group(flags = ctx.attr.cpu_flags_dpcc[cpu_id]) ], - with_features = [with_feature_set(features = ["dpc++"])], - ), - ], + cpu_opt_feature = common.cpu_opt_feature( + cpu_id, + flag_list, + ctx.attr.cpu_flags_dpcc[cpu_id], ) features.append(cpu_opt_feature) features.append(user_compile_flags_feature) @@ -1175,41 +980,15 @@ def _impl(ctx): cc_toolchain_config = rule( implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True), - "compiler": attr.string(mandatory = True), - "toolchain_identifier": attr.string(mandatory = True), - "host_system_name": attr.string(mandatory = True), - "target_system_name": attr.string(mandatory = True), - "target_libc": attr.string(mandatory = True), - "abi_version": attr.string(mandatory = True), - "abi_libc_version": attr.string(mandatory = True), - "cc_path": attr.string(mandatory = True), - "dpcc_path": attr.string(mandatory = True), - "cc_link_path": attr.string(mandatory = True), - "dpcc_link_path": attr.string(mandatory = True), - "ar_path": attr.string(mandatory = True), - "ar_merge_path": attr.string(mandatory = True), - "strip_path": attr.string(mandatory = True), - "cxx_builtin_include_directories": attr.string_list(), - "compile_flags_cc": attr.string_list(), - "compile_flags_dpcc": attr.string_list(), - "compile_flags_pedantic_cc": attr.string_list(), - "compile_flags_pedantic_dpcc": attr.string_list(), - "dbg_compile_flags": attr.string_list(), - "opt_compile_flags": attr.string_list(), - "cxx_flags": attr.string_list(), - "link_flags_cc": attr.string_list(), - "link_flags_dpcc": attr.string_list(), - "dynamic_link_libs": attr.string_list(), - "opt_link_flags": attr.string_list(), - "no_canonical_system_headers_flags_cc": attr.string_list(), - "no_canonical_system_headers_flags_dpcc": attr.string_list(), - "deterministic_compile_flags": attr.string_list(), - "supports_start_end_lib": attr.bool(), - "supports_random_seed": attr.bool(), - "cpu_flags_cc": attr.string_list_dict(), - "cpu_flags_dpcc": attr.string_list_dict(), - }, + # Platform-specific attributes; the rest are declared by + # COMMON_ATTRS. + attrs = dict( + COMMON_ATTRS, + strip_path = attr.string(mandatory = True), + no_canonical_system_headers_flags_cc = attr.string_list(), + no_canonical_system_headers_flags_dpcc = attr.string_list(), + supports_start_end_lib = attr.bool(), + supports_random_seed = attr.bool(), + ), provides = [CcToolchainConfigInfo], ) diff --git a/dev/bazel/toolchains/cc_toolchain_config_win.bzl b/dev/bazel/toolchains/cc_toolchain_config_win.bzl index 2510a8e949e..23e6ddd1624 100644 --- a/dev/bazel/toolchains/cc_toolchain_config_win.bzl +++ b/dev/bazel/toolchains/cc_toolchain_config_win.bzl @@ -36,7 +36,6 @@ load("@rules_cc//cc:cc_toolchain_config_lib.bzl", "flag_set", "env_entry", "env_set", - "tool_path", "variable_with_value", "with_feature_set", "action_config", @@ -45,50 +44,14 @@ load("@rules_cc//cc:cc_toolchain_config_lib.bzl", ) load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") - -all_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, -] - -preprocessor_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.clif_match, -] - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -lto_index_actions = [ - ACTION_NAMES.lto_index_for_executable, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, -] +load("@onedal//dev/bazel/toolchains:cc_toolchain_config_common.bzl", + "common", + "all_compile_actions", + "all_cpp_compile_actions", + "all_link_actions", + "lto_index_actions", + "COMMON_ATTRS", +) def _impl(ctx): cc_tool = tool( @@ -168,11 +131,7 @@ def _impl(ctx): implies = common_link_implies + ["shared_flag", "default_dynamic_libraries"], tools = [cc_link_tool, dpcc_link_tool], ) - cpp_link_static_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - implies = ["archiver_flags", "linker_param_file"], - tools = [tool(path = ctx.attr.ar_path)], - ) + cpp_link_static_library_action = common.cpp_link_static_library_action(ctx.attr.ar_path) action_configs = [ assemble_action, @@ -295,12 +254,8 @@ def _impl(ctx): # register a `supports_pic` feature. Matches rules_cc's MSVC auto-config # and keeps `cc_common.compile` from emitting both variants (which the # cc_module rule in dev/bazel/cc.bzl explicitly rejects). - supports_dynamic_linker_feature = feature( - name = "supports_dynamic_linker", enabled = True, - ) - do_not_link_dynamic_dependencies_feature = feature( - name = "do_not_link_dynamic_dependencies", enabled = False, - ) + supports_dynamic_linker_feature = common.supports_dynamic_linker_feature() + do_not_link_dynamic_dependencies_feature = common.do_not_link_dynamic_dependencies_feature() no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) # Inject Windows shell env vars into every compile and link action so @@ -325,16 +280,7 @@ def _impl(ctx): )] if msvc_env_entries else [], ) - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - flag_sets = [flag_set( - actions = all_compile_actions, - flag_groups = [flag_group( - flags = ["-c", "%{source_file}"], - expand_if_available = "source_file", - )], - )], - ) + compiler_input_flags_feature = common.compiler_input_flags_feature() compiler_output_flags_feature = feature( name = "compiler_output_flags", @@ -357,16 +303,7 @@ def _impl(ctx): )], ) - linker_param_file_feature = feature( - name = "linker_param_file", - flag_sets = [flag_set( - actions = all_link_actions + [ACTION_NAMES.cpp_link_static_library], - flag_groups = [flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - )], - )], - ) + linker_param_file_feature = common.linker_param_file_feature() default_compile_flags_feature = feature( name = "default_compile_flags", @@ -432,66 +369,18 @@ def _impl(ctx): ], ) - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([flag_group(flags = ctx.attr.link_flags_cc)] - if ctx.attr.link_flags_cc else []), - with_features = [with_feature_set(not_features = ["dpc++"])], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([flag_group(flags = ctx.attr.link_flags_dpcc)] - if ctx.attr.link_flags_dpcc else []), - with_features = [with_feature_set(features = ["dpc++"])], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([flag_group(flags = ctx.attr.opt_link_flags)] - if ctx.attr.opt_link_flags else []), - with_features = [with_feature_set(features = ["opt"])], - ), - ], + default_link_flags_feature = common.default_link_flags_feature( + ctx.attr.link_flags_cc, + ctx.attr.link_flags_dpcc, + ctx.attr.opt_link_flags, ) - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [flag_set( - actions = all_compile_actions, - flag_groups = [flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - )], - )], - ) + user_compile_flags_feature = common.user_compile_flags_feature() - user_link_flags_feature = feature( - name = "user_link_flags", - flag_sets = [flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - expand_if_available = "user_link_flags", - )], - )], - ) + user_link_flags_feature = common.user_link_flags_feature() - default_dynamic_libraries_feature = feature( - name = "default_dynamic_libraries", - flag_sets = [flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([flag_group(flags = ctx.attr.dynamic_link_libs)] - if ctx.attr.dynamic_link_libs else []), - with_features = [with_feature_set( - not_features = ["do_not_link_dynamic_dependencies"], - )], - )], + default_dynamic_libraries_feature = common.default_dynamic_libraries_feature( + ctx.attr.dynamic_link_libs, ) # DPC++ links go through the icx clang-cl driver so it can add SYCL device @@ -816,22 +705,10 @@ def _impl(ctx): ] for cpu_id, flag_list in ctx.attr.cpu_flags_cc.items(): - cpu_opt_feature = feature( - name = "{}_flags".format(cpu_id), - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = flag_list)], - with_features = [with_feature_set(not_features = ["dpc++"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group( - flags = ctx.attr.cpu_flags_dpcc[cpu_id], - )], - with_features = [with_feature_set(features = ["dpc++"])], - ), - ], + cpu_opt_feature = common.cpu_opt_feature( + cpu_id, + flag_list, + ctx.attr.cpu_flags_dpcc[cpu_id], ) features.append(cpu_opt_feature) @@ -926,41 +803,21 @@ def _impl(ctx): cc_toolchain_config = rule( implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True), - "compiler": attr.string(mandatory = True), - "toolchain_identifier": attr.string(mandatory = True), - "host_system_name": attr.string(mandatory = True), - "target_system_name": attr.string(mandatory = True), - "target_libc": attr.string(mandatory = True), - "abi_version": attr.string(mandatory = True), - "abi_libc_version": attr.string(mandatory = True), - "cc_path": attr.string(mandatory = True), - "dpcc_path": attr.string(mandatory = True), - "cc_link_path": attr.string(mandatory = True), - "dpcc_link_path": attr.string(mandatory = True), - "ar_path": attr.string(mandatory = True), - "cxx_builtin_include_directories": attr.string_list(), - "compile_flags_cc": attr.string_list(), - "compile_flags_dpcc": attr.string_list(), - "compile_flags_pedantic_cc": attr.string_list(), - "compile_flags_pedantic_dpcc": attr.string_list(), - "dbg_compile_flags": attr.string_list(), - "opt_compile_flags": attr.string_list(), - "cxx_flags": attr.string_list(), - "link_flags_cc": attr.string_list(), - "link_flags_dpcc": attr.string_list(), - "dynamic_link_libs": attr.string_list(), - "opt_link_flags": attr.string_list(), - "deterministic_compile_flags": attr.string_list(), - "cpu_flags_cc": attr.string_list_dict(), - "cpu_flags_dpcc": attr.string_list_dict(), + # Platform-specific attributes; the rest are declared by + # COMMON_ATTRS. + attrs = dict( + COMMON_ATTRS, + # A standalone linker, `lld-link` or `link`, rather than the compiler + # driver the compile actions use. Linux links through the driver, so + # these are Windows only. + cc_link_path = attr.string(mandatory = True), + dpcc_link_path = attr.string(mandatory = True), # `INCLUDE` / `LIB` / `PATH` values captured at repo-configure time # so bazel-sandboxed compile and link actions can find MSVC + Windows # SDK + oneAPI headers/libs without the shell env being inherited. - "env_include": attr.string(default = ""), - "env_lib": attr.string(default = ""), - "env_path": attr.string(default = ""), - }, + env_include = attr.string(default = ""), + env_lib = attr.string(default = ""), + env_path = attr.string(default = ""), + ), provides = [CcToolchainConfigInfo], ) diff --git a/dev/bazel/toolchains/cc_toolchain_lnx.bzl b/dev/bazel/toolchains/cc_toolchain_lnx.bzl index ca44a3b1b53..ac7ad7d46b1 100644 --- a/dev/bazel/toolchains/cc_toolchain_lnx.bzl +++ b/dev/bazel/toolchains/cc_toolchain_lnx.bzl @@ -63,26 +63,6 @@ def _find_tool(repo_ctx, tool_name, mandatory = False): def find_tool(repo_ctx, tool_name, mandatory = False): return _find_tool(repo_ctx, tool_name, mandatory) -def _create_ar_merge_tool(repo_ctx, ar_path): - ar_merge_name = "merge_static_libs.sh" - repo_ctx.template( - ar_merge_name, - Label("@onedal//dev/bazel/toolchains/tools:merge_static_libs_lnx.tpl.sh"), - {"%{ar_path}": ar_path}, - ) - ar_merge_path = repo_ctx.path(ar_merge_name) - return str(ar_merge_path) - -def _create_dynamic_link_wrapper(repo_ctx, prefix, cc_path): - wrapper_name = prefix + "_dynamic_link.sh" - repo_ctx.template( - wrapper_name, - Label("@onedal//dev/bazel/toolchains/tools:dynamic_link_lnx.tpl.sh"), - {"%{cc_path}": cc_path}, - ) - wrapper_path = repo_ctx.path(wrapper_name) - return str(wrapper_path) - def _find_tools(repo_ctx, reqs): # TODO: Use full compiler path from reqs # A cross-toolchain triple prefix (e.g. `aarch64-linux-gnu-`) applies to @@ -94,8 +74,6 @@ def _find_tools(repo_ctx, reqs): cc_path, _ = _find_tool(repo_ctx, cross_prefix + reqs.compiler_id, mandatory = True) strip_path, _ = _find_tool(repo_ctx, cross_prefix + "strip", mandatory = True) dpcc_path, dpcpp_found = _find_tool(repo_ctx, reqs.dpc_compiler_id, mandatory = False) - cc_link_path = _create_dynamic_link_wrapper(repo_ctx, "cc", cc_path) - dpcc_link_path = _create_dynamic_link_wrapper(repo_ctx, "dpc", dpcc_path) if dpcpp_found: # The llvm-ar tool is used because Bazel prepends directory names with +, # which caused issues with GNU ar on RHEL. Derive it from the DPC++ @@ -104,16 +82,11 @@ def _find_tools(repo_ctx, reqs): if not repo_ctx.path(ar_path).exists: auto_configure_fail("Cannot find DPC++ archiver at {}".format(ar_path)) - ar_merge_path = _create_ar_merge_tool(repo_ctx, ar_path) - return struct( cc = cc_path, dpcc = dpcc_path, - cc_link = cc_link_path, - dpcc_link = dpcc_link_path, strip = strip_path, ar = ar_path, - ar_merge = ar_merge_path, is_dpc_found = dpcpp_found, dpc_compiler_version = reqs.dpc_compiler_version ) @@ -224,21 +197,11 @@ def configure_cc_toolchain_lnx(repo_ctx, reqs): "%{compiler_deps}": get_starlark_list([ ":builtin_include_directory_paths", ]), - "%{ar_deps}": get_starlark_list([ - ":" + paths.basename(tools.ar_merge), - ]), - "%{linker_deps}": get_starlark_list([ - ":" + paths.basename(tools.cc_link), - ":" + paths.basename(tools.dpcc_link), - ]), # Tools "%{cc_path}": tools.cc, "%{dpcc_path}": tools.dpcc, - "%{cc_link_path}": tools.cc_link, - "%{dpcc_link_path}": tools.dpcc_link, "%{ar_path}": tools.ar, - "%{ar_merge_path}": tools.ar_merge, "%{strip_path}": tools.strip, "%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories), "%{compile_flags_cc}": get_starlark_list( diff --git a/dev/bazel/toolchains/cc_toolchain_lnx.tpl.BUILD b/dev/bazel/toolchains/cc_toolchain_lnx.tpl.BUILD index 112a7ffd448..4830d141523 100644 --- a/dev/bazel/toolchains/cc_toolchain_lnx.tpl.BUILD +++ b/dev/bazel/toolchains/cc_toolchain_lnx.tpl.BUILD @@ -19,26 +19,11 @@ package(default_visibility = ["//visibility:public"]) load("@onedal//dev/bazel/toolchains:cc_toolchain_config_lnx.bzl", "cc_toolchain_config") load("@rules_cc//cc:defs.bzl", "cc_toolchain") -filegroup( - name = "empty", - srcs = [], -) - filegroup( name = "compiler_deps", srcs = [%{compiler_deps}], ) -filegroup( - name = "ar_deps", - srcs = [%{ar_deps}], -) - -filegroup( - name = "linker_deps", - srcs = [%{linker_deps}], -) - cc_toolchain_config( name = "%{cc_toolchain_identifier}_config", cpu = "%{target_cpu}", @@ -51,10 +36,7 @@ cc_toolchain_config( abi_libc_version = "%{abi_libc_version}", cc_path = "%{cc_path}", dpcc_path = "%{dpcc_path}", - cc_link_path = "%{cc_link_path}", - dpcc_link_path = "%{dpcc_link_path}", ar_path = "%{ar_path}", - ar_merge_path = "%{ar_merge_path}", strip_path = "%{strip_path}", cxx_builtin_include_directories = [%{cxx_builtin_include_directories}], compile_flags_cc = [%{compile_flags_cc}], @@ -82,13 +64,8 @@ cc_toolchain( toolchain_identifier = "%{cc_toolchain_identifier}", toolchain_config = ":%{cc_toolchain_identifier}_config", all_files = ":compiler_deps", - ar_files = ":ar_deps", as_files = ":compiler_deps", compiler_files = ":compiler_deps", - dwp_files = ":empty", - linker_files = ":linker_deps", - objcopy_files = ":empty", - strip_files = ":empty", supports_param_files = %{supports_param_files}, ) diff --git a/dev/bazel/toolchains/cc_toolchain_win.bzl b/dev/bazel/toolchains/cc_toolchain_win.bzl index 95817479c76..b1fe22d194a 100644 --- a/dev/bazel/toolchains/cc_toolchain_win.bzl +++ b/dev/bazel/toolchains/cc_toolchain_win.bzl @@ -61,8 +61,9 @@ def _find_tools_icx(repo_ctx): # Use `icx.exe` (clang-cl driver) for C and C++/DPC++ compile. # For host link, call `lld-link.exe` (or link.exe) DIRECTLY rather # than going through the icx driver — mirrors makefile common.mk:125 - # (`link.dynamic.win = link ...`) and Linux's dynamic_link_lnx.tpl.sh - # wrapper. Going through icx for huge link actions caused LNK1170: + # (`link.dynamic.win = link ...`). Linux has no equivalent: there the + # driver is the linker. Going through icx for huge link actions caused + # LNK1170: # icx materialised every Bazel-line arg into a single >131071-char # line in its own intermediate response file before invoking link.exe. cc_path, _ = _find_tool(repo_ctx, "icx", mandatory = True) diff --git a/dev/bazel/toolchains/extra_toolchain.bzl b/dev/bazel/toolchains/extra_toolchain.bzl deleted file mode 100644 index a290f58d457..00000000000 --- a/dev/bazel/toolchains/extra_toolchain.bzl +++ /dev/null @@ -1,56 +0,0 @@ -#=============================================================================== -# Copyright 2020 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -load("@onedal//dev/bazel/toolchains:common.bzl", "detect_os", "detect_compiler") -load("@onedal//dev/bazel/toolchains:extra_toolchain_lnx.bzl", - "configure_extra_toolchain_lnx") -load("@onedal//dev/bazel/toolchains:extra_toolchain_win.bzl", - "configure_extra_toolchain_win") - -ExtraToolchainInfo = provider( - fields = [ - "patch_daal_kernel_defines", - ], -) - -def _extra_toolchain_impl(ctx): - toolchain_info = platform_common.ToolchainInfo( - extra_toolchain_info = ExtraToolchainInfo( - patch_daal_kernel_defines = ctx.attr.patch_daal_kernel_defines, - ), - ) - return [toolchain_info] - -extra_toolchain = rule( - implementation = _extra_toolchain_impl, - attrs = { - "patch_daal_kernel_defines": attr.string(mandatory=True), - }, -) - -def _onedal_extra_toolchain_impl(repo_ctx): - os_id = detect_os(repo_ctx) - compiler_id = detect_compiler(repo_ctx, os_id) - configure_extra_toolchain_os = { - "lnx": configure_extra_toolchain_lnx, - "win": configure_extra_toolchain_win, - }[os_id] - configure_extra_toolchain_os(repo_ctx, compiler_id) - -onedal_extra_toolchain = repository_rule( - implementation = _onedal_extra_toolchain_impl, -) - diff --git a/dev/bazel/toolchains/extra_toolchain_extension.bzl b/dev/bazel/toolchains/extra_toolchain_extension.bzl deleted file mode 100644 index 3e361661d5f..00000000000 --- a/dev/bazel/toolchains/extra_toolchain_extension.bzl +++ /dev/null @@ -1,21 +0,0 @@ -#=============================================================================== -# Copyright contributors to the oneDAL project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -load("@onedal//dev/bazel/toolchains:extra_toolchain.bzl", "onedal_extra_toolchain") - -onedal_extra_toolchain_extension = module_extension( - implementation = lambda ctx: onedal_extra_toolchain(name = "onedal_extra_toolchain"), -) diff --git a/dev/bazel/toolchains/extra_toolchain_lnx.bzl b/dev/bazel/toolchains/extra_toolchain_lnx.bzl deleted file mode 100644 index e6d2c6aa55c..00000000000 --- a/dev/bazel/toolchains/extra_toolchain_lnx.bzl +++ /dev/null @@ -1,29 +0,0 @@ -#=============================================================================== -# Copyright 2020 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -def configure_extra_toolchain_lnx(repo_ctx, compiler_id): - repo_ctx.template( - "patch_daal_kernel_defines.sh", - Label("@onedal//dev/bazel/toolchains/tools:patch_daal_kernel_defines.sh"), - ) - patch_daal_kernel_defines_path = str(repo_ctx.path("patch_daal_kernel_defines.sh")) - repo_ctx.template( - "BUILD", - Label("@onedal//dev/bazel/toolchains:extra_toolchian_lnx.tpl.BUILD"), - { - "%{patch_daal_kernel_defines}": patch_daal_kernel_defines_path, - } - ) diff --git a/dev/bazel/toolchains/extra_toolchain_win.bzl b/dev/bazel/toolchains/extra_toolchain_win.bzl deleted file mode 100644 index e4eedf4e6d4..00000000000 --- a/dev/bazel/toolchains/extra_toolchain_win.bzl +++ /dev/null @@ -1,33 +0,0 @@ -#=============================================================================== -# Copyright contributors to the oneDAL project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -def configure_extra_toolchain_win(repo_ctx, compiler_id): - repo_ctx.template( - "patch_daal_kernel_defines.cmd", - Label("@onedal//dev/bazel/toolchains/tools:patch_daal_kernel_defines.cmd"), - ) - repo_ctx.template( - "patch_daal_kernel_defines.ps1", - Label("@onedal//dev/bazel/toolchains/tools:patch_daal_kernel_defines.ps1"), - ) - patch_daal_kernel_defines_path = str(repo_ctx.path("patch_daal_kernel_defines.cmd")) - repo_ctx.template( - "BUILD", - Label("@onedal//dev/bazel/toolchains:extra_toolchain_win.tpl.BUILD"), - { - "%{patch_daal_kernel_defines}": patch_daal_kernel_defines_path, - } - ) diff --git a/dev/bazel/toolchains/extra_toolchain_win.tpl.BUILD b/dev/bazel/toolchains/extra_toolchain_win.tpl.BUILD deleted file mode 100644 index cd77ff62b5e..00000000000 --- a/dev/bazel/toolchains/extra_toolchain_win.tpl.BUILD +++ /dev/null @@ -1,22 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("@onedal//dev/bazel/toolchains:extra_toolchain.bzl", "extra_toolchain") - -extra_toolchain( - name = "extra_tools", - patch_daal_kernel_defines = "%{patch_daal_kernel_defines}", -) - -toolchain( - name = "extra_tools_win", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - toolchain = ":extra_tools", - toolchain_type = "@onedal//dev/bazel/toolchains:extra", -) diff --git a/dev/bazel/toolchains/extra_toolchian_lnx.tpl.BUILD b/dev/bazel/toolchains/extra_toolchian_lnx.tpl.BUILD deleted file mode 100644 index 42b105c259b..00000000000 --- a/dev/bazel/toolchains/extra_toolchian_lnx.tpl.BUILD +++ /dev/null @@ -1,21 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("@onedal//dev/bazel/toolchains:extra_toolchain.bzl", "extra_toolchain") - -extra_toolchain( - name = "extra_tools", - patch_daal_kernel_defines = "%{patch_daal_kernel_defines}", -) - -toolchain( - name = "extra_tools_lnx", - exec_compatible_with = [ - "@platforms//os:linux", - ], - # `patch_daal_kernel_defines.sh` is an arch-independent text patcher run - # as a build action, not something that produces target-arch code, so it - # applies regardless of target platform (including cross-compiles to - # aarch64/riscv64 where the target platform is not x86_64). - toolchain = ":extra_tools", - toolchain_type = "@onedal//dev/bazel/toolchains:extra", -) diff --git a/dev/bazel/toolchains/tools/dynamic_link_lnx.tpl.sh b/dev/bazel/toolchains/tools/dynamic_link_lnx.tpl.sh deleted file mode 100644 index e38c6a12a65..00000000000 --- a/dev/bazel/toolchains/tools/dynamic_link_lnx.tpl.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -#=============================================================================== -# Copyright 2014 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -args_patched=() -for arg in "$@" -do - if [[ $arg == *".def" ]]; then - def_file=${arg//@} - else - args_patched+=(${arg}) - fi -done - -if [[ ${def_file} ]]; then - export_symbols=$(grep -v -E '^(EXPORTS|;|$)' ${def_file} | sed -e 's/^/-u /') - echo ${export_symbols} > ${def_file}_patched - %{cc_path} "${args_patched[@]}" "@${def_file}_patched" -else - %{cc_path} "$@" -fi diff --git a/dev/bazel/toolchains/tools/merge_static_libs_lnx.tpl.sh b/dev/bazel/toolchains/tools/merge_static_libs_lnx.tpl.sh deleted file mode 100644 index 3da25b6450e..00000000000 --- a/dev/bazel/toolchains/tools/merge_static_libs_lnx.tpl.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -#=============================================================================== -# Copyright 2014 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -output=$1 - -shift -input=$* - -mri="CREATE ${output}\n" -for lib in $input -do - mri+="ADDLIB ${lib}\n" -done -mri+="SAVE\n" - -printf "${mri[@]}" | %{ar_path} -M diff --git a/dev/bazel/toolchains/tools/patch_daal_kernel_defines.cmd b/dev/bazel/toolchains/tools/patch_daal_kernel_defines.cmd deleted file mode 100644 index d8604054013..00000000000 --- a/dev/bazel/toolchains/tools/patch_daal_kernel_defines.cmd +++ /dev/null @@ -1,20 +0,0 @@ -::=============================================================================== -:: Copyright contributors to the oneDAL project -:: -:: Licensed under the Apache License, Version 2.0 (the "License"); -:: you may not use this file except in compliance with the License. -:: You may obtain a copy of the License at -:: -:: http://www.apache.org/licenses/LICENSE-2.0 -:: -:: Unless required by applicable law or agreed to in writing, software -:: distributed under the License is distributed on an "AS IS" BASIS, -:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -:: See the License for the specific language governing permissions and -:: limitations under the License. -::=============================================================================== - -@echo off -setlocal -%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0patch_daal_kernel_defines.ps1" %* -exit /b %ERRORLEVEL% diff --git a/dev/bazel/toolchains/tools/patch_daal_kernel_defines.ps1 b/dev/bazel/toolchains/tools/patch_daal_kernel_defines.ps1 deleted file mode 100644 index 0566df2f544..00000000000 --- a/dev/bazel/toolchains/tools/patch_daal_kernel_defines.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -#=============================================================================== -# Copyright contributors to the oneDAL project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -param( - [Parameter(Mandatory=$true)][string]$InputPath, - [Parameter(Mandatory=$true)][string]$OutputPath, - [string]$Cpus = "" -) - -$ErrorActionPreference = "Stop" - -if ([string]::IsNullOrWhiteSpace($Cpus)) { - Copy-Item -LiteralPath $InputPath -Destination $OutputPath -Force - exit 0 -} - -$cpuPattern = ($Cpus -split '\s+' | Where-Object { $_ } | ForEach-Object { [regex]::Escape($_.ToUpperInvariant()) }) -join '|' -$pattern = "(?m)^#define DAAL_KERNEL_($cpuPattern)\b" - -# Match the makefile byte for byte. Its recipe is -# sed -b -i -E -e 's/^#define DAAL_KERNEL_\b/$(sed.eol)/' -# with `sed.eol.win = \r`, so a disabled define becomes a lone CR that turns the -# existing LF into CRLF, while every other line keeps its original LF ending. -# Line-oriented cmdlets cannot express that: `Get-Content` drops the endings and -# `Set-Content` re-emits all of them as CRLF, which made the released header -# differ from the Make one on every line. -$content = [System.IO.File]::ReadAllText($InputPath) -$patched = [System.Text.RegularExpressions.Regex]::Replace($content, $pattern, "`r") -$utf8NoBom = New-Object System.Text.UTF8Encoding($false) -[System.IO.File]::WriteAllText($OutputPath, $patched, $utf8NoBom) diff --git a/dev/bazel/toolchains/tools/patch_daal_kernel_defines.sh b/dev/bazel/toolchains/tools/patch_daal_kernel_defines.sh deleted file mode 100755 index 70fc45a2a3d..00000000000 --- a/dev/bazel/toolchains/tools/patch_daal_kernel_defines.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -#=============================================================================== -# Copyright contributors to the oneDAL project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#=============================================================================== - -input=$1 -output=$2 -cpus=$3 - -if [ "${cpus}" == "" ]; then - cp $input $output - exit -fi - -function join { local IFS="$1"; shift; echo "$*"; } - -replacements=() -for cpu in $cpus -do - replacements+=("^#define DAAL_KERNEL_${cpu^^}\b") -done - -sed_args=$(join '|' "${replacements[@]}") -sed -E "s/${sed_args}//" $input > $output diff --git a/dev/bazel/toolchains/tools/tool_not_found.tpl.bat b/dev/bazel/toolchains/tools/tool_not_found.tpl.bat index 2833091c82a..36906c0f1f0 100644 --- a/dev/bazel/toolchains/tools/tool_not_found.tpl.bat +++ b/dev/bazel/toolchains/tools/tool_not_found.tpl.bat @@ -15,4 +15,6 @@ rem See the License for the specific language governing permissions and rem limitations under the License. rem ============================================================================ -echo "%{tool_name} is not found" +rem Stands in for a missing tool, so fail loudly instead of leaving outputs unwritten. +echo %{tool_name} is not found! Make sure it is available in PATH. 1>&2 +exit /b 1 diff --git a/dev/bazel/toolchains/tools/tool_not_found.tpl.sh b/dev/bazel/toolchains/tools/tool_not_found.tpl.sh index f6c03fd7822..7ef21d51cde 100644 --- a/dev/bazel/toolchains/tools/tool_not_found.tpl.sh +++ b/dev/bazel/toolchains/tools/tool_not_found.tpl.sh @@ -15,7 +15,7 @@ # limitations under the License. #=============================================================================== -echo -echo "%{tool_name} is not found!" -echo "Make sure %{tool_name} is available in \$PATH" -echo +# Stands in for a missing tool, so fail loudly instead of leaving outputs unwritten. +echo "%{tool_name} is not found!" >&2 +echo "Make sure %{tool_name} is available in \$PATH" >&2 +exit 1