-
Notifications
You must be signed in to change notification settings - Fork 109
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
Ability to pass any compiler flags directly to the compiler #1096
Comments
My understanding of the fortran features structure is to hide compiler details behind the flags, so I'm not 100% sure adding compiler-specific flags is the best approach here. Regarding max line length, not all compilers support varying it but GNU definitely offers this good option. Instead of adding one more structure (remember that custom flags are passed via CLI rather than manifest), could we instead just change this: Line 173 in 1cfcaf8
to this? flag_gnu_free_form = " -ffree-form -ffree-line-length-none -ffixed-line-length-none", & |
Thank you for your speedy comments!
This is intended to not be specific to any compiler and the responsibility then is passed to the "user". But I understand that hiding compiler specifics is a design choice and therefore shouldn't be changed lightly. However, I can still see the benefit of having a way to specify any compiler flags via the manifest, rather than requiring
I think this sounds good and would solve issues with that particular flag. I shall raise another issue/PR to update the free-form but I am still interested in this mechanism of passing any compiler flag through the manifest. Happy to be proved wrong though. |
I agree, would probably make the most sense to have them under the [build]
link = ["blas","lapack"]
flags = ["-some-other-flag"]
c-flags = ["-c-only-flag"]
cxx-flags = ["-cpp-only-flag"] |
I like this idea, it would make it easier to pass flags for |
Would it be possible to define different sets of flags for each supported compiler? I guess there are projects, that are only working with one specific compiler, or maybe don't work with one specific compiler. It would be nice to define this in the toml. This would be an opportunity for defining compiler specific flags. E.g. [build]
default_flags = ["-O3", "-g"]
[build.compilers.ifort]
flags = ["-O2", "-fast"]
min_version = "19.1.0"
[build.compilers.gfortran]
supported = false |
One would need to cross this with the OS. Intel uses slightly different nomenclature for the same flags depending on the OS. |
Exactly, that's why flags for shared Fortran features are standardized via the Lines 160 to 174 in 1cfcaf8
so I think this structure seems preferable. For example for unlimited line length, I think it should be the default setting for the "Free" source form on all compilers ( Then, one may still want compiler-based flags, I think it could make sense to have just the flag name so the initial symbol is resolved internally (e.g. because Intel wants [build]
link = ["blas","lapack"]
flags = ["some-other-flag"] # note: no dash
flags.intel = ["intel-only-flag"]
c-flags = ["c-only-flag"]
c-flags.gnu = ["gnu-only-flag"]
cxx-flags = ["cpp-only-flag"]
note OpenMP is a metapackage: I believe openacc could be implemented the same way, especially as it may carry over additional linking flags |
it would be |
This seems to be a subset of allowing for profile definitions in the fpm.toml manifest file. Extensive work was being done on that at one time, and there is a related pull request but no action since that I see of. Allowing compiler options in the fpm.toml file seems like it should take into account how the package is built when it is a dependency, and which compiler and which OS as discussed; |
I can imagine a scenario where this contributes to fragmentation in the package ecosystem: Let's imagine for the sake of argument that we implement the above solution. The good thing is that we now have an escape-hatch if we want to manipulate our compilers behaviors in ways not implemented by
for all the relevant compilers. This is a little annoying, sure it would be nice if a Imagine down the road a package author writes a package and they use
and now if someone wants to use package This example is contrived, but for more complex cases, and in a scenario where many packages end up using the escape hatch I think it risks fragmenting the package ecosystem in ways that can be difficult to reverse. |
I don't think that will be a problem. Compiler profiles would probably not be used on a daily basis. And those who are not looking for it because it is necessary for them may not even know that this feature exists. If you want to use it for a project that should work everywhere, you have to take care of it accordingly. If you don't do this, there is always the option of creating a pull request or a fork. However, compiler profiles would enable projects that would otherwise be impractical or impossible with fpm. E.g. CUDA Fortran projects. |
I wouldn't say this
One does not need to go that far to see the need for profiles. Most of the time one is looking for a way of achieving the same behavior across different compilers (or close enough). Take file inlinement optimization: gfortran So, the key problem from my point of view is not achieving different behaviors for each particular compiler/platform. It is being cross-platform/compiler compatible. |
Compiler flag profiles were a GSoC 2021 project --> #498. Jakub Jelinek maintained his development blog here: https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297 This feature turned out to be very tricky, for several reasons:
In CMake, you essentially end up using generator expressions based on the $<Fortran_COMPILER_ID> selector. File-specific flags are added using: set_source_files_properties(foo.f90 PROPERTIES COMPILE_FLAGS $<...>) If you dig, you will find several related issues, |
IMO:
is the key problem to solve as:
Once the OS and the compiler are given, fpm has no decision to take in this regard,
Should not be fpm's responsibility: the developer choses his compiler and sets the flags as per the compiler documentation. If it is wrong, then that's the developers responsibility.
I would say it is a separate issue: Should fpm build/rebuild all upstream dependencies applying the same flags? This can be debated, I see reasons to do so and reasons to don't do it. But it should be uncoupled from the possibility of defining custom profiles. My take is, |
I guess one should have the means to force it if necessary (e.g. for debugging). This is what we have now with The problem was that package A built with
I think the issue may have been fixed in recent GCC and LLVM versions though according to discussion here (https://news.ycombinator.com/item?id=41212072). |
Lots to think about! Thinking about it, I believe that profiles and assignment of compiler-specific flags are two different topics.
[build]
link = ["blas","lapack"] # all compilers
flags = ["some-other-flag"] # All compilers
c-flags = ["c-only-flag"]
cxx-flags = ["cpp-only-flag"]
[build.intel]
flags = ["intel-only-flag"] # intel only
[build.gnu]
c-flags = ["gnu-only-flag"]
#... 1b) for build/link flags that represent Fortran-specific features, we should keep building on the facilities we have, namely metapackages (for openacc, coarrays, etc.) and the
Here is an example I would see fit: I want to build my package with quadruple precision support (ok this may even be standardized in the Fortran table). So I imagine I will have: [profiles]
quad-precision = [macros.cpp = "WITH_QP", build.link = "quadmath"] |
Description
It would be very useful to pass compiler flags from the fpm.toml file directly to the compilation commands. It seems that currently it is possible to pass very specific flags such as -ffree-form but something more generic would be more flexible. For example
The new
user-defined-flags
would then be passed straight through to the compiler and the compiler allowed to catch any errors with the flags.Possible Solution
get_feature_flags could handle a new feature
user_defined_flags
This would of course require further changes to add
user-defined-flags
. Could this be added everywheresource-form
also is currently?Additional Information
No response
The text was updated successfully, but these errors were encountered: