Add a Bazel-built slicot via f2c
Previously, we were using the host binaries along with slycot, which
didn't support using it at runtime.
We built slicot itself using f2c, and then the normal Bazel C/C++
infrastructure on the resulting C code.
We're also using clapack, which is lapack and BLAS pre-run through f2c
along with various fixups.
The build is horribly noisy and full of warnings and information
messages, but oh well.
Change-Id: If13056ff56d334b7207cd9f0f7c0ce22b999b78e
diff --git a/tools/build_rules/fortran.bzl b/tools/build_rules/fortran.bzl
index e1f2abf..e8b25c1 100644
--- a/tools/build_rules/fortran.bzl
+++ b/tools/build_rules/fortran.bzl
@@ -1,3 +1,5 @@
+load('@//tools/build_rules:select.bzl', 'compiler_select')
+
def _single_fortran_object_impl(ctx):
toolchain_cflags = (ctx.fragments.cpp.compiler_options([]) +
ctx.fragments.cpp.c_options +
@@ -91,3 +93,60 @@
visibility = visibility,
restricted_to = ['@//tools:k8'],
)
+
+f2c_copts = compiler_select({
+ 'clang': [
+ '-Wno-incompatible-pointer-types-discards-qualifiers',
+ # Clang appears to be a bit over-eager about this and the comma operator.
+ '-Wno-sometimes-uninitialized',
+ ],
+ 'gcc': [
+ # TODO(Brian): Remove this once we can actually disable all the warnings.
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43245 isn't fixed in our
+ # roborio toolchain yet, so we can't for now.
+ '-Wno-error',
+ ],
+}) + [
+ # f2c appears to know what it's doing without adding extra ().
+ '-Wno-parentheses',
+
+ '-Wno-unused-parameter',
+ '-Wno-missing-field-initializers',
+ '-Wno-unused-variable',
+]
+'''Copts to use when compiling f2c-generated files.
+
+This is useful when building externally-f2ced files.'''
+
+def f2c_library(name, srcs, copts = [], **kwargs):
+ '''Converts Fortran code to C and then compiles it.
+
+ Attrs:
+ srcs: .f source files
+ **kwargs: passed to native.cc_library
+ '''
+ c_srcs = [f[:-2] + '.c' for f in srcs]
+
+ out_dir = c_srcs[0].split('/')[:-1]
+ for c_src in c_srcs:
+ if c_src.split('/')[:-1] != out_dir:
+ # Need to figure out how to make multiple f2c calls or something to
+ # support this, and we haven't had a use case yet.
+ fail('Multiple output directories not supported', 'srcs')
+
+ native.genrule(
+ name = '_%s_f2c' % name,
+ visibility = ['//visibility:private'],
+ srcs = srcs,
+ outs = c_srcs,
+ tools = [
+ '@f2c',
+ ],
+ cmd = '$(location @f2c) -d$(@D)/%s $(SRCS)' % ('/'.join(out_dir),),
+ )
+ native.cc_library(
+ name = name,
+ srcs = c_srcs,
+ copts = f2c_copts + copts,
+ **kwargs
+ )
diff --git a/tools/build_rules/select.bzl b/tools/build_rules/select.bzl
index 151283f..994e775 100644
--- a/tools/build_rules/select.bzl
+++ b/tools/build_rules/select.bzl
@@ -68,6 +68,6 @@
if 'clang' not in values:
fail('Need to handle clang!', 'values')
return select({
- '//tools:compiler_gcc': values['gcc'],
- '//tools:compiler_clang': values['clang'],
+ '@//tools:compiler_gcc': values['gcc'],
+ '@//tools:compiler_clang': values['clang'],
})