xref: /aosp_15_r20/external/pytorch/third_party/eigen.BUILD (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# This is BUILD file is derived from https://github.com/tensorflow/tensorflow/blob/master/third_party/eigen.BUILD
2
3# Description:
4#   Eigen is a C++ template library for linear algebra: vectors,
5#   matrices, and related algorithms.
6
7load("@rules_cc//cc:defs.bzl", "cc_library")
8
9licenses([
10    # Note: Eigen is an MPL2 library that includes GPL v3 and LGPL v2.1+ code.
11    #       We've taken special care to not reference any restricted code.
12    "reciprocal",  # MPL2
13    "notice",  # Portions BSD
14])
15
16exports_files(["COPYING.MPL2"])
17
18# License-restricted (i.e. not reciprocal or notice) files inside Eigen/...
19EIGEN_RESTRICTED_FILES = [
20    "Eigen/src/OrderingMethods/Amd.h",
21    "Eigen/src/SparseCholesky/**",
22]
23
24# Notable transitive dependencies of restricted files inside Eigen/...
25EIGEN_RESTRICTED_DEPS = [
26    "Eigen/Eigen",
27    "Eigen/IterativeLinearSolvers",
28    "Eigen/MetisSupport",
29    "Eigen/Sparse",
30    "Eigen/SparseCholesky",
31    "Eigen/SparseLU",
32]
33
34EIGEN_FILES = [
35    "Eigen/**",
36    "unsupported/Eigen/CXX11/**",
37    "unsupported/Eigen/FFT",
38    "unsupported/Eigen/KroneckerProduct",
39    "unsupported/Eigen/src/FFT/**",
40    "unsupported/Eigen/src/KroneckerProduct/**",
41    "unsupported/Eigen/MatrixFunctions",
42    "unsupported/Eigen/SpecialFunctions",
43    "unsupported/Eigen/Splines",
44    "unsupported/Eigen/src/MatrixFunctions/**",
45    "unsupported/Eigen/src/SpecialFunctions/**",
46    "unsupported/Eigen/src/Splines/**",
47    "unsupported/Eigen/NonLinearOptimization",
48    "unsupported/Eigen/NumericalDiff",
49    "unsupported/Eigen/src/**",
50    "unsupported/Eigen/Polynomials",
51]
52
53# List of files picked up by glob but actually part of another target.
54EIGEN_EXCLUDE_FILES = ["Eigen/src/Core/arch/AVX/PacketMathGoogleTest.cc"]
55
56# Disallowed eigen modules/files in rNA:
57# * Using the custom STL and memory support, it is not needed and should
58#   not be used with c++17.
59# * We will only support the EulerAnglesZYX provided by //atg/geometry so
60#   just don't allow people to access the unsupported eigen module.
61EIGEN_DISALLOW_FILES = [
62    "Eigen/StlSupport/*.h",
63    "unsupported/Eigen/EulerAngles",
64    "unsupported/Eigen/src/EulerAngles/**",
65]
66
67# Files known to be under MPL2 license.
68EIGEN_MPL2_HEADER_FILES = glob(
69    EIGEN_FILES,
70    exclude = EIGEN_EXCLUDE_FILES +
71              EIGEN_RESTRICTED_FILES +
72              EIGEN_DISALLOW_FILES +
73              EIGEN_RESTRICTED_DEPS + [
74        # Guarantees any file missed by excludes above will not compile.
75        "Eigen/src/Core/util/NonMPL2.h",
76        "Eigen/**/CMakeLists.txt",
77    ],
78)
79
80cc_library(
81    name = "eigen",
82    hdrs = EIGEN_MPL2_HEADER_FILES,
83    defines = [
84        # This define (mostly) guarantees we don't link any problematic
85        # code. We use it, but we do not rely on it, as evidenced above.
86        "EIGEN_MPL2_ONLY",
87        "EIGEN_MAX_ALIGN_BYTES=64",
88    ],
89    includes = ["."],
90    visibility = ["//visibility:public"],
91)
92