Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to improve Fortran compiler finding for Windows/Mac Slicer extension build #55

Closed
sjh26 opened this issue Apr 23, 2020 · 11 comments
Closed
Assignees

Comments

@sjh26
Copy link
Contributor

sjh26 commented Apr 23, 2020

The current method used on the Slicer factory machine to find the Fortran compiler needs some work.

This line:
https://github.com/Slicer/DashboardScripts/blob/af76712f7afd0e82f489f3f29ff64fd8569afb3f/overload-vs2015-slicerextensions_preview_nightly.cmake#L55

should set the environment variable, but this doesn't seem to be picked up by the extension build

@sjh26
Copy link
Contributor Author

sjh26 commented Apr 28, 2020

This error seems to also be on the mac build:

http://slicer.cdash.org/viewBuildError.php?buildid=1896073

It has a similar fortran environment variable set in the extensions driver script.

Perhaps we can just set the environment variables on the system for those two machines? That would allow these to build while we sort out the rest.

@sjh26 sjh26 changed the title Need to improve Fortran compiler finding for Windows Slicer extension build Need to improve Fortran compiler finding for Windows/Mac Slicer extension build Apr 30, 2020
@jcfr
Copy link
Contributor

jcfr commented Sep 9, 2020

Looking into this, the compiler is found as expected:

From http://slicer.cdash.org/buildSummary.php?buildid=2009360:

[...]
-- Looking up any Fortran compiler
-- Looking up any Fortran compiler - /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran (value of FC environment variable)
-- Extracting compiler identifier for /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran
-- Extracting compiler identifier for /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran - GNU
-- Retrieving GNU Fortran compiler implicit link info
-- Retrieving GNU Fortran compiler implicit link info - done
-- Fortran_GNU_IMPLICIT_LINK_LIBRARIES=gfortran;gcc_ext.10.5;gcc;quadmath;m
-- Fortran_GNU_IMPLICIT_LINK_DIRECTORIES=/Volumes/D/Support/miniconda3/envs/gfortran-env/lib/gcc/x86_64-apple-darwin13.4.0/7.3.0;/Volumes/D/Support/miniconda3/envs/gfortran-env/lib;/usr/local/lib;/usr/lib
-- Fortran_GNU_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES=/Library/Frameworks;/System/Library/Frameworks
-- Fortran_GNU_RUNTIME_LIBRARIES=/Volumes/D/Support/miniconda3/envs/gfortran-env/lib/libgfortran.dylib;/Volumes/D/Support/miniconda3/envs/gfortran-env/lib/libquadmath.dylib;/usr/lib/libm.dylib
-- Fortran_GNU_RUNTIME_DIRECTORIES=/Volumes/D/Support/miniconda3/envs/gfortran-env/lib;/usr/lib
-- Found Fortran: GNU
[...]

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Using the CMake option --trace-expand, I narrowed down the problem to this command:

/Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran  -E /Volumes/D/Support/CMake-3.15.1.app/Contents/share/cmake-3.15/Modules/CMakeTestGNU.c
gfortran: error trying to exec 'cc1': execvp: No such file or directory

Context:

/Volumes/D/Support/CMake-3.15.1.app/Contents/share/cmake-3.15/Modules/CMakeDetermineFortranCompiler.cmake(218): 
execute_process(
  COMMAND /Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran  
    -E /Volumes/D/Support/CMake-3.15.1.app/Contents/share/cmake-3.15/Modules/CMakeTestGNU.c
  OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT
  RESULT_VARIABLE CMAKE_COMPILER_RETURN
  )

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Seems to be related to AnacondaRecipes/aggregate#112

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Running the following command also report an error

/Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran --help -v

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Since the issue is missing cc1 executable, I tried the following without success:

echo "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -cc1 \"\$@\"" > /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc1

chmod u+x /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc1

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH

then

/Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran --help -v
Using built-in specs.
COLLECT_GCC=/Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran
COLLECT_LTO_WRAPPER=/Volumes/D/Support/miniconda3/envs/gfortran-env/libexec/gcc/x86_64-apple-darwin13.4.0/7.5.0/lto-wrapper
Usage: gfortran [options] file...
Options:
  -pass-exit-codes         Exit with highest error code from a phase.
  --help                   Display this information.
  --target-help            Display target specific command line options.
  --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].
                           Display specific types of command line options.
  --version                Display compiler version information.
  -dumpspecs               Display all of the built in spec strings.
  -dumpversion             Display the version of the compiler.
  -dumpmachine             Display the compiler's target processor.
  -print-search-dirs       Display the directories in the compiler's search path.
  -print-libgcc-file-name  Display the name of the compiler's companion library.
  -print-file-name=<lib>   Display the full path to library <lib>.
  -print-prog-name=<prog>  Display the full path to compiler component <prog>.
  -print-multiarch         Display the target's normalized GNU triplet, used as
                           a component in the library path.
  -print-multi-directory   Display the root directory for versions of libgcc.
  -print-multi-lib         Display the mapping between command line options and
                           multiple library search directories.
  -print-multi-os-directory Display the relative path to OS libraries.
  -print-sysroot           Display the target libraries directory.
  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.
  -Wa,<options>            Pass comma-separated <options> on to the assembler.
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor.
  -Wl,<options>            Pass comma-separated <options> on to the linker.
  -Xassembler <arg>        Pass <arg> on to the assembler.
  -Xpreprocessor <arg>     Pass <arg> on to the preprocessor.
  -Xlinker <arg>           Pass <arg> on to the linker.
  -save-temps              Do not delete intermediate files.
  -save-temps=<arg>        Do not delete intermediate files.
  -no-canonical-prefixes   Do not canonicalize paths when building relative
                           prefixes to other gcc components.
  -pipe                    Use pipes rather than intermediate files.
  -time                    Time the execution of each subprocess.
  -specs=<file>            Override built-in specs with the contents of <file>.
  -std=<standard>          Assume that the input sources are for <standard>.
  --sysroot=<directory>    Use <directory> as the root directory for headers
                           and libraries.
  -B <directory>           Add <directory> to the compiler's search paths.
  -v                       Display the programs invoked by the compiler.
  -###                     Like -v but options quoted and commands not executed.
  -E                       Preprocess only; do not compile, assemble or link.
  -S                       Compile only; do not assemble or link.
  -c                       Compile and assemble, but do not link.
  -o <file>                Place the output into <file>.
  -pie                     Create a position independent executable.
  -shared                  Create a shared library.
  -x <language>            Specify the language of the following input files.
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension.

Options starting with -g, -f, -m, -O, -W, or --param are automatically
 passed on to the various sub-processes invoked by gfortran.  In order to pass
 other options on to these processes the -W<letter> options must be used.

Target: x86_64-apple-darwin13.4.0
Configured with: ../configure --prefix=/Volumes/D/Support/miniconda3/envs/gfortran-env --with-libiconv-prefix=/Volumes/D/Support/miniconda3/envs/gfortran-env --enable-languages=c,fortran --with-tune=generic --disable-multilib --enable-checking=release --disable-bootstrap --build=x86_64-apple-darwin13.4.0 --target=x86_64-apple-darwin13.4.0 --with-gmp=/Volumes/D/Support/miniconda3/envs/gfortran-env --with-mpfr=/Volumes/D/Support/miniconda3/envs/gfortran-env --with-mpc=/Volumes/D/Support/miniconda3/envs/gfortran-env --with-isl=/Volumes/D/Support/miniconda3/envs/gfortran-env
Thread model: posix
gcc version 7.5.0 (GCC) 
COLLECT_GCC_OPTIONS='--help' '-v' '-mmacosx-version-min=10.13.7' '-asm_macosx_version_min=10.13' '-mtune=generic'

 cc1 -quiet -v -D__DYNAMIC__ help-dummy -fPIC -quiet -dumpbase help-dummy -mmacosx-version-min=10.13.7 -mtune=generic -auxbase help-dummy -version --help -o /var/folders/6y/zp9dkw5d5wg35y8qvn29hpww0000gn/T//cc3OdVrh.s
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
error: unknown argument: '-quiet'
error: unknown argument: '-fPIC'
error: unknown argument: '-quiet'
error: unknown argument: '-dumpbase'
error: unknown argument: '-mmacosx-version-min=10.13.7'
error: unknown argument: '-mtune=generic'
error: unknown argument: '-auxbase'

For bug reporting instructions, please see:
<https://gcc.gnu.org/bugs/>

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Using cc1 script referenced above allows the command to complete:

/Volumes/D/Support/miniconda3/envs/gfortran-env/bin/gfortran  -E /Volumes/D/Support/CMake-3.15.1.app/Contents/share/cmake-3.15/Modules/CMakeTestGNU.c
# 1 "/Volumes/D/Support/CMake-3.15.1.app/Contents/share/cmake-3.15/Modules/CMakeTestGNU.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 352 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/Volumes/D/Support/CMake-3.15.1.app/Contents/share/cmake-3.15/Modules/CMakeTestGNU.c" 2

void THIS_IS_GNU();

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Problem solved using the following scripts also referenced from https://www.slicer.org/wiki/Documentation/Nightly/Developers/Fortran#macOS

#
# 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

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

macOS package for SPHARM-PDM is now available:

image

@jcfr
Copy link
Contributor

jcfr commented Sep 10, 2020

Since packages for both macOS and Windows are now available, I am closing this issue.

QA of the generated packages may reveal other issues but these should be tracked in separate issues.

cc: @bpaniagua @allemangD

@jcfr jcfr closed this as completed Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants