forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfortran.bzl
39 lines (34 loc) · 1.36 KB
/
gfortran.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
# -*- python -*-
# This is a Bazel repository_rule for libgfortran. See
# https://www.bazel.io/versions/master/docs/skylark/repository_rules.html
def _find_and_symlink(repository_ctx, lib_name):
gfortran = repository_ctx.which("gfortran")
result = repository_ctx.execute([gfortran,
"--print-file-name=" + lib_name])
if result.return_code != 0:
print(result.return_code, result.stdout, result.stderr)
fail("gfortran.bzl: Could not --print-file-name=" + lib_name + ". " +
"Is gfortran installed?")
path = result.stdout.strip()
if path:
repository_ctx.symlink(path, lib_name)
else:
fail("gfortran.bzl: Found gfortran but not " + lib_name + ". Yikes!")
def _gfortran_impl(repository_ctx):
"""Locate libgfortran.a and libquadmath.a. Wrap them in a cc_library."""
_find_and_symlink(repository_ctx, "libgfortran.a")
_find_and_symlink(repository_ctx, "libquadmath.a")
BUILD = """
cc_library(
name = "lib",
srcs = ["libgfortran.a", "libquadmath.a"],
hdrs = [],
linkopts = ["-ldl"],
visibility = ["//visibility:public"],
)
""".replace("\n ", "\n") # Strip leading indentation.
repository_ctx.file("BUILD", content=BUILD)
gfortran_repository = repository_rule(
local = True,
implementation = _gfortran_impl,
)