forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpy.bzl
64 lines (52 loc) · 1.6 KB
/
numpy.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- mode: python -*-
# vi: set ft=python :
"""
Finds local system NumPy headers and makes them available to be used as a
C/C++ dependency.
Example:
WORKSPACE:
load("//tools:numpy.bzl", "numpy_repository")
numpy_repository(
name = "foo",
python_version = "2.7",
)
BUILD:
cc_library(
name = "foobar",
deps = ["@foo//:numpy"],
srcs = ["bar.cc"],
)
Arguments:
name: A unique name for this rule.
python_version: The version of Python for which NumPy headers are to be
found.
"""
def _impl(repository_ctx):
python = repository_ctx.which("python{}".format(
repository_ctx.attr.python_version))
if not python:
fail("Could NOT find python{}".format(repository_ctx.attr.version))
result = repository_ctx.execute([
python,
"-c",
"from __future__ import print_function; import numpy; print(numpy.get_include());",
])
if result.return_code != 0:
fail("Could NOT determine NumPy include", attr=result.stderr)
source = repository_ctx.path(result.stdout.strip())
destination = repository_ctx.path("include")
repository_ctx.symlink(source, destination)
file_content = """
cc_library(
name = "numpy",
hdrs = glob(["include/**"]),
includes = ["include"],
visibility = ["//visibility:public"],
)
"""
repository_ctx.file("BUILD", content=file_content, executable=False)
numpy_repository = repository_rule(
_impl,
attrs = {"python_version": attr.string(default = "2.7")},
local = True,
)