Skip to content

Commit

Permalink
Migrate TFs third_party/gpus/crosstool to Starlark
Browse files Browse the repository at this point in the history
This cl makes this toolchain forward compatible for Bazel's incompatible flags:
* bazelbuild/bazel#7008
* bazelbuild/bazel#6861
* bazelbuild/bazel#7320

The current change creates a drop-in replacement for the proto crosstool, with the exception that:
* all legacy fields are removed
* templated variables are replaced by rule attributes
* instead of empty paths in msvc toolchain we now use 'msvc_not_used' path (CcToolchainConfigInfo doesn't allow empty strings for paths).
* introduced to_list_of_strings function so we can pass list of starlark string around

The mechanical transformation makes the crosstool definition less readable than before - this will be addressed in a subsequent change.

This change was tested by:
1) running cuda_configure.bzl and retrieving generated BUILD and CROSSTOOL files
2) applying this change
3) running cuda_configure.bzl and retrieving generated BUILD and cc_toolchain_config.bzl files
4) Using [cc_toolchain_compare_test](https://github.com/bazelbuild/rules_cc/blob/master/tools/migration/ctoolchain_compare.bzl#L24) rule to verify both CROSSTOOL and cc_toolchain_configs configure the C++ toolchain identically

PiperOrigin-RevId: 248094053
  • Loading branch information
tensorflower-gardener committed May 14, 2019
1 parent 9803eba commit 7adbdf8
Show file tree
Hide file tree
Showing 7 changed files with 1,742 additions and 1,677 deletions.
49 changes: 46 additions & 3 deletions gpus/crosstool/BUILD.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# This file is expanded from a template by cuda_configure.bzl
# Update cuda_configure.bzl#verify_build_defines when adding new variables.

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

licenses(["restricted"])

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -35,7 +40,6 @@ cc_toolchain(
name = "cc-compiler-local",
all_files = "%{linker_files}",
compiler_files = ":empty",
cpu = "local",
dwp_files = ":empty",
linker_files = "%{linker_files}",
objcopy_files = ":empty",
Expand All @@ -46,32 +50,71 @@ cc_toolchain(
# regular options will be left of them.
supports_param_files = 1,
toolchain_identifier = "local_linux",
toolchain_config = ":cc-compiler-local-config",
)

cc_toolchain_config(
name = "cc-compiler-local-config",
cpu = "local",
builtin_include_directories = [%{cxx_builtin_include_directories}],
extra_no_canonical_prefixes_flags = [%{extra_no_canonical_prefixes_flags}],
host_compiler_path = "%{host_compiler_path}",
host_compiler_prefix = "%{host_compiler_prefix}",
host_compiler_warnings = [%{host_compiler_warnings}],
host_unfiltered_compile_flags = [%{unfiltered_compile_flags}],
linker_bin_path = "%{linker_bin_path}",
)

cc_toolchain(
name = "cc-compiler-darwin",
all_files = "%{linker_files}",
compiler_files = ":empty",
cpu = "darwin",
dwp_files = ":empty",
linker_files = "%{linker_files}",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_identifier = "local_darwin",
toolchain_config = ":cc-compiler-local-darwin",
)

cc_toolchain_config(
name = "cc-compiler-local-darwin",
cpu = "darwin",
builtin_include_directories = [%{cxx_builtin_include_directories}],
extra_no_canonical_prefixes_flags = [%{extra_no_canonical_prefixes_flags}],
host_compiler_path = "%{host_compiler_path}",
host_compiler_prefix = "%{host_compiler_prefix}",
host_compiler_warnings = [%{host_compiler_warnings}],
host_unfiltered_compile_flags = [%{unfiltered_compile_flags}],
linker_bin_path = "%{linker_bin_path}",
)

cc_toolchain(
name = "cc-compiler-windows",
all_files = "%{win_linker_files}",
compiler_files = ":empty",
cpu = "x64_windows",
dwp_files = ":empty",
linker_files = "%{win_linker_files}",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_identifier = "local_windows",
toolchain_config = ":cc-compiler-windows-config",
)

cc_toolchain_config(
name = "cc-compiler-windows-config",
cpu = "x64_windows",
builtin_include_directories = [%{cxx_builtin_include_directories}],
msvc_cl_path = "%{msvc_cl_path}",
msvc_env_include = "%{msvc_env_include}",
msvc_env_lib = "%{msvc_env_lib}",
msvc_env_path = "%{msvc_env_path}",
msvc_env_tmp = "%{msvc_env_tmp}",
msvc_lib_path = "%{msvc_lib_path}",
msvc_link_path = "%{msvc_link_path}",
msvc_ml_path = "%{msvc_ml_path}",
)

filegroup(
Expand Down
Loading

0 comments on commit 7adbdf8

Please sign in to comment.