Open barracuda156 opened 1 year ago
fortran-polyroots builds OK on ARM macOS with both the latest fpm
release and trunk. Your error message seems to suggest that there is a ieee_arithmetic.mod
file dangling around somewhere that can't be read by gfortran.
Note this sometimes happens to me if the file is corrupt (i.e. because I've run CTRL+C while gfortran was building it)
@perazz I am sure it builds on some platforms, however my issue here is quite specific: is there a way to pass flags to finclude
directory of GCC to FPM in a way that will actually work. The module might not be perfect, but it does work with fortran-stdlib
, for example, and passes most of GCC’s IEEE tests. It should probably work in this, relatively light, scenario too.
OK @barracuda156 so you want to force include some gcc-12 module, but what compiler version are you using? (typing which gfortran
shoud reveal it).
Generalizing your issue, you'd want to pass special compiler flags to given sources. That could be a relatively easy extension to PR #847 I'm working on already. It needs some refactoring anyways, because fpm
does not pass any configuration to each source file.
This puts accents a bit off; I want to fix includes, which fpm
fails to pass for some reason. These should be passed automatically, and they are, when GCC controls build process. It is not that I am trying to force something which is alien to compiler :)
gcc 12.2.0 is being used with libgcc of the same version (i.e. libgcc 12.2.0 is the runtime used by the compiler).
Set-up of fpm
environment can be seen here: https://github.com/macports/macports-ports/blob/master/_resources/port1.0/group/fortran-1.0.tcl
P. S. fortran-polyroots
is not in Macports yet, since I cannot submit it as long as it is broken, but the portfile I use is typical and looks like this, for example: https://github.com/macports/macports-ports/blob/master/fortran/fortran-roots/Portfile
To that I tried to add custom flags via build.cmd-append --flag="-I/${path_to_finclude}"
.
Do you think the issue could be caused by the space at the beginning of your folder?
-I /opt/local
Another test that may be worth doing is to specify ieee_arithmetic as intrinsic:
use, intrinsic :: ieee_arithmetic
Maybe, that will force GCC search for it in the installation folder?
@perazz Unfortunately, neither removal of the space nor changing to use, intrinsic :: ieee_arithmetic
has any effect, though error differs a bit:
+ gfortran -c ././src/polyroots_module.F90 -I/opt/local/lib/gcc12/gcc/powerpc-apple-darwin10/12.2.0/finclude/ -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single -J build/gfortran_CDA1396E3D316517 -Ibuild/gfortran_CDA1396E3D316517 -o build/gfortran_CDA1396E3D316517/polyroots-fortran/src_polyroots_module.F90.o
././src/polyroots_module.F90:24:8:
use ieee_arithmetic
1
Fatal Error: Cannot read module file 'ieee_arithmetic.mod' opened at (1), because it was created by a different version of GNU Fortran
compilation terminated.
[ 50%] polyroots_module.F90 done.
././src/polyroots_module.F90:24:8:
use ieee_arithmetic
1
Fatal Error: Cannot read module file 'ieee_arithmetic.mod' opened at (1), because it was created by a different version of GNU Fortran
compilation terminated.
Which is factually wrong, it is from the same version (by design, Macports rebuilds everything from scratch). And then adding intrinsic tag:
+ gfortran -c ././src/polyroots_module.F90 -I/opt/local/lib/gcc12/gcc/powerpc-apple-darwin10/12.2.0/finclude/ -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single -J build/gfortran_CDA1396E3D316517 -Ibuild/gfortran_CDA1396E3D316517 -o build/gfortran_CDA1396E3D316517/polyroots-fortran/src_polyroots_module.F90.o
././src/polyroots_module.F90:24:21:
use, intrinsic :: ieee_arithmetic
1
Fatal Error: Can't find an intrinsic module named 'ieee_arithmetic' at (1)
compilation terminated.
[ 50%] polyroots_module.F90 done.
././src/polyroots_module.F90:24:21:
use, intrinsic :: ieee_arithmetic
1
Fatal Error: Can't find an intrinsic module named 'ieee_arithmetic' at (1)
compilation terminated.
this similar thread suggests to doublecheck that gfortran's (v 12.2.0) path is in $LD_LIBRARY_PATH
; but you're including it manually so it should be OK.
I think your gfortran
command is not wrapping gfortran-12 but is pointing to an older version. You could try add flag --version
to see what it prints
@perazz Portgroup creates a symlink to gfortran
12.2.0 in a bin dir for FMP
usage: https://github.com/macports/macports-ports/blob/b2f123027f27f80166f174ec67135a82078c65a4/_resources/port1.0/group/fortran-1.0.tcl#L40-L48
And sets path in env. (I kinda know how it is set to work, because I have written that code.)
And it is indeed symlink to correct gfortran:
36-21% /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_fortran-polyroots/fortran-polyroots/work/bin/gfortran --version
GNU Fortran (MacPorts gcc12 12.2.0_2) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Build env cannot be that fundamentally broken, since numerous FPM packages build fine it in.
Now I see - apparently PowerPC does not support gcc's ieee_arithmetic
:
Now I see - apparently PowerPC does not support gcc's
ieee_arithmetic
:
@perazz I have written it :) GCC would not build ieee_arithmetic
if it is not supported in the first place.
Not IEEE itself, it is fine as-is, the problem was in missing fpu header in gfortran
config. See two commits here with implementation for Darwin PPC: https://github.com/barracuda156/gcc-git/tree/gfortran
It does not work perfectly yet, but most of tests pass: https://github.com/iains/darwin-toolchains-start-here/discussions/40
So the GCC is built with ieee_arithmetic
support, and while something may not work correctly still, it should be detected. For example, fortran-stdlib
detects it, builds fine and passes pretty much all tests.
See how stdlib
was failing before: https://github.com/fortran-lang/stdlib/issues/690
Now it builds. Difference? CMake build systems there via FPM.
Still broken at least with some packages requiring IEEE_arithmetic module.
---> Extracting slsqp-1.4.1.tar.gz
Executing: cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_slsqp/slsqp/work" && /usr/bin/gzip -dc '/opt/local/var/macports/distfiles/slsqp/slsqp-1.4.1.tar.gz' | /usr/bin/gnutar --no-same-owner -xf -
---> Configuring slsqp
---> Building slsqp
xinstall: mkdir /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_slsqp/slsqp/work/bin
Executing: cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_slsqp/slsqp/work/slsqp-1.4.1" && /opt/local/bin/fpm install --verbose --prefix="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_slsqp/slsqp/work/opt/local" --profile="release"
+ mkdir -p build/dependencies
<INFO> BUILD_NAME: build/gfortran
<INFO> COMPILER: gfortran
<INFO> C COMPILER: gcc
<INFO> CXX COMPILER: g++
<INFO> COMPILER OPTIONS: -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single
<INFO> C COMPILER OPTIONS:
<INFO> CXX COMPILER OPTIONS:
<INFO> LINKER OPTIONS:
<INFO> INCLUDE DIRECTORIES: []
+ mkdir -p build/gfortran_63E63B2712D76620
+ mkdir -p build/gfortran_2654F75F5833692A
[ 0%] slsqp_kinds.F90
+ mkdir -p build/gfortran_2654F75F5833692A/slsqp/
+ gfortran -c ././src/slsqp_kinds.F90 -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single -fimplicit-none -Werror=implicit-interface -ffree-form -J build/gfortran_2654F75F5833692A -Ibuild/gfortran_2654F75F5833692A -o build/gfortran_2654F75F5833692A/slsqp/src_slsqp_kinds.F90.o
[ 16%] slsqp_kinds.F90 done.
[ 16%] slsqp_support.f90
+ gfortran -c ././src/slsqp_support.f90 -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single -fimplicit-none -Werror=implicit-interface -ffree-form -J build/gfortran_2654F75F5833692A -Ibuild/gfortran_2654F75F5833692A -o build/gfortran_2654F75F5833692A/slsqp/src_slsqp_support.f90.o
[ 33%] slsqp_support.f90 done.
[ 33%] bvls_module.f90
+ gfortran -c ././src/bvls_module.f90 -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single -fimplicit-none -Werror=implicit-interface -ffree-form -J build/gfortran_2654F75F5833692A -Ibuild/gfortran_2654F75F5833692A -o build/gfortran_2654F75F5833692A/slsqp/src_bvls_module.f90.o
[ 50%] bvls_module.f90 done.
[ 50%] slsqp_core.f90
+ gfortran -c ././src/slsqp_core.f90 -O3 -funroll-loops -Wimplicit-interface -fPIC -fmax-errors=1 -fcoarray=single -fimplicit-none -Werror=implicit-interface -ffree-form -J build/gfortran_2654F75F5833692A -Ibuild/gfortran_2654F75F5833692A -o build/gfortran_2654F75F5833692A/slsqp/src_slsqp_core.f90.o
././src/slsqp_core.f90:12:21:
use, intrinsic :: ieee_arithmetic, only: ieee_is_nan, ieee_value, ieee_quiet_nan
1
Fatal Error: Can't find an intrinsic module named 'ieee_arithmetic' at (1)
compilation terminated.
[ 66%] slsqp_core.f90 done.
././src/slsqp_core.f90:12:21:
use, intrinsic :: ieee_arithmetic, only: ieee_is_nan, ieee_value, ieee_quiet_nan
1
Fatal Error: Can't find an intrinsic module named 'ieee_arithmetic' at (1)
compilation terminated.
<ERROR> Compilation failed for object " src_slsqp_core.f90.o "
<ERROR> stopping due to failed compilation
STOP 1
Command failed: cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_slsqp/slsqp/work/slsqp-1.4.1" && /opt/local/bin/fpm install --verbose --prefix="/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_fortran_slsqp/slsqp/work/opt/local" --profile="release"
Exit code: 1
And yeah, this problem seems to be exclusive to FPM. Whenever I build something like that with CMake, everything just works.
@perazz It seems that the cause of the issue was rather odd: prefix/bin had an archaic symlink to gfortran-7 (don’t ask, the file dates back to 2021, apparently it was during some early attempts to build Stan), which apparently confused FPM when it searched for modules, but normally did not affect anything else. Discovered this today when tried to build a CMake port with a broken configure – it failed to pick right settings, and I was surprised to see gfortran-7 in the log. Well, it was pulled via that symlink. Killed it, everything works now with IEEE_arithmetic in FPM. At least fortran-polyroots
now builds and passes tests, reproducibly.
Wow, this is great! Congrats @barracuda156 on the fix.
Wow, this is great! Congrats @barracuda156 on the fix.
I wanna verify on another machine, and then gonna close the issue.
Yet the module is sitting there:
It also seems to work fine with non-
fpm
builds (without passing any specific flags, GCC handles it automatically).