From 98b51ab10ec872cf5aa469ad529b0346dc01679b Mon Sep 17 00:00:00 2001 From: chrislovecnm Date: Tue, 13 Jun 2023 10:20:51 -0600 Subject: [PATCH 1/2] Fix(bzlmod): Windows Python Interpreter symlink issues When using Windows you cannot run the symlink directly. Because of how symlinks work in Windows we need to use the path realink. Unlike Linux and OSX we cannot execute the Python symlink directly. Windows throws an error "-1073741515", when we execute the symlink directory. This error means that the Python binary cannot find dlls. This is because the symlink that we create is not in the same folder as the dlls. This commit introduces code that resolves the actual location of the interpreter using the path realink when we are running bzlmod and Windows. --- python/pip_install/pip_repository.bzl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index 5239fd5f9c..7544b93d13 100644 --- a/python/pip_install/pip_repository.bzl +++ b/python/pip_install/pip_repository.bzl @@ -15,9 +15,11 @@ "" load("//python:repositories.bzl", "get_interpreter_dirname", "is_standalone_interpreter") +load("//python:versions.bzl", "WINDOWS_NAME") load("//python/pip_install:repositories.bzl", "all_requirements") load("//python/pip_install:requirements_parser.bzl", parse_requirements = "parse") load("//python/pip_install/private:srcs.bzl", "PIP_INSTALL_PY_SRCS") +load("//python/private:toolchains_repo.bzl", "get_host_os_arch") CPPFLAGS = "CPPFLAGS" @@ -72,8 +74,16 @@ def _resolve_python_interpreter(rctx): python_interpreter = _get_python_interpreter_attr(rctx) if rctx.attr.python_interpreter_target != None: - target = rctx.attr.python_interpreter_target - python_interpreter = rctx.path(target) + python_interpreter = rctx.path(rctx.attr.python_interpreter_target) + + # If we have @@ we have bzlmod so we need to hand Windows differently. + if str(Label("//:unused")).startswith("@@"): + (os, _) = get_host_os_arch(rctx) + + # If we have Windows the symlink will not work directly and we need + # to resolve the realpath. + if os == WINDOWS_NAME: + python_interpreter = python_interpreter.realpath elif "/" not in python_interpreter: found_python_interpreter = rctx.which(python_interpreter) if not found_python_interpreter: @@ -670,7 +680,6 @@ py_binary( def _whl_library_impl(rctx): python_interpreter = _resolve_python_interpreter(rctx) - args = [ python_interpreter, "-m", @@ -699,7 +708,7 @@ def _whl_library_impl(rctx): ) if result.return_code: - fail("whl_library %s failed: %s (%s)" % (rctx.attr.name, result.stdout, result.stderr)) + fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code)) return From ecfb816546747ee2dfe499d6cdf44623e8c79673 Mon Sep 17 00:00:00 2001 From: Chris Love <335402+chrislovecnm@users.noreply.github.com> Date: Tue, 13 Jun 2023 11:05:42 -0600 Subject: [PATCH 2/2] Update python/pip_install/pip_repository.bzl Making English better. Co-authored-by: Richard Levasseur --- python/pip_install/pip_repository.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index 7544b93d13..915b4705ae 100644 --- a/python/pip_install/pip_repository.bzl +++ b/python/pip_install/pip_repository.bzl @@ -80,8 +80,8 @@ def _resolve_python_interpreter(rctx): if str(Label("//:unused")).startswith("@@"): (os, _) = get_host_os_arch(rctx) - # If we have Windows the symlink will not work directly and we need - # to resolve the realpath. + # On Windows, the symlink doesn't work because Windows attempts to find + # Python DLLs where the symlink is, not where the symlink points. if os == WINDOWS_NAME: python_interpreter = python_interpreter.realpath elif "/" not in python_interpreter: