Skip to content

Commit 5c93277

Browse files
committed
wip: make gen_implib a rule
Note: This does **not** resolve the rules_python host error when building wheels on Linux, but seems like a good starting point? And, improves readability + consistency with other Drake build rules w.r.t. genrule's makefile semantics.
1 parent 82871c9 commit 5c93277

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
_PY_CC_TOOLCHAIN_TYPE = "@rules_python//python/cc:toolchain_type"
2+
3+
def _impl(ctx):
4+
args = ctx.actions.args()
5+
args.add("--dlopen-callback", ctx.attr.dlopen_callback)
6+
args.add("--outdir", ctx.outputs.outs[0].dirname)
7+
args.add(ctx.file.src.path)
8+
9+
py_toolchain = ctx.toolchains[_PY_CC_TOOLCHAIN_TYPE]
10+
11+
ctx.actions.run(
12+
mnemonic = "GenImplib",
13+
executable = ctx.executable.tool,
14+
arguments = [args],
15+
inputs = [ctx.file.src],
16+
outputs = ctx.outputs.outs,
17+
tools = [
18+
ctx.executable.tool,
19+
py_toolchain.py3_runtime.files,
20+
]
21+
)
22+
23+
return [DefaultInfo(
24+
files = depset(ctx.outputs.outs),
25+
)]
26+
27+
gen_implib = rule(
28+
implementation = _impl,
29+
attrs = {
30+
"src": attr.label(allow_single_file = True, mandatory = True),
31+
"tool": attr.label(
32+
mandatory = True,
33+
executable = True,
34+
cfg = "target",
35+
),
36+
"dlopen_callback": attr.string(mandatory = True),
37+
"outs": attr.output_list(mandatory = True),
38+
},
39+
toolchains = ["@rules_python//python/cc:toolchain_type"]
40+
)

tools/workspace/mosek/package.BUILD.bazel

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
44
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
55
load("@drake//tools/install:install.bzl", "install", "install_files")
66
load("@drake//tools/skylark:cc.bzl", "cc_import", "cc_library")
7+
load("//tools/workspace/mosek:gen_implib.bzl", "gen_implib")
78

89
package(default_visibility = ["//visibility:private"])
910

@@ -79,12 +80,12 @@ _IMPLIB_SRCS = [
7980
"{}.init.c".format(_MOSEK_SO_NAME),
8081
]
8182

82-
genrule(
83+
gen_implib(
8384
name = "_gen_implib",
84-
srcs = [_MOSEK_MAJMIN_GLOB[0]],
85+
src = _MOSEK_MAJMIN_GLOB[0],
8586
outs = _IMPLIB_SRCS,
86-
cmd = "$(execpath @implib_so_internal//:gen) --dlopen-callback=drake_dlopen_mosek --outdir=$(RULEDIR) $<",
87-
tools = ["@implib_so_internal//:gen"],
87+
drake_dlopen_mosek = "drake_dlopen_mosek",
88+
tool = "@implib_so_internal//:gen",
8889
)
8990

9091
cc_library(

0 commit comments

Comments
 (0)