Documentation/Nightly/Developers/Fortran

From Slicer Wiki
Revision as of 15:52, 10 September 2020 by JChris.FillionR (talk | contribs) (→‎macOS)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Home < Documentation < Nightly < Developers < Fortran

Linux

Install a fortran compiler with the package manager, like gfortran.

macOS

- Install Miniconda - See https://conda.io/miniconda.html

 ./Miniconda3-latest-MacOSX-x86_64.sh -p /Volumes/D/Support/miniconda3/
 Do you wish the installer to prepend the Miniconda3 install location
 Answered NO

- To activate of base env.

 source /Volumes/D/Support/miniconda3/bin/activate

- Add conda-forge

 conda config --add channels conda-forge

-Then create gfortran-env and install gfortran

 conda create -n gfortran-env
 conda activate gfortran-env
 conda install gfortran_osx-64

- Create cc1 wrapper script to workaround issue https://github.com/NIRALUser/SPHARM-PDM/issues/55:

#
# Create gfortran wrapper script to ensure cc1
#

fake_bin_dir="fake-bin-to-workaround-cc1-issue"

if [[ ! -f /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran-real ]]; then
  mv /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran-real
fi

cat << EOF > /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran
#!/usr/bin/env bash

script_dir=\$(cd \$(dirname \$0) || exit 1; pwd)

export PATH=\$script_dir/../$fake_bin_dir/:\$PATH

\$script_dir/gfortran-real "\$@"
EOF

chmod u+x /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran

#
# Create cc1 wrapper script into "fake-bin" directory
#
mkdir -p /Volumes/D/Support/miniconda3/envs/gfortran-env/$fake_bin_dir

cat << EOF > /Volumes/D/Support/miniconda3/envs/gfortran-env/$fake_bin_dir/cc1
#!/usr/bin/env bash

# See https://github.com/NIRALUser/SPHARM-PDM/issues/55
# Script adapted from https://github.com/conda-forge/ambertools-feedstock/blob/04e4327e6a3cffdfda36158755ffe00c565fe08c/recipe/fake-bin/cc1

script_dir=\$(cd \$(dirname \$0) || exit 1; pwd)

ARGS=()
for var in "\$@"; do
    # Ignore known bad arguments
    [ "\$var" != '-quiet' ] && ARGS+=("\$var")
done

\$script_dir/../bin/clang "\${ARGS[@]}"
EOF

chmod u+x /Volumes/D/Support/miniconda3/envs/gfortran-env/$fake_bin_dir/cc1

- update @rpath from gfortran libraries

Before packaging, we have to fix the installed gfortran libraries with the following script: fix_gfortran_lib_rpath.sh.

The script substitutes @rpath with the needed full paths. Requires atool and install_name_tool.

cd /tmp

curl -L# https://gist.githubusercontent.com/phcerdan/146de9398052335d8a76c5b0070715a6/raw/e698a724a22c09055f75f7f221c8a3f1f59c5488/fix_gfortran_lib_rpaths.sh -o fix_gfortran_lib_rpaths.sh

chmod u+x /tmp/fix_gfortran_lib_rpaths.sh

/tmp/fix_gfortran_lib_rpaths.sh /Volumes/D/Support/miniconda3/envs/gfortran-env/lib

Windows

- Install Miniconda - See https://scikit-ci-addons.readthedocs.io/en/latest/addons.html#install-miniconda3-4-5-4-ps1

- Install Flang, a fortran compiler targeting llvm: scikit-ci-addons