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

cmd/go: compilation order of fortran files is significant #21605

Open
ctessum opened this Issue Aug 25, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@ctessum

ctessum commented Aug 25, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="{....}"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build881373539=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I would like to build a go package that includes fortran source code files, similar to https://github.com/golang/go/tree/master/misc/cgo/fortran. The important difference from this example is that the package that I would like to compile includes fortran modules, for example:

package.go // depends on code in a_subroutine.f90
a_subroutine.f90 // depends on code in b_module.f90
b_module.90 

I would expect to be able to compile this with go build.

What did you expect to see?

successful compilation.

What did you see instead?

# {...}
<command-line>:12:6:

Fatal Error: Can't open module file ‘b_module.mod’ for reading at (1): No such file or directory

I think the problem might be that the order that fortran files are fed into the compiler is significant, and the go tool does not appear to account for this.

Potential fixes for this problem:

  1. renaming all of the fortran files in the directory so that their alphabetical order is also their required compilation order. While this (usually?) works, it appears to depend on undocumented behavior.
  2. resolving the fortran dependencies and figuring out the file order within the go tool. This seems unlikely to happen.
  3. Allowing the specification of files to be compiled (and their order) a la #12953.
  4. Others?

@ianlancetaylor ianlancetaylor changed the title from cgo: compilation order of fortran files is significant to cmd/go: compilation order of fortran files is significant Aug 25, 2017

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Aug 25, 2017

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 25, 2017

The go tool is not designed to be an all-purpose build system.

@ctessum

This comment has been minimized.

ctessum commented Aug 25, 2017

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 25, 2017

Interesting question. Guaranteeing alphabetical order is not a problem, but at least for C code we would not want to guarantee that the compilations do not occur in parallel. Perhaps for Fortran we could make an exception and serialize the compilations. But that might give us some extra complexity for a very unusual use case.

@ctessum

This comment has been minimized.

ctessum commented Aug 25, 2017

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 25, 2017

The go tool effectively spawns separate processes gfortran -c a.f, gfortran -c b.f, gfortran -c c.f. Right now it does them in serial, but in the future it might start them all at the same time. That will work fine for C or C++, but, apparently, not for Fortran.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment