flang icon indicating copy to clipboard operation
flang copied to clipboard

add support for macOS

Open s-u opened this issue 7 years ago • 8 comments

This is a minimal set of code changes and additions to cmake rules to allow flang and libpgmath to build on macOS (aka Darwin).

[Tested using clang6 to build on Darwin 15.6.0 (aka OS X 10.11.6)]

s-u avatar Sep 15 '18 01:09 s-u

Simon, can you do an individual contributor license agreement for us so we can take this pull request?

NVIDIA is requiring that we do CLAs for this sort of outside contribution.

This is described in the Flang wiki here: https://github.com/flang-compiler/flang/wiki/Community

gklimowicz avatar Sep 17 '18 17:09 gklimowicz

@s-u FYI, I can't take these changes without a completed contributor license agreement. At least for about another few weeks.

If you have an update for this, please let me know.

gklimowicz avatar Oct 04 '19 20:10 gklimowicz

@s-u CLA (contributor license agreement) is not a requirement now. If you are interested in submitting this PR please rebase, else consider closing.

kiranchandramohan avatar Feb 14 '21 16:02 kiranchandramohan

@kiranchandramohan thanks, rebased and updated. I have tested the build using classic-flang-llvm-project (bootstrapped with Xcode 10.3) on macOS 10.14 (Mojave) = Darwin 18.

s-u avatar Feb 15 '21 00:02 s-u

Seems like each time I thought I was approving particular commit, it was approval for the entire PR!

pawosm-arm avatar Feb 15 '21 10:02 pawosm-arm

runtime/flangrti/CMakeLists.txt has FLANG_LIBOMP and LIBPGMATH hard-coded to libomp.so and libpgmath.so. These should be set to libomp.dylib and libpgmath.dylib on Mac. Otherwise the project doesn't compile.

dnoan avatar Mar 25 '21 18:03 dnoan

@s-u Can you address @dnoan's comment above?

Also could you let me know the build instructions you used for Mac?

kiranchandramohan avatar Apr 07 '21 14:04 kiranchandramohan

Build instruction are like in the Wiki only slightly modified - your mileage may wary depending on tools used.

BASE="`pwd`"
CMAKE=/Applications/CMake.app/Contents/bin/cmake

INSTALL_PREFIX=/opt/flang
CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
    -DLLVM_CONFIG=$INSTALL_PREFIX/bin/llvm-config \
    -DCMAKE_CXX_COMPILER=$INSTALL_PREFIX/bin/clang++ \
    -DCMAKE_C_COMPILER=$INSTALL_PREFIX/bin/clang \
    -DCMAKE_Fortran_COMPILER=$INSTALL_PREFIX/bin/flang 
    -DCMAKE_Fortran_COMPILER_ID=Flang \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_TARGETS_TO_BUILD=X86"

cd classic-flang-llvm-project
mkdir -p build && cd build
## There is a bug in that branch that uses wrong flags for xml2 so we have to disable it
$CMAKE $CMAKE_OPTIONS -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
       -DLLVM_ENABLE_CLASSIC_FLANG=ON -DLLVM_ENABLE_PROJECTS="clang;openmp;libcxx;libcxxabi" \
       -DLLVM_ENABLE_LIBXML2=OFF ../llvm
make -j12

cd "$BASE"

(cd flang/runtime/libpgmath
 mkdir -p build && cd build
 $CMAKE $CMAKE_OPTIONS ..
 make -j12
 make install)

(cd flang
 mkdir -p build && cd build
 $CMAKE $CMAKE_OPTIONS -DFLANG_LLVM_EXTENSIONS=ON \
	-DFLANG_LIBOMP=$INSTALL_PREFIX/lib/libomp.dylib -DLIBPGMATH=$INSTALL_PREFIX/lib/libpgmath.dylib ..
 make -j12
 make install)

@dnoan it says that those are undefined, so if you define them it works, no code change needed. I have now added a fix for the suffixes as well (so now you no longer need to set those).

s-u avatar Apr 11 '21 23:04 s-u