Skip to content

Commit 201e2d4

Browse files
fix: Make local runtime repo work for windows
In particular, this fixes two problems: First, windows requires interface libraries to be linked in. Second, windows requires an alternative search path since LIBDIR is not filled in.
1 parent 0b3d845 commit 201e2d4

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

python/private/get_local_runtime_info.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
# https://stackoverflow.com/questions/47423246/get-pythons-lib-path
3737
# For now, it seems LIBDIR has what is needed, so just use that.
3838
"LIBDIR",
39+
# A backup alternative for deriving LIBDIR in cases that LIBDIR is not available
40+
"LIBDEST",
3941
# The versioned libpythonX.Y.so.N file. Usually?
4042
# It might be a static archive (.a) file instead.
4143
"INSTSONAME",

python/private/local_runtime_repo.bzl

+9
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,22 @@ def _local_runtime_repo_impl(rctx):
112112
info["INSTSONAME"],
113113
]
114114

115+
if repo_utils.get_platforms_os_name(rctx) == 'windows':
116+
shared_lib_names.append("python{major}{minor}.lib".format(**info))
117+
shared_lib_names.append("python3.lib")
118+
119+
interpreter_path = interpreter_path.replace('\\', '/')
120+
115121
# In some cases, the value may be empty. Not clear why.
116122
shared_lib_names = [v for v in shared_lib_names if v]
117123

118124
# In some cases, the same value is returned for multiple keys. Not clear why.
119125
shared_lib_names = {v: None for v in shared_lib_names}.keys()
120126
shared_lib_dir = info["LIBDIR"]
121127

128+
if shared_lib_dir == None:
129+
shared_lib_dir = info["LIBDEST"] + "/../libs"
130+
122131
# The specific files are symlinked instead of the whole directory
123132
# because it can point to a directory that has more than just
124133
# the Python runtime shared libraries, e.g. /usr/lib, or a Python

python/private/local_runtime_repo_setup.bzl

+19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
load("@bazel_skylib//lib:selects.bzl", "selects")
1818
load("@rules_cc//cc:cc_library.bzl", "cc_library")
19+
load("@rules_cc//cc:cc_import.bzl", "cc_import")
1920
load("@rules_python//python:py_runtime.bzl", "py_runtime")
2021
load("@rules_python//python:py_runtime_pair.bzl", "py_runtime_pair")
2122
load("@rules_python//python/cc:py_cc_toolchain.bzl", "py_cc_toolchain")
@@ -58,6 +59,20 @@ def define_local_runtime_toolchain_impl(
5859
major_minor = "{}.{}".format(major, minor)
5960
major_minor_micro = "{}.{}".format(major_minor, micro)
6061

62+
version_dict = {'major': major, 'minor': minor}
63+
64+
cc_import(
65+
name = "interface",
66+
interface_library = "lib/python{major}{minor}.lib".format(**version_dict),
67+
system_provided = True,
68+
)
69+
70+
cc_import(
71+
name = "abi3_interface",
72+
interface_library = "lib/python3.lib",
73+
system_provided = True,
74+
)
75+
6176
cc_library(
6277
name = "_python_headers",
6378
# NOTE: Keep in sync with watch_tree() called in local_runtime_repo
@@ -67,6 +82,10 @@ def define_local_runtime_toolchain_impl(
6782
allow_empty = True,
6883
),
6984
includes = ["include"],
85+
deps = select({
86+
"@bazel_tools//src/conditions:windows": [":interface", ":abi3_interface"],
87+
"//conditions:default": None,
88+
}),
7089
)
7190

7291
cc_library(

0 commit comments

Comments
 (0)