From ad9ef4c7b291361d88b0344b57cec404c1f2ad06 Mon Sep 17 00:00:00 2001 From: Aadharsh Rajkumar Date: Sun, 12 Oct 2025 22:15:21 -0400 Subject: [PATCH 1/5] dependency installer for macOS, Debian/Ubuntu, and RedHat/CentOS --- scripts/install_dependencies.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/install_dependencies.sh diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh new file mode 100755 index 0000000000..18f4e8774d --- /dev/null +++ b/scripts/install_dependencies.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +echo "Installing required dependencies..." + +# Detect OS and install packages +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "Detected macOS" + brew update + brew install cmake protobuf boost python@3.10 +elif [[ -f /etc/debian_version ]]; then + echo "Detected Debian/Ubuntu" + sudo apt-get update + sudo apt-get install -y build-essential cmake protobuf-compiler libboost-all-dev python3 python3-pip +elif [[ -f /etc/redhat-release ]]; then + echo "Detected RedHat/CentOS" + sudo yum install -y epel-release + sudo yum install -y cmake3 protobuf-compiler boost-devel python3 +else + echo "Unsupported OS: $OSTYPE" + exit 1 +fi + +echo "Dependencies installed successfully." From da1dc115b20fe0d2d012ca414b105d681ff9a75b Mon Sep 17 00:00:00 2001 From: Aadharsh Rajkumar Date: Sun, 12 Oct 2025 22:30:51 -0400 Subject: [PATCH 2/5] dependency installer for macOS, Debian/Ubuntu, and RedHat/CentOS --- scripts/install_dependencies.sh | 93 ++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 8 deletions(-) mode change 100755 => 100644 scripts/install_dependencies.sh diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh old mode 100755 new mode 100644 index 18f4e8774d..f0e5002dbe --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -1,21 +1,98 @@ #!/bin/bash -set -e +# A solution for consolidating dependency installation commands for different operating systems (for macOS, Debian/Ubuntu, RedHat/CentOS) +# Allows minimal repetition in command installations in multiple CI workflow files. +# CI logs on which commands are being run. -echo "Installing required dependencies..." +# Instructions: +# 1. Run this command: chmod +x ./scripts/install_dependencies.sh +# 2. Run the installer: ./scripts/install_dependencies.sh -# Detect OS and install packages +set -euo pipefail +set -x + +OS="$(uname -s)" +echo "Installing dependencies for $OS OS" + +# macOS if [[ "$OSTYPE" == "darwin"* ]]; then - echo "Detected macOS" + # Use Homebrew for macOS package management + echo "Detected macOS." + export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" brew update - brew install cmake protobuf boost python@3.10 + + # Packages to install + declare -A packages + packages=( + ["cmake"]="cmake" + ["gcc"]="gcc" + ["python3"]="python@3.10" + ["boost"]="boost" + ["protobuf"]="protobuf" + ) + + # Install missing packages + for exe in "${!packages[@]}"; do + formula="${packages[$exe]}" + if ! command -v "$exe" >/dev/null 2>&1; then + echo "Installing $formula..." + brew install --verbose "$formula" + else + echo "$exe already installed" + fi + done + + # Verification + echo "Verifying installations..." + which cmake; cmake --version + which gcc; gcc --version + which python3; python3 --version + brew list boost || echo "boost not found" + brew list protobuf || echo "protobuf not found" + + echo "macOS dependencies installed successfully." + + +# Debian/Ubuntu elif [[ -f /etc/debian_version ]]; then echo "Detected Debian/Ubuntu" - sudo apt-get update - sudo apt-get install -y build-essential cmake protobuf-compiler libboost-all-dev python3 python3-pip + sudo apt-get update -y + + # Install all required packages (this time with openmpi and fftw) + pkgs="tar wget make cmake gcc g++ python3 python3-dev openmpi-bin libopenmpi-dev fftw3 libfftw3-dev protobuf-compiler libboost-all-dev" + sudo apt-get install -y $pkgs + + # Verification + echo "Verifying installations..." + cmake --version || echo "cmake not found" + gcc --version || echo "gcc not found" + python3 --version || echo "python3 not found" + mpirun --version || echo "mpirun not found" + ldconfig -p | grep -q libfftw3 || echo "FFTW library not found" + + echo "Linux dependencies installed successfully." + + +# RedHat/CentOS elif [[ -f /etc/redhat-release ]]; then echo "Detected RedHat/CentOS" sudo yum install -y epel-release - sudo yum install -y cmake3 protobuf-compiler boost-devel python3 + + # Install all required packages (this time with openmpi and fftw) + pkgs="tar wget make cmake3 gcc gcc-c++ python3 openmpi fftw protobuf boost-devel" + sudo yum install -y $pkgs + + # Verification + echo "Verifying installations..." + cmake3 --version || echo "cmake3 not found" + gcc --version || echo "gcc not found" + python3 --version || echo "python3 not found" + mpirun --version || echo "mpirun not found" + rpm -q fftw || echo "FFTW library not found" + + echo "RedHat/CentOS dependencies installed successfully." + + +# If Unsupported OS else echo "Unsupported OS: $OSTYPE" exit 1 From 0cd21cd7f6249fe6e11df58a4af061c07b7bb70a Mon Sep 17 00:00:00 2001 From: Aadharsh Rajkumar Date: Sat, 18 Oct 2025 20:20:44 -0400 Subject: [PATCH 3/5] Add dependency installation script and integrate into CI workflow - scripts/install_dependencies.sh: installs required dependencies on CI - .github/workflows/test.yml: updated workflow to call the install_dependencies.sh script - CMakeLists.txt: added dependency check/integration for CI --- .github/workflows/test.yml | 42 +++------- CMakeLists.txt | 9 +++ scripts/install_dependencies.sh | 138 ++++++++++++++++++++++---------- 3 files changed, 116 insertions(+), 73 deletions(-) mode change 100644 => 100755 scripts/install_dependencies.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 503f691ec6..c660bb3336 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,39 +48,21 @@ jobs: - name: Clone uses: actions/checkout@v4 - - name: Set up Python 3.13 - uses: actions/setup-python@v5 - with: - python-version: '3.13' - - - name: Setup MacOS - if: matrix.os == 'macos' - run: | - brew update - brew upgrade - brew install coreutils python fftw hdf5 gcc@15 boost open-mpi lapack - echo "FC=gfortran-15" >> $GITHUB_ENV - echo "BOOST_INCLUDE=/opt/homebrew/include/" >> $GITHUB_ENV - - - name: Setup Ubuntu - if: matrix.os == 'ubuntu' && matrix.intel == false + - name: Install Dependencies (Unified Script) run: | - sudo apt update -y - sudo apt install -y cmake gcc g++ python3 python3-dev hdf5-tools \ - libfftw3-dev libhdf5-dev openmpi-bin libopenmpi-dev \ - libblas-dev liblapack-dev + chmod +x ./scripts/install_dependencies.sh + ./scripts/install_dependencies.sh - - name: Setup Ubuntu (Intel) - if: matrix.os == 'ubuntu' && matrix.intel == true + - name: Verify dependency installation run: | - wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB - sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB - sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" - sudo apt-get update - sudo apt-get install -y intel-oneapi-compiler-fortran intel-oneapi-mpi intel-oneapi-mpi-devel - source /opt/intel/oneapi/setvars.sh - printenv >> $GITHUB_ENV + cmake --version + gcc --version + python3 --version + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' - name: Build run: | @@ -135,4 +117,4 @@ jobs: if: matrix.lbl == 'frontier' with: name: logs-${{ strategy.job-index }}-${{ matrix.device }} - path: test-${{ matrix.device }}.out + path: test-${{ matrix.device }}.out \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b6970ad9f..6470ddfcff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -715,3 +715,12 @@ site_name(SITE_NAME) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/cmake/configuration.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/configuration.txt") + +# ------------------------- +# Small dependency-check executable (used by CI to verify deps like Boost) +find_package(Boost REQUIRED) +add_executable(dependency_check examples/dependency_check/dependency_check.cpp) +# make sure compiler sees Boost headers +target_include_directories(dependency_check PRIVATE ${Boost_INCLUDE_DIRS}) +# don't force any link libraries: we use Boost header macros only +# ------------------------- diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh old mode 100644 new mode 100755 index f0e5002dbe..b1f015cec7 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -8,78 +8,130 @@ # 2. Run the installer: ./scripts/install_dependencies.sh set -euo pipefail -set -x +set -x +export DEBIAN_FRONTEND=noninteractive OS="$(uname -s)" echo "Installing dependencies for $OS OS" +if command -v sudo >/dev/null 2>&1; then + SUDO="sudo" +else + SUDO="" +fi + +# macOS +# if [[ "$OSTYPE" == "darwin"* ]]; then +# # Use Homebrew for macOS package management +# echo "Detected macOS." +# export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" +# brew update + +# # Packages to install +# declare -A packages +# packages=( +# ["cmake"]="cmake" +# ["gcc"]="gcc" +# ["python3"]="python@3.10" +# ["boost"]="boost" +# ["protobuf"]="protobuf" +# ) + +# # Install missing packages +# for exe in "${!packages[@]}"; do +# formula="${packages[$exe]}" +# if ! command -v "$exe" >/dev/null 2>&1; then +# echo "Installing $formula..." +# brew install --verbose "$formula" +# else +# echo "$exe already installed" +# fi +# done + +# # Verification +# echo "Verifying installations..." +# which cmake; cmake --version +# which gcc; gcc --version +# which python3; python3 --version +# brew list boost || echo "boost not found" +# brew list protobuf || echo "protobuf not found" + +# echo "macOS dependencies installed successfully." # macOS if [[ "$OSTYPE" == "darwin"* ]]; then - # Use Homebrew for macOS package management echo "Detected macOS." export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" brew update + brew upgrade || true + + # Install required packages (mirrors workflow setup) + pkgs=(coreutils python fftw hdf5 gcc@15 boost open-mpi lapack cmake protobuf) - # Packages to install - declare -A packages - packages=( - ["cmake"]="cmake" - ["gcc"]="gcc" - ["python3"]="python@3.10" - ["boost"]="boost" - ["protobuf"]="protobuf" - ) - - # Install missing packages - for exe in "${!packages[@]}"; do - formula="${packages[$exe]}" - if ! command -v "$exe" >/dev/null 2>&1; then - echo "Installing $formula..." - brew install --verbose "$formula" + for pkg in "${pkgs[@]}"; do + if ! brew list "$pkg" >/dev/null 2>&1; then + echo "Installing $pkg..." + brew install "$pkg" || brew reinstall "$pkg" else - echo "$exe already installed" + echo "$pkg already installed." fi done - # Verification - echo "Verifying installations..." - which cmake; cmake --version - which gcc; gcc --version - which python3; python3 --version - brew list boost || echo "boost not found" - brew list protobuf || echo "protobuf not found" + # Fix potential linking issues for Homebrew-installed libraries + brew link --overwrite python || true + brew link --overwrite boost || true + brew link --overwrite hdf5 || true + brew link --overwrite cmake || true + brew link --overwrite protobuf || true - echo "macOS dependencies installed successfully." + # Environment setup + echo "FC=gfortran-15" >> "$GITHUB_ENV" + echo "BOOST_INCLUDE=/opt/homebrew/include/" >> "$GITHUB_ENV" + echo "macOS dependencies installed successfully." # Debian/Ubuntu elif [[ -f /etc/debian_version ]]; then echo "Detected Debian/Ubuntu" - sudo apt-get update -y # Install all required packages (this time with openmpi and fftw) - pkgs="tar wget make cmake gcc g++ python3 python3-dev openmpi-bin libopenmpi-dev fftw3 libfftw3-dev protobuf-compiler libboost-all-dev" - sudo apt-get install -y $pkgs - - # Verification - echo "Verifying installations..." - cmake --version || echo "cmake not found" - gcc --version || echo "gcc not found" - python3 --version || echo "python3 not found" - mpirun --version || echo "mpirun not found" - ldconfig -p | grep -q libfftw3 || echo "FFTW library not found" - - echo "Linux dependencies installed successfully." - + if [[ "${CI_INTEL:-false}" == "true" ]]; then + echo "Intel OneAPI environment detected. Installing Intel compilers and MPI..." + wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + $SUDO apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + $SUDO add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" + $SUDO apt-get update + $SUDO apt-get install -y intel-oneapi-compiler-fortran intel-oneapi-mpi intel-oneapi-mpi-devel + source /opt/intel/oneapi/setvars.sh + if [[ -n "${GITHUB_ENV:-}" ]]; then + echo "source /opt/intel/oneapi/setvars.sh" >> "$GITHUB_ENV" + fi + printenv >> "$GITHUB_ENV" + echo "Intel OneAPI installation completed." + else + echo "Standard GNU environment detected. Installing open-source toolchain..." + $SUDO apt-get update -y + pkgs="tar wget make cmake gcc g++ python3 python3-dev openmpi-bin libopenmpi-dev fftw3 libfftw3-dev protobuf-compiler libboost-all-dev" + $SUDO apt-get install -y $pkgs + + # Verification + echo "Verifying installations..." + cmake --version || echo "cmake not found" + gcc --version || echo "gcc not found" + python3 --version || echo "python3 not found" + mpirun --version || echo "mpirun not found" + ldconfig -p | grep -q libfftw3 || echo "FFTW library not found" + + echo "Linux (GNU) dependencies installed successfully." + fi # RedHat/CentOS elif [[ -f /etc/redhat-release ]]; then echo "Detected RedHat/CentOS" - sudo yum install -y epel-release + $SUDO yum install -y epel-release # Install all required packages (this time with openmpi and fftw) pkgs="tar wget make cmake3 gcc gcc-c++ python3 openmpi fftw protobuf boost-devel" - sudo yum install -y $pkgs + $SUDO yum install -y $pkgs # Verification echo "Verifying installations..." From aa497c871134b4fbddeebda455ee7cc9da2f657e Mon Sep 17 00:00:00 2001 From: Aadharsh Rajkumar Date: Sat, 18 Oct 2025 21:15:30 -0700 Subject: [PATCH 4/5] Add .gitattributes to enforce LF line endings --- .gitattributes | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index 442e4b4321..0d579138c4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ -/tests/**/* linguist-generated=true -/toolchain/mechanisms/* linguist-generated=true +*.fpp text eol=lf +*.f90 text eol=lf +*.sh text eol=lf +/tests/**/* linguist-generated=true +/toolchain/mechanisms/* linguist-generated=true From a09cb0ece2788a1cc3488344a55f37f14152099a Mon Sep 17 00:00:00 2001 From: Aadharsh Rajkumar Date: Mon, 27 Oct 2025 16:39:01 -0400 Subject: [PATCH 5/5] undid past commit, added boost compile check and secure OneAPI keys, and added suggested fixes for dependency installer --- .github/workflows/test.yml | 19 ++- CMakeLists.txt | 6 +- scripts/install_dependencies.sh | 287 +++++++++++++++++++------------- 3 files changed, 183 insertions(+), 129 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c660bb3336..1e008162f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,10 +48,16 @@ jobs: - name: Clone uses: actions/checkout@v4 - - name: Install Dependencies (Unified Script) - run: | - chmod +x ./scripts/install_dependencies.sh - ./scripts/install_dependencies.sh + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Make dependency installer executable + run: chmod +x ./scripts/install_dependencies.sh + + - name: Run dependency installer + run: ./scripts/install_dependencies.sh - name: Verify dependency installation run: | @@ -59,11 +65,6 @@ jobs: gcc --version python3 --version - - name: Set up Python 3.13 - uses: actions/setup-python@v5 - with: - python-version: '3.13' - - name: Build run: | /bin/bash mfc.sh test --dry-run -j $(nproc) --${{ matrix.debug }} --${{ matrix.mpi }} --${{ matrix.precision }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 6470ddfcff..892651a265 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") $<$:-fprofile-arcs> $<$:-ftest-coverage> $<$:-O1> - ) + ) add_link_options( $<$:-lgcov> @@ -148,7 +148,7 @@ if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") -Wunderflow -Wrealloc-lhs -Wsurprising - ) + ) endif() if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 10) @@ -195,7 +195,7 @@ elseif ((CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_Fortran_COMPILER_ add_compile_options( $<$:-Mfreeform> $<$:-cpp> - $<$:-Minfo=inline> + $<$:-Minfo=inline> $<$:-Minfo=accel> ) diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index b1f015cec7..d5d2ca596a 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -7,147 +7,200 @@ # 1. Run this command: chmod +x ./scripts/install_dependencies.sh # 2. Run the installer: ./scripts/install_dependencies.sh -set -euo pipefail +set -euo pipefail set -x -export DEBIAN_FRONTEND=noninteractive - -OS="$(uname -s)" -echo "Installing dependencies for $OS OS" - -if command -v sudo >/dev/null 2>&1; then - SUDO="sudo" -else - SUDO="" -fi - -# macOS -# if [[ "$OSTYPE" == "darwin"* ]]; then -# # Use Homebrew for macOS package management -# echo "Detected macOS." -# export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" -# brew update - -# # Packages to install -# declare -A packages -# packages=( -# ["cmake"]="cmake" -# ["gcc"]="gcc" -# ["python3"]="python@3.10" -# ["boost"]="boost" -# ["protobuf"]="protobuf" -# ) - -# # Install missing packages -# for exe in "${!packages[@]}"; do -# formula="${packages[$exe]}" -# if ! command -v "$exe" >/dev/null 2>&1; then -# echo "Installing $formula..." -# brew install --verbose "$formula" -# else -# echo "$exe already installed" -# fi -# done - -# # Verification -# echo "Verifying installations..." -# which cmake; cmake --version -# which gcc; gcc --version -# which python3; python3 --version -# brew list boost || echo "boost not found" -# brew list protobuf || echo "protobuf not found" - -# echo "macOS dependencies installed successfully." -# macOS -if [[ "$OSTYPE" == "darwin"* ]]; then - echo "Detected macOS." + +SUDO=${SUDO:-sudo} +CI_INTEL=${CI_INTEL:-false} + +log() { echo ">>> $*"; } + +# Guarded append to GITHUB_ENV (safe when running locally) +append_to_github_env() { + local line="$1" + if [[ -n "${GITHUB_ENV:-}" ]]; then + printf '%s\n' "$line" >> "$GITHUB_ENV" + else + printf '%s\n' "$line" + fi +} + +verify_tool() { + local t="$1" + if command -v "$t" >/dev/null 2>&1; then + "$t" --version 2>&1 | head -n1 || true + else + echo "$t not found" + fi +} + +# macOS / Homebrew +install_macos() { + log "Detected macOS" + + if ! command -v brew >/dev/null 2>&1; then + log "Homebrew not found. Please install Homebrew first." + return 1 + fi + export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" brew update brew upgrade || true - # Install required packages (mirrors workflow setup) pkgs=(coreutils python fftw hdf5 gcc@15 boost open-mpi lapack cmake protobuf) for pkg in "${pkgs[@]}"; do - if ! brew list "$pkg" >/dev/null 2>&1; then - echo "Installing $pkg..." - brew install "$pkg" || brew reinstall "$pkg" + # Use brew list to detect installed formulae (correct for lib-only formulae) + if ! brew list --formula | grep -q "^${pkg%%@*}$"; then + log "Installing ${pkg}..." + brew install "${pkg}" || brew reinstall "${pkg}" || log "Failed to install ${pkg} (continuing)" else - echo "$pkg already installed." + log "${pkg} already installed" fi done - # Fix potential linking issues for Homebrew-installed libraries + # Attempt to fix common Homebrew linking quirks brew link --overwrite python || true brew link --overwrite boost || true brew link --overwrite hdf5 || true brew link --overwrite cmake || true brew link --overwrite protobuf || true - # Environment setup - echo "FC=gfortran-15" >> "$GITHUB_ENV" - echo "BOOST_INCLUDE=/opt/homebrew/include/" >> "$GITHUB_ENV" - - echo "macOS dependencies installed successfully." - -# Debian/Ubuntu -elif [[ -f /etc/debian_version ]]; then - echo "Detected Debian/Ubuntu" - - # Install all required packages (this time with openmpi and fftw) - if [[ "${CI_INTEL:-false}" == "true" ]]; then - echo "Intel OneAPI environment detected. Installing Intel compilers and MPI..." - wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB - $SUDO apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB - $SUDO add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" - $SUDO apt-get update - $SUDO apt-get install -y intel-oneapi-compiler-fortran intel-oneapi-mpi intel-oneapi-mpi-devel - source /opt/intel/oneapi/setvars.sh - if [[ -n "${GITHUB_ENV:-}" ]]; then - echo "source /opt/intel/oneapi/setvars.sh" >> "$GITHUB_ENV" - fi - printenv >> "$GITHUB_ENV" - echo "Intel OneAPI installation completed." + # Export useful environment vars in GH Actions only (guarded) + append_to_github_env "FC=gfortran-15" + append_to_github_env "BOOST_INCLUDE=/opt/homebrew/include/" + + log "Verifying installations..." + # Use guarded verification so script doesn't exit on set -e for these checks + if ! verify_tool cmake >/dev/null 2>&1; then echo "cmake not found"; fi + if ! verify_tool gcc >/dev/null 2>&1; then echo "gcc not found"; fi + if ! verify_tool gfortran >/dev/null 2>&1; then echo "gfortran not found"; fi + if ! verify_tool python3 >/dev/null 2>&1; then echo "python3 not found"; fi + if ! verify_tool mpirun >/dev/null 2>&1; then echo "mpirun not found"; fi + + if brew list --formula | grep -q "^fftw$"; then + echo "FFTW library found" else - echo "Standard GNU environment detected. Installing open-source toolchain..." - $SUDO apt-get update -y - pkgs="tar wget make cmake gcc g++ python3 python3-dev openmpi-bin libopenmpi-dev fftw3 libfftw3-dev protobuf-compiler libboost-all-dev" - $SUDO apt-get install -y $pkgs - - # Verification - echo "Verifying installations..." - cmake --version || echo "cmake not found" - gcc --version || echo "gcc not found" - python3 --version || echo "python3 not found" - mpirun --version || echo "mpirun not found" - ldconfig -p | grep -q libfftw3 || echo "FFTW library not found" - - echo "Linux (GNU) dependencies installed successfully." + echo "FFTW library not found" fi -# RedHat/CentOS -elif [[ -f /etc/redhat-release ]]; then - echo "Detected RedHat/CentOS" - $SUDO yum install -y epel-release + log "macOS dependencies installed successfully." +} - # Install all required packages (this time with openmpi and fftw) - pkgs="tar wget make cmake3 gcc gcc-c++ python3 openmpi fftw protobuf boost-devel" - $SUDO yum install -y $pkgs +# Debian / Ubuntu +install_debian() { + log "Detected Debian/Ubuntu" - # Verification - echo "Verifying installations..." - cmake3 --version || echo "cmake3 not found" - gcc --version || echo "gcc not found" - python3 --version || echo "python3 not found" - mpirun --version || echo "mpirun not found" - rpm -q fftw || echo "FFTW library not found" + $SUDO apt-get update -y + $SUDO apt-get install -y build-essential wget tar cmake python3 python3-dev pkg-config - echo "RedHat/CentOS dependencies installed successfully." + if [[ "${CI_INTEL}" == "true" ]]; then + log "Intel OneAPI: adding repo with signed-by keyring (secure method)" + # download key and install to /etc/apt/keyrings (modern secure approach) + wget -q https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB -O /tmp/intel-pubkey.PUB + $SUDO mkdir -p /etc/apt/keyrings + $SUDO install -m 0644 /tmp/intel-pubkey.PUB /etc/apt/keyrings/intel-archive-keyring.gpg + echo "deb [signed-by=/etc/apt/keyrings/intel-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | $SUDO tee /etc/apt/sources.list.d/oneapi.list > /dev/null + $SUDO apt-get update -y + $SUDO apt-get install -y intel-oneapi-compiler-fortran intel-oneapi-mpi intel-oneapi-mpi-devel || log "Intel packages failed; continuing" + + # capture environment changes made by Intel setvars.sh and append only deltas to GITHUB_ENV + if [[ -f /opt/intel/oneapi/setvars.sh ]]; then + env > /tmp/env_before + source /opt/intel/oneapi/setvars.sh || log "sourcing Intel setvars.sh failed" + if [[ -n "${GITHUB_ENV:-}" ]]; then + # append only newly added / changed env vars + diff --unchanged-line-format="" --old-line-format="" --new-line-format="%L" <(sort /tmp/env_before) <(env | sort) >> "$GITHUB_ENV" || true + fi + rm -f /tmp/env_before + fi + fi + # Install common dev packages including fftw/openmpi/protobuf/boost + $SUDO apt-get install -y libfftw3-dev libopenmpi-dev openmpi-bin libprotobuf-dev protobuf-compiler libboost-all-dev + + log "Verifying installations..." + if ! verify_tool cmake >/dev/null 2>&1; then echo "cmake not found"; fi + if ! verify_tool gfortran >/dev/null 2>&1; then echo "gfortran not found"; fi + if ! verify_tool python3 >/dev/null 2>&1; then echo "python3 not found"; fi + if ! verify_tool mpirun >/dev/null 2>&1; then echo "mpirun not found"; fi + if ! ldconfig -p | grep -q libfftw3; then echo "FFTW library not found"; fi +} + +# RHEL / CentOS +install_rhel() { + log "Detected RHEL/CentOS" + + pkgs="tar wget make cmake3 gcc gcc-c++ python3-devel openmpi openmpi-devel fftw fftw-devel protobuf protobuf-devel boost-devel" + $SUDO yum install -y $pkgs || $SUDO dnf install -y $pkgs || log "yum/dnf install failed" + + log "Verifying installations..." + if command -v cmake3 >/dev/null 2>&1; then + verify_tool cmake3 + elif command -v cmake >/dev/null 2>&1; then + verify_tool cmake + else + echo "cmake not found" + fi -# If Unsupported OS -else - echo "Unsupported OS: $OSTYPE" - exit 1 -fi + if ! verify_tool gfortran >/dev/null 2>&1; then echo "gfortran not found"; fi + if ! verify_tool python3 >/dev/null 2>&1; then echo "python3 not found"; fi + if ! verify_tool mpirun >/dev/null 2>&1; then echo "mpirun not found"; fi + if ! ldconfig -p | grep -q libfftw3; then echo "FFTW library not found"; fi +} + +# Boost compile check +boost_check() { + log "Verifying Boost by compiling a tiny program..." + cat <<'EOF' > /tmp/boost_check.cpp +#include +#include +int main(){ std::cout << "Boost version: " << BOOST_LIB_VERSION << std::endl; return 0;} +EOF + + # Try pkg-config first (if available) + if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists boost; then + g++ /tmp/boost_check.cpp -o /tmp/boost_check $(pkg-config --cflags --libs boost) || true + else + # Try a plain compile (system include path), fallback to /opt/homebrew/include + if g++ /tmp/boost_check.cpp -o /tmp/boost_check 2>/dev/null; then + true + else + if [[ -d /opt/homebrew/include ]]; then + g++ -I/opt/homebrew/include /tmp/boost_check.cpp -o /tmp/boost_check || true + else + log "Could not compile boost_check; boost include path unknown" + fi + fi + fi -echo "Dependencies installed successfully." + if [[ -x /tmp/boost_check ]]; then + /tmp/boost_check || true + else + log "boost_check binary not available" + fi +} + +# Main entry +main() { + case "$(uname -s)" in + Darwin) + install_macos + ;; + *) + if [[ -f /etc/debian_version ]]; then + install_debian + elif [[ -f /etc/redhat-release ]] || [[ -f /etc/centos-release ]]; then + install_rhel + else + log "Unsupported OS: $OSTYPE" + return 1 + fi + ;; + esac + + boost_check + log "Done." +} + +main "$@" \ No newline at end of file