Skip to content

Commit 610a540

Browse files
committed
wip: make gen_implib a rule
1 parent 82871c9 commit 610a540

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
)
18+
19+
return [DefaultInfo(
20+
files = depset(ctx.outputs.outs),
21+
)]
22+
23+
gen_implib = rule(
24+
implementation = _impl,
25+
attrs = {
26+
"src": attr.label(allow_single_file = True, mandatory = True),
27+
"tool": attr.label(
28+
mandatory = True,
29+
executable = True,
30+
cfg = "target",
31+
),
32+
"dlopen_callback": attr.string(mandatory = True),
33+
"outs": attr.output_list(mandatory = True),
34+
},
35+
toolchains = ["@rules_python//python/cc:toolchain_type"]
36+
)

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("@drake//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+
dlopen_callback = "drake_dlopen_mosek",
88+
tool = "@implib_so_internal//:gen",
8889
)
8990

9091
cc_library(

0 commit comments

Comments
 (0)