blob: 69ae570d24fa9c42a0681990778ed252aaf1df55 [file] [log] [blame]
Austin Schuh1f9aeb42015-11-12 23:34:49 -08001# TODO(austin): I bet this is wrong.
2licenses(['restricted'])
3
Austin Schuh4f857292018-02-15 23:42:04 -08004load('@//tools/build_rules:fortran.bzl', 'fortran_library')
Austin Schuh1f9aeb42015-11-12 23:34:49 -08005
6# We can't create _wrapper.so in the slycot folder, and can't move it.
7# The best way I found to do this is to modify _wrapper.pyf to instead generate
8# a _fortranwrapper.so library, and then place a _wrapper.py file in slycot/
9# which loads _fortranwrapper from the correct location. This means that I
10# don't need to modify the repository.
11genrule(
12 name = '_fortranwrapper_pyf',
13 srcs = ['slycot/src/_wrapper.pyf'],
14 outs = ['slycot/src/_fortranwrapper.pyf'],
Austin Schuh9d92e6b2017-10-17 01:19:38 -070015 cmd = 'cat $(SRCS) | sed \'s/_wrapper/_fortranwrapper/\' > $(OUTS)',
16 restricted_to = ['@//tools:k8'],
Austin Schuh1f9aeb42015-11-12 23:34:49 -080017)
18
19# Now generate the module wrapper.
20genrule(
21 name = '_fortranwrappermodule',
22 srcs = [
23 'slycot/src/analysis.pyf',
24 'slycot/src/synthesis.pyf',
25 'slycot/src/_fortranwrapper.pyf',
26 'slycot/src/math.pyf',
27 'slycot/src/transform.pyf',
28 ],
29 outs = ['_fortranwrappermodule.c'],
Austin Schuh12eae642017-10-18 10:58:45 -070030 cmd = '/usr/bin/python /usr/bin/f2py $(location :slycot/src/_fortranwrapper.pyf) --include-paths external/slycot_repo/slycot/src/ --coutput $(OUTS) && sed "s/Generation date.*/Generation date: redacted/" -i $(OUTS)',
Austin Schuh9d92e6b2017-10-17 01:19:38 -070031 restricted_to = ['@//tools:k8'],
Austin Schuh1f9aeb42015-11-12 23:34:49 -080032)
33
34# Build it.
35cc_library(
36 name = 'slycot_c',
37 srcs = [
38 ':_fortranwrappermodule',
39 ],
40 deps = [
41 ':fortran_files',
42 '@usr_repo//:python2.7_lib',
43 '@usr_repo//:python2.7_f2py',
44 ],
45 copts = [
46 '-Wno-error',
47 '-Wno-incompatible-pointer-types-discards-qualifiers',
48 '-Wno-cast-align',
49 '-Wno-unused-parameter',
50 '-Wno-missing-field-initializers',
51 '-Wno-unused-function',
52 ],
Austin Schuh9d92e6b2017-10-17 01:19:38 -070053 restricted_to = ['@//tools:k8'],
Austin Schuh1f9aeb42015-11-12 23:34:49 -080054)
55
56# Now actually build the fortran files.
57fortran_library(
58 name = 'fortran_files',
59 srcs = glob(['slycot/src/*.f']),
60)
61
62# Link it all together. Make sure it is dynamically linked since I don't know
63# how to build the fortran files in statically to a single .so yet, and I'm not
64# sure bazel does either.
65cc_binary(
66 name = '_fortranwrapper.so',
67 deps = [
68 ':fortran_files',
69 ':slycot_c',
70 ],
71 linkopts = ['-shared', '-lblas', '-llapack'],
Brian Silvermand1c19fb2016-07-07 00:10:57 -070072 linkstatic = False,
Austin Schuh9d92e6b2017-10-17 01:19:38 -070073 restricted_to = ['@//tools:k8'],
Austin Schuh1f9aeb42015-11-12 23:34:49 -080074)
75
76# Generate the _wrapper file which loads _fortranwrapper and pretends.
77genrule(
78 name = '_wrapper',
79 outs = ['slycot/_wrapper.py'],
Brian Silvermand1c19fb2016-07-07 00:10:57 -070080 cmd = 'echo "from external.slycot_repo._fortranwrapper import *" > $(OUTS)',
81 output_to_bindir = True,
Austin Schuh9d92e6b2017-10-17 01:19:38 -070082 restricted_to = ['@//tools:k8'],
Austin Schuh1f9aeb42015-11-12 23:34:49 -080083)
84
85# Now present a python library for slycot
86py_library(
87 name = 'slycot',
88 srcs = [
89 'slycot/analysis.py',
90 'slycot/examples.py',
91 'slycot/__init__.py',
92 'slycot/math.py',
93 'slycot/synthesis.py',
94 'slycot/transform.py',
95 ':_wrapper',
96 ],
97 data = [
98 ':_fortranwrapper.so',
99 ],
100 visibility = ['//visibility:public'],
Austin Schuh9d92e6b2017-10-17 01:19:38 -0700101 restricted_to = ['@//tools:k8'],
Austin Schuh1f9aeb42015-11-12 23:34:49 -0800102)