qcscine / molassembler

Chemoinformatics toolkit with support for inorganic molecules
https://scine.ethz.ch/download/molassembler
BSD 3-Clause "New" or "Revised" License
31 stars 7 forks source link

Build fails with clang 13 on MacOS #5

Closed awvwgk closed 1 year ago

awvwgk commented 2 years ago

Compilation fails with clang 13 on MacOS. I'm aware that you don't support MacOS, however the compilation still fails which is worth reporting.

[16/135] Building CXX object src/CMakeFiles/molassembler_obj.dir/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp.o
FAILED: src/CMakeFiles/molassembler_obj.dir/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp.o 
$BUILD_PREFIX/bin/x86_64-apple-darwin13.4.0-clang++ -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DEIGEN_USE_BLAS -I$SRC_DIR/src -I$SRC_DIR/_build/src -isystem $SRC_DIR/_build -isystem $PREFIX/include/eigen3 -isystem $PREFIX -isystem $PREFIX/include/Scine -isystem /Users/runner/mambaforge/conda-bld/scine-molassembler_1657188655384 -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -fmessage-length=0 -isystem $PREFIX/include -fdebug-prefix-map=$SRC_DIR=/usr/local/src/conda/scine-molassembler-1.2.0 -fdebug-prefix-map=$PREFIX=/usr/local/src/conda-prefix -O3 -DNDEBUG -isysroot /Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wshadow -Wpedantic -fconstexpr-steps=100000000 -fconstexpr-backtrace-limit=0 -fopenmp=libomp -std=gnu++14 -MD -MT src/CMakeFiles/molassembler_obj.dir/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp.o -MF src/CMakeFiles/molassembler_obj.dir/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp.o.d -o src/CMakeFiles/molassembler_obj.dir/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp.o -c $SRC_DIR/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp
$SRC_DIR/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp:868:3: error: use of undeclared identifier 'feenableexcept'; did you mean 'feraiseexcept'?
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
  ^~~~~~~~~~~~~~
  feraiseexcept
/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/fenv.h:235:12: note: 'feraiseexcept' declared here
extern int feraiseexcept(int /* excepts */);
           ^
$SRC_DIR/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp:932:3: error: use of undeclared identifier 'fedisableexcept'; did you mean 'feraiseexcept'?
  fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
  ^~~~~~~~~~~~~~~
  feraiseexcept
/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/fenv.h:235:12: note: 'feraiseexcept' declared here
extern int feraiseexcept(int /* excepts */);
           ^
2 errors generated.

CMake configuration

-- The C compiler identification is Clang 13.0.1
-- The CXX compiler identification is Clang 13.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: $BUILD_PREFIX/bin/x86_64-apple-darwin13.4.0-clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: $BUILD_PREFIX/bin/x86_64-apple-darwin13.4.0-clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Scine::UtilsOS found locally at $PREFIX/lib/cmake/ScineUtilsOS
-- Could NOT find nauty (missing: nauty_DIR)
-- nauty found locally at nauty_DIR-NOTFOUND
-- Found nlohmann_json: $PREFIX/lib/cmake/nlohmann_json/nlohmann_jsonConfig.cmake (found version "3.10.5") 
-- Could NOT find RingDecomposerLib (missing: RingDecomposerLib_DIR)
-- RingDecomposerLib found locally at RingDecomposerLib_DIR-NOTFOUND
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Doxygen not found - Documentation for Molassembler will not be built.
-- Configuring done
-- Generating done

System info

     active environment : base
    active env location : /Users/runner/mambaforge
            shell level : 1
       user config file : /Users/runner/.condarc
 populated config files : /Users/runner/mambaforge/.condarc
          conda version : 4.12.0
    conda-build version : 3.21.9
         python version : 3.9.13.final.0
       virtual packages : __osx=10.15.7=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /Users/runner/mambaforge  (writable)
      conda av data dir : /Users/runner/mambaforge/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/runner/mambaforge/pkgs
                          /Users/runner/.conda/pkgs
       envs directories : /Users/runner/mambaforge/envs
                          /Users/runner/.conda/envs
               platform : osx-64
             user-agent : conda/4.12.0 requests/2.27.1 CPython/3.9.13 Darwin/19.6.0 OSX/10.15.7
                UID:GID : 501:20
             netrc file : None
           offline mode : False
awvwgk commented 2 years ago

The OSX build can be fixed by adding a custom fenv.h, which implements the missing floating point functionality in the OSX C-library:

/**@file src/fenv.h */
#pragma once

#include_next <fenv.h>

#if defined(__APPLE__) && defined(__MACH__)

// Public domain polyfill for feenableexcept on OS X
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c

inline int feenableexcept(unsigned int excepts)
{
    static fenv_t fenv;
    unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
    // previous masks
    unsigned int old_excepts;

    if (fegetenv(&fenv)) {
        return -1;
    }
    old_excepts = fenv.__control & FE_ALL_EXCEPT;

    // unmask
    fenv.__control &= ~new_excepts;
    fenv.__mxcsr   &= ~(new_excepts << 7);

    return fesetenv(&fenv) ? -1 : old_excepts;
}

inline int fedisableexcept(unsigned int excepts)
{
    static fenv_t fenv;
    unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
    // all previous masks
    unsigned int old_excepts;

    if (fegetenv(&fenv)) {
        return -1;
    }
    old_excepts = fenv.__control & FE_ALL_EXCEPT;

    // mask
    fenv.__control |= new_excepts;
    fenv.__mxcsr   |= new_excepts << 7;

    return fesetenv(&fenv) ? -1 : old_excepts;
}

#endif

Unfortunately, the polyfill for the floating point exceptions only works for OSX/x86_64 but not OSX/arm64

jan-grimo commented 2 years ago

Considering the floating point runtime checking was intended as a debugging tool to figure out why this routine does not work the way it should, the import to <cfenv> is best removed and the subsequent function calls too.

We're grateful to you trying out compatibility with MacOS. Are there any other compilation failures?

awvwgk commented 2 years ago

Removing the <cfenv> header should enable me to cross-compile for MacOS/arm64. Maybe this patch will work (see https://github.com/conda-forge/scine-molassembler-feedstock/pull/4)

diff --git a/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp b/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp
index 83cb413d..e7cb9196 100644
--- a/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp
+++ b/src/Molassembler/DistanceGeometry/TetrangleSmoothing.cpp
@@ -11,7 +11,6 @@
 #include "Molassembler/Temple/Invoke.h"

 #include <Eigen/Dense>
-#include <cfenv>

 namespace Scine {
 namespace Molassembler {
@@ -865,7 +864,6 @@ struct TetrangleLimits {
 };

 unsigned tetrangleSmooth(Eigen::Ref<Eigen::MatrixXd> bounds) {
-  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);

   const unsigned N = bounds.cols();

@@ -929,7 +927,6 @@ unsigned tetrangleSmooth(Eigen::Ref<Eigen::MatrixXd> bounds) {
     ++iterations;
   } while(changedSomething);

-  fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
   return iterations;
 }

Are there any other compilation failures?

I have a collection of patches as well as some custom CMake finders to get molassembler to compile and use the correct libraries. Most of those are already posted here in the issue tracker.

weymutht commented 1 year ago

This is fixed in release 2.0.0.