Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel fails to build jaxlib: While resolving toolchains for target @org_tensorflow//tensorflow/tools/git:gen_git_source: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. #13227

Closed
yurivict opened this issue Mar 16, 2021 · 6 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug

Comments

@yurivict
Copy link

Analyzing: target //build:build_wheel (1 packages loaded, 0 targets configured)
DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1556410077 -0400"
DEBUG: Repository io_bazel_rules_docker instantiated at:
  /usr/ports/math/py-jax/jax/WORKSPACE:34:10: in <toplevel>
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace0.bzl:105:34: in workspace
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/bazel_toolchains/repositories/repositories.bzl:37:23: in repositories
Repository rule git_repository defined at:
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/bazel_tools/tools/build_defs/repo/git.bzl:199:33: in <toplevel>
Analyzing: target //build:build_wheel (14 packages loaded, 13 targets configured)
Analyzing: target //build:build_wheel (14 packages loaded, 13 targets configured)
Analyzing: target //build:build_wheel (14 packages loaded, 13 targets configured)
Analyzing: target //build:build_wheel (139 packages loaded, 3068 targets configured)
INFO: Repository llvm-project instantiated at:
  /usr/ports/math/py-jax/jax/WORKSPACE:30:10: in <toplevel>
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace2.bzl:1083:21: in workspace
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace2.bzl:632:9: in _tf_repositories
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/llvm/workspace.bzl:10:20: in repo
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/repo.bzl:112:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/repo.bzl:65:35: in <toplevel>
INFO: Repository boringssl instantiated at:
  /usr/ports/math/py-jax/jax/WORKSPACE:30:10: in <toplevel>
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace2.bzl:1083:21: in workspace
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace2.bzl:670:20: in _tf_repositories
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/repo.bzl:112:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/repo.bzl:65:35: in <toplevel>
INFO: Repository double_conversion instantiated at:
  /usr/ports/math/py-jax/jax/WORKSPACE:30:10: in <toplevel>
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace2.bzl:1083:21: in workspace
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/tensorflow/workspace2.bzl:844:20: in _tf_repositories
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/repo.bzl:112:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /usr/home/yuri/.cache/bazel/_bazel_yuri/324920dd194a60c357dae36bcca2577c/external/org_tensorflow/third_party/repo.bzl:65:35: in <toplevel>
ERROR: While resolving toolchains for target @org_tensorflow//tensorflow/tools/git:gen_git_source: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//build:build_wheel' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
INFO: Elapsed time: 59.817s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (141 packages loaded, 3079 targets configured)
ERROR: Build failed. Not running target
FAILED: Build did NOT complete successfully (141 packages loaded, 3079 targets configured)
Traceback (most recent call last):
  File "build/build.py", line 521, in <module>
    main()
  File "build/build.py", line 516, in main
    shell(command)
  File "build/build.py", line 51, in shell
    output = subprocess.check_output(cmd)
  File "/usr/local/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/usr/local/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/usr/local/bin/bazel', 'run', '--verbose_failures=true', '--config=short_logs', '--config=mkl_open_source_only', ':build_wheel', '--', '--output_path=/usr/ports/math/py-jax/jax/dist']' returned non-zero exit status 1.

Compiler: clang-10
OS: FreeBSD 12.2

See the original bug report here: jax-ml/jax#6076

@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug labels Mar 24, 2021
@oquenchil
Copy link
Contributor

@katre Is this the problem you fixed recently?

@katre
Copy link
Member

katre commented Mar 24, 2021

What version of Bazel is this?

@yurivict: You can provide more debugging information by re-running the Bazel invocation with the flag --toolchain_resolution_debug=@bazel_tools//tools/cpp:toolchain_type with Bazel built from HEAD. With an older Bazel, the flag is --toolchain_resolution_debug (with no argument) and produces much more data. In either case, please save the output as a log and attach it to this issue.

@oquenchil: I suspect the problem here is that we don't have a CC toolchain for FreeBSD, and so toolchain resolution is failing. Toolchain resolution is run for CC rules even if the result isn't used, and so if a toolchain isn't present this error would be the result.

Options:

  1. @yurivict can define a CC toolchain, possibly based on the auto-configured one in tools/cpp. Starting with the C++ toolchain tutorial and the C++ toolchain reference would be good starts.
  2. We can re-add a dummy toolchain that matches as a last resort for any build. We had this previously, but it caused different errors since it wasn't a real toolchain and so, if it was selected, it would cause build errors.
  3. I've kicked around the idea of optional toolchains, which would solve this for CC rules as they could then continue using legacy toolchains if the incompatible flag isn't flipped. This isn't a simple task and isn't currently prioritized.

@yurivict: Unfortunately, our FreeBSD support isn't in great shape. We do have some support, but the engineer who added it has since left the team and we don't have any FreeBSD testing, so I am not surprised that the code is not working. We need a volunteer who is knowledgeable about FreeBSD and can run tests, since this is not something we are currently supporting.

@jxy
Copy link

jxy commented Jul 15, 2022

This issue is caused by Tensorflow overwriting the platform as linux, tensorflow/tensorflow#56725. I manually patched up that file tensorflow/third_party/remote_config/remote_platform_configure.bzl, with the additional lines

         elif os.startswith("freebsd"):
             platform = "freebsd"

In addition, we need to patch bazelrc to pick up --config=posix,

diff --git a/.bazelrc b/.bazelrc
index da136a8d7..9e1ef1250 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -106,6 +106,8 @@ build:linux --copt=-Wno-array-parameter
 
 build:macos --config=posix
 
+build:freebsd --config=posix
+
 # Suppress all warning messages.
 build:short_logs --output_filter=DONT_MATCH_ANYTHING
 

and use the actual platform tag to build the wheel, because platform.system() is not enough for the tag,

diff --git a/build/build_wheel.py b/build/build_wheel.py
index cb85e2c67..12cd63072 100644
--- a/build/build_wheel.py
+++ b/build/build_wheel.py
@@ -19,6 +19,7 @@
 
 import argparse
 import datetime
+import distutils
 import functools
 import glob
 import os
@@ -274,17 +275,9 @@ def edit_jaxlib_version(sources_path):
 
 def build_wheel(sources_path, output_path, cpu):
   """Builds a wheel in `output_path` using the source tree in `sources_path`."""
-  platform_name, cpu_name = {
-    ("Linux", "x86_64"): ("manylinux2014", "x86_64"),
-    ("Linux", "aarch64"): ("manylinux2014", "aarch64"),
-    ("Linux", "ppc64le"): ("manylinux2014", "ppc64le"),
-    ("Darwin", "x86_64"): ("macosx_10_14", "x86_64"),
-    ("Darwin", "arm64"): ("macosx_11_0", "arm64"),
-    ("Windows", "AMD64"): ("win", "amd64"),
-  }[(platform.system(), cpu)]
   python_tag_arg = (f"--python-tag=cp{sys.version_info.major}"
                     f"{sys.version_info.minor}")
-  platform_tag_arg = f"--plat-name={platform_name}_{cpu_name}"
+  platform_tag_arg = f"--plat-name={distutils.util.get_platform()}"
   cwd = os.getcwd()
   if os.environ.get('JAXLIB_NIGHTLY'):
     edit_jaxlib_version(sources_path)

After these, compile for cpu works.

@hawkinsp
Copy link

@jxy if you want to send PRs to JAX and to TensorFlow with those fixes and tag me, I'll review/approve them.

The second patch to JAX can't be checked in as is: in particular, for JAX we support cross-compilation (and we rely on that for Mac ARM builds) so the CPU of the running Python interpreter may not match the target CPU.

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Oct 18, 2023
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please post @bazelbuild/triage in a comment here and we'll take a look. Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

5 participants