Skip to content

Make phasar buildable on Apple Silicon #802

@printerboi

Description

@printerboi

Is your feature request related to a problem? Please describe.
I think it would be nice if Phasar was compilable on Apple Silicon. I've read the wiki and acknowledged, that you currently do not support development on the aforementioned hardware, however I think the related problems are easy to fix. Currently, the build process is stuck on three mayor problems:

  1. Apple Clang vs. LLVM-15

  2. fatal error: 'stdlib.h' file not found

  3. ld: library 'stdc++fs' not found

Describe the solution you'd like

  1. This is not a problem of Phasar by itself, but as the build process does rely on LLVM-15 the wiki should mention that users are required to install the Version of LLVM using homebrew and then creating a symlink to tell the compiler where the required files are located. The following steps should cover this:
brew install llvm@15
# add this to .bashrc/.zshrc for permanent access
# execute only once for temporary persitance
export PATH="$PATH:$(brew --prefix llvm@15)/bin"
export LLVM_DIR=/opt/homebrew/opt/llvm@15/lib/cmake/llvm
  1. LLVM relies on stdlib.h, which is included in several places. However, the homebrew version is not able to find the header file, as it is provided by apple's own SDK. This can easily be fixed by executing:
# Install xcode if not already performed
xcode-select --install
# Add this to .bashrc/.zshrc for persistance
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
# Execute cmake with the variable
cmake -DCMAKE_BUILD_TYPE=Release .. -DCMAKE_OSX_SYSROOT="$SDKROOT"
  1. stdc++fs is not present in macOS on Apple Silicon. The OS supplies its own standalone std::filesystem, therefore the environment variable inside cmakelists.txt can be unset, if building on Silicon. I think the easiest fix is to check whether a file system header can be found by CMake:
# Check if the underlying toolchain has a default std filesystem header
include(CheckIncludeFileCXX)
check_include_file_cxx(filesystem HAS_FILESYSTEM_HEADER)

message(STATUS "CHECK std filesystem exists: ${HAS_STD_FILESYSTEM} ")

# Filesystem
if (LLVM_ENABLE_LIBCXX)
  # If no file system exists, link a filesystem explicitly
  if (NOT HAS_FILESYSTEM_HEADER)
    set(PHASAR_STD_FILESYSTEM c++fs)
  else()
  # Else clear the value
    unset(PHASAR_STD_FILESYSTEM)
  endif()
else()
  if (NOT HAS_FILESYSTEM_HEADER)
    set(PHASAR_STD_FILESYSTEM stdc++fs)
  else()
    unset(PHASAR_STD_FILESYSTEM)
  endif()
endif()

I think this would also fix #563

Describe alternatives you've considered
Alternatively, the support for macOS and Apple Silicon can stay as it is.

Additional context
I developed the fixes on my MacBook Pro 2024. The fixes work on my machine, further testing is necessary to ensure compatibility.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions