fix Windows build with latest rules_rust

the extra .lib file that is being output for .dll files was tripping
up the copy; we need to select only the .dll file
This commit is contained in:
Damien Elmes 2021-12-20 18:59:55 +10:00
parent 4f64494573
commit 0c7a9be359
2 changed files with 41 additions and 19 deletions

View File

@ -2,6 +2,7 @@ load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement") load("@py_deps//:requirements.bzl", "requirement")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//lib:selects.bzl", "selects") load("@bazel_skylib//lib:selects.bzl", "selects")
load(":python_lib.bzl", "copy_python_lib")
py_binary( py_binary(
name = "genbackend", name = "genbackend",
@ -44,26 +45,9 @@ genrule(
], ],
) )
copy_file( copy_python_lib(
name = "rsbridge_unix",
src = "//pylib/rsbridge",
out = "rsbridge.so",
)
copy_file(
name = "rsbridge_win",
src = "//pylib/rsbridge",
out = "rsbridge.pyd",
)
alias(
name = "rsbridge", name = "rsbridge",
actual = selects.with_or({ src = "//pylib/rsbridge",
(
"@rules_rust//rust/platform:x86_64-pc-windows-msvc",
): ":rsbridge_win",
"//conditions:default": ":rsbridge_unix",
}),
) )
_py_srcs = [ _py_srcs = [

View File

@ -0,0 +1,38 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
def _copy_python_lib_impl(ctx):
desired_file = None
target_name = ctx.label.name
if ctx.attr.is_windows:
target_name += ".pyd"
for file in ctx.files.src:
if file.extension == "dll":
desired_file = file
break
else:
target_name += ".so"
desired_file = ctx.files.src[0]
file = ctx.actions.declare_file(target_name)
ctx.actions.symlink(output = file, target_file = desired_file)
return [DefaultInfo(files = depset([file]))]
_copy_python_lib = rule(
implementation = _copy_python_lib_impl,
attrs = {
"src": attr.label(),
"is_windows": attr.bool(mandatory = True),
},
)
def copy_python_lib(name, src):
"Copy a dynamic library, renaming it to the extension Python expects."
_copy_python_lib(
name = name,
src = src,
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
)