hiker / fab_new

BOM version of the flexible build system for scientific software
https://metoffice.github.io/fab/
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Improved support for flags #11

Open hiker opened 2 months ago

hiker commented 2 months ago

The new compiler class introduces a separate Flag class, in addition to the existing AddFlags and FlagsConfig.

The Flags and FlagsConfig classes should be combined into one, allowing conditional (AddFlags) and unconditional flags to be used in one object. Additionally to path-specific flags, we need to:

hiker commented 2 months ago

Suggested implementation details:

The implementation can be done in several smaller steps:

  1. Add Flags properly to compiler (atm compilation flags are provided in the compilation step - we should change this so that the flags are added to the compiler). For now do not remove the existing flags from compilation, since we need the path-specific capability (which we won't have yet).
  2. Add mode to the BuildConfig and compiler flags.
  3. Support path-specific flags. Then we can finally remove the flag parameters from the compilation steps.
  4. Support compiler version conditional flag.
hiker commented 2 months ago

Originally, it would have been feasible to implement the flags as class/static variables (meaning if you inherit from a compiler, you would also get the flags). Just to clarify, the variables should be stored in the instances (taken from the ToolRepository). This is a requirement for the upcoming proper compiler wrapper, which allows us to do:

    gcc = Gcc()
    mpicc = Mpicc(gcc)
    assert gcc.flags == []
    assert mpicc.flags == []
    # Setting flags in gcc must become visible in the wrapper compiler:
    gcc.add_flags(["-a", "-b"])
    assert gcc.flags == ["-a", "-b"]
    assert mpicc.flags == ["-a", "-b"]

Basically, a site can just take the (say) ifort compiler from the tool repository, add whatever flags it wants to add (with all the flexibility added here). But if an app then select to use mpif90 based on ifort, it will automatically get the site-specific flags. Of if a site doesn't use mpif90, but mpiifort for intel, it can just declare mpiifort based on intel, and will also get the flags.

It would also allow an application to define more than one (say) ifort compiler with different flags ... though I can't see a good use case for that :)