[R-SIG-Mac] Flang

Simon Urbanek @|mon@urb@nek @end|ng |rom R-project@org
Sat Feb 20 02:11:11 CET 2021


This message is for very advanced/curios expert users only!

Flang is a Fortran compiler based on clang/llvm which has been mostly donated by nVidia. It has existed on Linux for a while, but with some patching can be made to work on macOS as well. For quite some time I have a PR https://github.com/flang-compiler/flang/pull/592 which adds macOS support to the upstream sources. Since there was some activity recently, I decided to update it to the latest flang and to test it. It is now capable of building R (macOS x86_64 build) which passes all checks (that was not the case before) so I have created a binary of the compiler (since it's quite a beast to build) at
https://github.com/s-u/flang-macos/releases/tag/fixed-b23418
in case those very adventurous decide to play wit it. It lives in /opt/flang and should work on macOS Catalina or higher.
In order to build R I had to add 'LDFLAGS=-L/opt/flang/lib -lpgmath -lflang -lflangrti -lomp' when using this compiler since R cannot figure out the correct flags for mixing flang and clang yet.

Note: there is a namespace collision regarding the name "flang" since the flang I refer to (https://github.com/flang-compiler/flang) is what was originally called flang, but now there is f18 which is an attempt to re-write Fortran support in clang/llvm from scratch and recently they decided to rename it from f18 to flang, to cause complete confusion. f18 is part of the mainstream llvm sources, but is nowhere close to be usable (it cannot generate code yet) so is unrelated to what I'm talking about here.

Cheers,
Simon

PS: if we have any compiler geeks here - the sources suggest that nVidia has also added arm64 sources of the libpgmath runtime library aimed at Windows. It would be interesting to see if those could be made work to support aarch64 (Apple silicon) - in theory it should work. My initial attempts failed as I could not get them to compile, but if someone had more spare time on their hands may be more successful...



More information about the R-SIG-Mac mailing list