Skip to content

Commit ccb2059

Browse files
authored
Add additional_dlls parameter to local_runtime_repo_setup
1 parent b063c2c commit ccb2059

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

bazel/repo_rules/local_runtime_repo_setup.bzl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# See https://github.com/bazel-contrib/rules_python/pull/3148
1818
"""Setup code called by the code generated by `local_runtime_repo`."""
1919

20+
load("@bazel_skylib//lib:paths.bzl", "paths")
2021
load("@bazel_skylib//lib:selects.bzl", "selects")
2122
load("@rules_cc//cc:cc_import.bzl", "cc_import")
2223
load("@rules_cc//cc:cc_library.bzl", "cc_library")
@@ -39,7 +40,8 @@ def define_local_runtime_toolchain_impl(
3940
interface_library,
4041
libraries,
4142
abi3_interface_library,
42-
abi3_libraries):
43+
abi3_libraries,
44+
additional_dlls):
4345
"""Defines a toolchain implementation for a local Python runtime.
4446
4547
Generates public targets:
@@ -70,6 +72,8 @@ def define_local_runtime_toolchain_impl(
7072
e.g. "lib/python3.lib"
7173
abi3_libraries: `list[str]` Path[s] to the python libraries.
7274
e.g. ["lib/python3.dll"] or ["lib/python3.so"]
75+
additional_dlls: `list[str]` Path[s] to additional DLLs.
76+
e.g. ["lib/python3.dll"] or ["lib/python3.so"]
7377
"""
7478
major_minor = "{}.{}".format(major, minor)
7579
major_minor_micro = "{}.{}".format(major_minor, micro)
@@ -94,6 +98,15 @@ def define_local_runtime_toolchain_impl(
9498
)
9599
abi3_deps.append(":abi3_interface")
96100

101+
for dll in additional_dlls:
102+
name = paths.basename(dll).replace(".", "_")
103+
cc_import(
104+
name = name,
105+
shared_library = dll,
106+
)
107+
libraries.append(":" + name)
108+
abi3_libraries.append(":" + name)
109+
97110
native.filegroup(
98111
name = "includes",
99112
srcs = native.glob(
@@ -124,7 +137,7 @@ def define_local_runtime_toolchain_impl(
124137
)
125138

126139
cc_library(
127-
name = "libpython{}".format(major_minor),
140+
name = "libpython{}{}".format(major, minor),
128141
hdrs = [":includes"],
129142
srcs = libraries,
130143
)
@@ -159,7 +172,7 @@ def define_local_runtime_toolchain_impl(
159172
name = "py_cc_toolchain",
160173
headers = ":python_headers",
161174
# headers_abi3 = ":python_headers_abi3",
162-
libs = ":libpython{}".format(major_minor),
175+
libs = ":libpython{}{}".format(major, minor),
163176
python_version = major_minor_micro,
164177
visibility = ["//visibility:public"],
165178
)

0 commit comments

Comments
 (0)