-
Notifications
You must be signed in to change notification settings - Fork 99
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
[Fortran fpm] Add support for command-line specification of compiler options #235
Comments
Just a note, if you tie the build directory to the compiler options, as I've done for h-fpm, then you have to pass the same options to I don't know that the CLI for h-fpm and f-fpm must be identical. I think a little bit of experimentation in this area can help us find a more optimal solution. Ideally they should be similar and converge to the same, but don't have to be identical initially. |
We were discussing using another command for this over at #220. There is To solve the issue with the arguments for the other build modes,
In contrast |
I like it, but it's missing two aspects.
For 1, I would just add the |
I have a version ready that currently assumes The version I have ready just applies the options to the debug version Lean towards there being two options, one for compiles and one for |
lternate compilers. This is an alpha version for furthering discussion There are three new switches
Essentially, if you use --compiler and/or --flags you have to specify a The names release and debug are reserved. You can only specify the custom build flags on the "build" subcommand. So this is just a single file you have to build with gfortran: # get the single-file build file
wget http://www.urbanjost.altervista.org/REMOVE/ffpm.f90
# compile and name "ffpm" somewhere in your path
gfortran ffpm.f90 -o $HOME/.local/bin/ffpm
get an fpm project. For example
```bash
git clone https://github.com/urbanjost/M_CLI2
cd M_CLI2
# assuming `ffpm` is in your path from above:
# build the package with the name "ONE" with the nvfortran compiler:
ffpm build --compiler nvfortran --flags '-Mbackslash' --build_name ONE
# build it again with the ifort compiler:
ffpm build --compiler ifort
# build it again normally
ffpm build
# and again as a release version
ffpm build --release
# build with gfortran but with no user-specified compiler switches
ffpm build --build_name DEFAULT
# to run that
ffpm run --build_name DEFAULT
# profile with gfortran
ffpm build --build_name PROFILE --flags '-pg'
ffpm run --build_name PROFILE
ffpm run --build_name PROFILE --runner gprof
# build with ifort(1) compiler and profiling options
ffpm build --compiler ifort --build_name PROFILE --flags '-p' # build
ffpm run --compiler ifort --build_name PROFILE # run
ffpm run --compiler ifort --build_name PROFILE --runner gprof # profile Ideally I would like to see this functionality available via the TOML file as discussed in other issues but this gives a working model for getting an idea of what some of the issues will be. RIght now for compilers other than gfortran it is assuming the modules are placed in the directory specified via -module DIRNAME which is an issue that needs a more generic solution. Hopefully this will further the discussion a bit more and help lead to a real pull request. |
So after trying a lot of variants, I think: If you supply any user-specified compiler options with --flags you must use the build command to build and you must specify a user-supplied build name via --build_name. You can then use --compiler and --build_name with a matching name on the run and test commands to run executables built with those options. On build options after -- can be options equivalent to --flags or maybe should be "loader only" options. If your compiler name is not known and the switch for specifying where output files to be placed is not "-module $NAME" then you must supply and environment variable called FPM_BUILD_OUTPUT which has a space placed between it and the build directory name unless it ends in an = in which case the filename is appended directory to it. So current usage would be unchanged. |
I would suggest to stay as consistent with other build systems. The established default for the compiler environment variable is
The environment variable
|
For whatever reason the browser is not letting me edit the post. I wanted to update it with some of the changes as a working document. Using FC instead of making up a "new" name seems like a particularly good one. Since hyphens are part of the "space-hyphen value" of POSIX commands I find the underscore useful for names, and then the names can be used directly in the code as well as hyphen is allowed in Fortran variable names; but that is probably as much personal taste as anything else as that argument has been going on at least as long as which text editor is "best" and which programming language is "best". When I get to a machine that works I will try to capture this all into a second take. Thanks for the quick response. I strongly want some of this to go into the TOML/configuration files so packages can be shared more readily but there will always be some need for directly specifying the switches and it lets us more experience with the issues of multiple compiler support On that note, I THINK your input on M_CLI2 plus working through several compiler bugs has the latest version of M_CLI2 passing its tests with nvfortran, ifort, and gfortran8.3+. Each compiler has it's pros and cons and bugs/features; but considering all that I think it is quite portable to modern Fortran compilers. It's predecessor was F77 and can on everything from SCOPE 2/UNICOS/SunOS/Solaris/HP-UX/AIX/NetBSD/Linux/Tru64/... so it was interesting that some of the modernizing made that a bit harder than I expected. It got cluttered by making a stand-alone version of; I hope to streamline it and add a bit of OOP to it in the future, but not in a hurry as long as it functions as intended. |
Anyone have any favorite compiler options for compilers other than gfortran that would be used as a seed for the default and --release compiler switches? Any suggestions for the --build_name key name that seem better or shorter? --tag or --ID perhaps? I added a number of other compiler names for testing based on the list in #223 but have no great way of testing the majority of them. A lot of the vendors used to support on-line access to test machines (manufactures and compiler vendors) but I do not see any remaining ones. Something for the wish list would be web interfaces for various compilers where you could give the URL of an fpm package and it would do a build of it and show the resulting output. Probably asking to much for more than a build, but just the build would be nice. After all, legend says some unnamed companies have the policy "It compiled, ship it!". |
still oscillating on a separate subcommand like fpm compile --ID xxxxx --compiler xxxx -flag xxx .[regular_build_options] -- LOADER_OPTIONS maybe no --flag option but options allowed after the compiler name, eg. "--compiler 'myf90 -traceback -pg' " fpm build,mytest=' -pg -O3' ...
fpm run,mytest ...
fpm test,mytest ... If ID is not provided |
Provisional Custom CompilesSo, after going through the suggestions and some testing with similar h-fpm features this is Add compiler switch --fc
FC is apparently a commonly used environment variable for the compiler, is new command "compile"The
-ID switch added to test and run to match name on compile commandThe ID names release and debug are reserved and cannot be used. preliminary support for alternate compilers for testingA skeleton was started for standard debug and release builds that allows SUMMARYSo default usage is unchanged from the previous version. By simply setting FC you can use it like the How does that sound? Instructions for testing before PR is submitted# single-file program for testing
wget http://www.urbanjost.altervista.org/REMOVE/ffpm.f90
# or pull from webpage of same name
# build and call ffpm. Example. Change output name as appropriate to put
# into your search path
gfortran ffpm.f90 -o $HOME/.local/bin/ffpm sample testing# get a test package or use your own
if [ ! -d M_CLI2 ]
then
git clone https://github.com/urbanjost/M_CLI2
fi
cd M_CLI2
set -x
# simple custom build
ffpm compile --fc nvfortran --flags '-Mbackslash' --ID ONE
ffpm run -ID ONE
# default build using ifort
ffpm build --fc ifort
# default build
ffpm build
# default release build
ffpm build --release
# not sure if this should do a default build or build with gfortran with
# no other switches
ffpm build --fc gfortran
# will not allow reserved names debug and reserve even for this case
ffpm compile --fc gfortran --ID debug
# profile with gfortran
unset FC
ffpm compile --ID PROFILE --flags '-pg'
ffpm run --ID PROFILE
ffpm run --ID PROFILE --runner gprof
# profile with --fc switch and ifort
ffpm compile --fc ifort --ID PROFILE --flags '-p' # build
ffpm run --fc ifort --ID PROFILE # run
ffpm run --fc ifort --ID PROFILE --runner gprof # profile
# profile using FC variable and appropriate flags for that compiler
export FC=ifort
ffpm compile --ID PROFILE --flags '-p' # build
ffpm run --ID PROFILE # run
ffpm run --ID PROFILE --runner gprof # profile |
Thanks @urbanjost; I've had a quick play around with your proposal demo — it's exciting to be able to use other compilers with fpm! I've been using the Once flags can be specified in the manifest as different configs, I would be unlikely to use the @urbanjost, would you be happy opening separate PRs for the specification of compilers and specification of flags? The former seems ready to go from a specification standpoint, whereas the latter may need more discussion in it's own PR. |
I will split them. My own comments in several other discussions is of the same sentiment. The prototype is just to aid the discussion. Everyone is different but I find it useful to actually try something if the discussion is stalled or has hit a roadblock. I separated this out as a way to actually test using other compilers and a --flags switch like h-fpm because of some of those reasons. Since a TOML file is not the most intuitive feature I found a prototype useful for exploring other alternatives like a command similiar to "custom" that would write a TOML entry; using aliases and environment variables from the shell to create alternatives; whether a single name or ID should imply a compiler ... If the configuration parameters are in a file they tend to be so specific to a compiler that I want something like "fpm custom profile" and the name "profile" can be used with various compilers. As-is I found So this let me actually test some of those combinations. It also matches the flag of the same name in h-fpm, and so on; but a lack of compiler and load options seemed to be the most commonly mentioned reason people could not use the earlier fpm versions. Thanks for actually trying it. There are pros and cons to any approach that involves supporting multiple compilers. So my sentiment is similar but there is nothing like trying it. I have been finding that with three compilers now available on my machine that I usually use the environment variable FC and start three terminal sessions in screen(1) or tmux(1) with one set up for each compiler and toggle between them. That has made me wonder if the compiler switch should allow multiple names like Still looking for other feedback on --flags including experiences with h-fpm or other source package managers. |
On the contrarian side of this; because of the problems with remembering the compiler switches I was considering that the first build of a directory cache some data. A TOML file would see appropriate but at least for the first cut I was just going to use NAMELIST. The first time you built a (compiler-specific) directory it would create a file with the compiler and load flags from the |
fpm custom -fc ifort -fflags '-g -C -CB -CU -fpe8 -ftrapuv -fp-model=precise' -ID my_debug or fpm build --custom mydebug ... |
Currently build and custom do not use the "unnamed" fields so The --ID switch would not be required. TO allow the same for f-fpm there would have to be a change to do the same. Currently names following the subcommand are assumed to be targets (the name of the executables. To remove the --ID switch from all commands that would have to be changed so the same as h-fpm where you specify that with --target NAME. It depends on which would be used more commonly. Alternatively there could be It would be a non-compatible change to f-fpm to change to --target but would keep f-fpm and h-fpm more aligned; but this is still alpha. I think with these changes the changes would be useful even with the TOML interface for development. For producing a real package I think having the configuration in a shippable format in the TOML file will be the dominant format for build options that are required for a package to be functional (ie. coarray, openMP, external packages like -X11 and netCFD, .ncurses, MPI, ...). |
So then the format could be fpm custom myopts --fflags 'compiler args' -- load_args
fpm run myopts
fpm run myopts -target demo1 -- options_for_demo1 But then to run multiple programs instead of fpm test test1 test2 test3 it would have to be fpm run --target 'test1 test2 test3' |
If anyone is interested I renamed the ffpm.f90 file to ffpm-custom.f90 and put ffpm.f90 there, which is a preliminary version that just specifies a compiler. So
After some further testing I will start a new issue for just the compiler switch and probably close the one for the |
The
h-fpm
version allows compiler options on the command line. I would propose allowing the same capability but using thesyntax
where ARGS could be multiple compiler options.
h-fpm
option would be informative as to whether this option should be added or not.h-fpm
version hashes the options to create a unique pathname for each combination of switches. That is an option here ; as well as requiring a user-supplied name ;or still being built in the standard location. Not sure what the general sentiment is about that. Using the hash resolves all kinds of collision problems but could be hard to remember and duplicate unless the hash is reversible and tagged with a name for reuse.The text was updated successfully, but these errors were encountered: