Skip to content

Commit

Permalink
flang: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 committed Sep 28, 2024
1 parent 926ebb3 commit 83f49e1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 11 deletions.
20 changes: 10 additions & 10 deletions packages/flang/0003-fix-missing-CHECK_MSG-macro.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
diff -uNr a/flang/lib/Evaluate/constant.cpp b/flang/lib/Evaluate/constant.cpp
--- a/flang/lib/Evaluate/constant.cpp
+++ b/flang/lib/Evaluate/constant.cpp
@@ -10,6 +10,7 @@
#include "flang/Evaluate/expression.h"
#include "flang/Evaluate/shape.h"
#include "flang/Evaluate/type.h"
+#include "flang/Common/idioms.h"
#include <string>
--- a/flang/include/flang/Common/idioms.h
+++ b/flang/include/flang/Common/idioms.h
@@ -89,6 +89,8 @@
#define CHECK(x) ((x) || (DIE("CHECK(" #x ") failed"), false))
// Same as above, but with a custom error message.
#define CHECK_MSG(x, y) ((x) || (DIE("CHECK(" #x ") failed: " #y), false))
+#elif !defined(CHECK_MSG)
+#define CHECK_MSG(x, y) CHECK(x)
#endif

namespace Fortran::evaluate {
// User-defined type traits that default to false:
11 changes: 11 additions & 0 deletions packages/flang/0004-do-not-call-timespec_get.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang/runtime/time-intrinsic.cpp
@@ -139,7 +139,7 @@
}
}

-#ifndef _AIX
+#if !defined(_AIX) && !(defined(__ANDROID__) && __ANDROID__ < 29)
// This is the fallback implementation, which should work everywhere.
template <typename Unused = void>
count_t GetSystemClockCount(int kind, fallback_implementation) {
26 changes: 26 additions & 0 deletions packages/flang/0005-use-libandroid-complex-math.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/flang/runtime/Float128Math/complex-math.h
+++ b/flang/runtime/Float128Math/complex-math.h
@@ -34,6 +34,23 @@
#elif LDBL_MANT_DIG == 113
/* Use 'long double' versions of libm functions. */
#include <complex.h>
+#if defined(__ANDROID__) && __ANDROID_API__ < 26
+long double complex cacosl (long double complex);
+long double complex cacoshl(long double complex);
+long double complex casinl (long double complex);
+long double complex casinhl(long double complex);
+long double complex catanl (long double complex);
+long double complex catanhl(long double complex);
+long double complex ccosl (long double complex);
+long double complex ccoshl (long double complex);
+long double complex cexpl (long double complex);
+long double complex clogl (long double complex);
+long double complex cpowl (long double complex, long double complex);
+long double complex csinl (long double complex);
+long double complex csinhl (long double complex);
+long double complex ctanl (long double complex);
+long double complex ctanhl (long double complex);
+#endif

#define CAbs(x) cabsl(x)
#define CAcos(x) cacosl(x)
26 changes: 26 additions & 0 deletions packages/flang/0006-dummy-bessel-functions-for-long-double.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/flang/runtime/Float128Math/math-entries.h
+++ b/flang/runtime/Float128Math/math-entries.h
@@ -185,9 +185,11 @@
DEFINE_SIMPLE_ALIAS(Ilogb, std::ilogb)
DEFINE_SIMPLE_ALIAS(Isinf, std::isinf)
DEFINE_SIMPLE_ALIAS(Isnan, std::isnan)
+#ifndef __ANDROID__
DEFINE_SIMPLE_ALIAS(J0, j0l)
DEFINE_SIMPLE_ALIAS(J1, j1l)
DEFINE_SIMPLE_ALIAS(Jn, jnl)
+#endif
DEFINE_SIMPLE_ALIAS(Ldexp, std::ldexp)
DEFINE_SIMPLE_ALIAS(Lgamma, std::lgamma)
DEFINE_SIMPLE_ALIAS(Llround, std::llround)
@@ -204,9 +206,11 @@
DEFINE_SIMPLE_ALIAS(Tanh, std::tanh)
DEFINE_SIMPLE_ALIAS(Tgamma, std::tgamma)
DEFINE_SIMPLE_ALIAS(Trunc, std::trunc)
+#ifndef __ANDROID__
DEFINE_SIMPLE_ALIAS(Y0, y0l)
DEFINE_SIMPLE_ALIAS(Y1, y1l)
DEFINE_SIMPLE_ALIAS(Yn, ynl)
+#endif

// Use numeric_limits to produce infinity of the right type.
#define F128_RT_INFINITY \
2 changes: 1 addition & 1 deletion packages/flang/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TERMUX_PKG_HOSTBUILD=true
# `flang-new` should be rebuilt when libllvm bumps version.
# See https://github.com/termux/termux-packages/issues/19362
DEP_QUALIFIER=$TERMUX_PKG_VERSION-$TERMUX_PKG_REVISION
TERMUX_PKG_DEPENDS="libc++, libllvm (= $DEP_QUALIFIER), clang (= $DEP_QUALIFIER), lld (= $DEP_QUALIFIER), mlir (= $DEP_QUALIFIER)"
TERMUX_PKG_DEPENDS="libandroid-complex-math-static, libc++, libllvm (= $DEP_QUALIFIER), clang (= $DEP_QUALIFIER), lld (= $DEP_QUALIFIER), mlir (= $DEP_QUALIFIER)"
TERMUX_PKG_BUILD_DEPENDS="libllvm-static"

# Upstream doesn't support 32-bit arches well. See https://github.com/llvm/llvm-project/issues/57621.
Expand Down
12 changes: 12 additions & 0 deletions packages/libllvm/clang-lib-Driver-ToolChains-CommonArgs.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1281,6 +1281,9 @@
if (AsNeeded)
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
}
+ if (TC.getTriple().isAndroid()) {
+ CmdArgs.push_back("-l:libandroid-complex-math.a");
+ }
CmdArgs.push_back("-lFortranRuntime");
CmdArgs.push_back("-lFortranDecimal");
}

0 comments on commit 83f49e1

Please sign in to comment.