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

Linker improvements to transparently handle site-specific paths #7

Open hiker opened 3 months ago

hiker commented 3 months ago

In order to better support different paths on different sites:

hiker commented 2 weeks ago

Looking at the PR, we had a misunderstanding - we need these flags as part of the linker (site- and compiler-specific), not the link step (which should be as independent from site/compiler as possible).

Here what I want to do when setting up a linker:

    gfortran = tr.get_tool(Category.LINKER, "linker-gfortran")
    gfortran.add_lib_flags("yaxt", ["-lyaxt", "-lyaxt_c"])
    gfortran.add_lib_flags("xios", ["-lxios"])
    gfortran.add_lib_flags("hdf5", ["-lhdf5"])
    gfortran.add_lib_flags("stdc++", ["-lstdc++"])

Now imagine that I need to add one common (e.g. spack-based) path (I know, it should all work out of the box, but other user's might have a different setup - on my laptop I have to add include path for the compiler. While this is different from the linker, you get the idea). ATM I would have to add the -L option for each library that I add, since I don't know what libraries the application will link with (e.g. it could just link with xios and not yaxt, or just hdf5 - but would need the same path for all these libs) - so in order for the linker to find each libs in whatever subset and order they are specified, each library would need to have the same path added. While this works (and it might be required if you have e.g. a more classical module setup, with each lib in a different directory), it is a lot more convenient to be able to write:

    gfortran = tr.get_tool(Category.LINKER, "linker-gfortran")
    gfortran.add_pre_flags(["-L", "/my/path/to/all/libs"]
    gfortran.add_lib_flags("yaxt", ["-lyaxt", "-lyaxt_c"])
    gfortran.add_lib_flags("xios", ["-lxios"])
    gfortran.add_lib_flags("hdf5", ["-lhdf5"])
    gfortran.add_post_flags(["-lstdc++"])      # Somewhat made up, but when we link with gfortran, we throw in the C++ libs

Even if the user should link with no libs, these flags should be added (seems unlikely that you have nothing to link in tbh :) ), but I can't see that adding these flags can hurt. Even if you are not using c++ and therefore don't need to link with it, it can't hurt (except for a few seconds linking time).

Hope that's clearer now.