jacobwilliams / json-fortran

A Modern Fortran JSON API
https://jacobwilliams.github.io/json-fortran/
Other
332 stars 83 forks source link

Procedure to query version of json-fortran #505

Closed awvwgk closed 2 years ago

awvwgk commented 2 years ago

Is there a way to query the version of json-fortran at runtime? Something along the lines of

use json_..._module, only : get_json_fortran_version
implicit none
character(len=:), allocatable :: version_string
call get_json_fortran_version(version_string)
print '(a)', version_string
end

Would be useful for projects which depend on json-fortran and want to report which version they are using at runtime.

jacobwilliams commented 2 years ago

No we don't currently have that. We could add it though. I do like the idea.

Currently the .VERSION file has the version number. That is mainly used for the doc deployment and isn't read by the code.

jacobwilliams commented 2 years ago

Maybe we can use preprocessing to include that file in a string parameter?

awvwgk commented 2 years ago

Note that module variables are accessed at compile time not at runtime. Using the version support from https://github.com/jacobwilliams/json-fortran/commit/8a33d9bb60fd681aaf62c31a290214ee6b3c6604 allows to check which version of json-fortran a project was compiled against, however not which version is currently used. For static linking those cases are identical, for dynamic linking those don't have to match.

jacobwilliams commented 2 years ago

I don't fully understand the concern. Are you saying somebody might use a newer shared lib with an older set of the .mod files? I would say they shouldn't do that.

awvwgk commented 2 years ago

Indeed, this is a realistic application as long as you allow setting BUILD_SHARED_LIBS=ON for CMake. Obviously, one has to be careful about compatible versions, but I'm basically using most Fortran libraries via dynamic linking and tight version pins without much problems so far. Having the possibility to query which actual version is used is useful in this scenario.

jacobwilliams commented 2 years ago

I'm still not sure I get it. If you use a fortran library that is exporting modules, you need the library and the mod files. There's no guarantee that using a newer library with old mod files is going to work at all. Is this what you are doing? I would not recommend it!

In any event, what about the function version I just committed?

awvwgk commented 2 years ago

Thanks, looks great.

There's no guarantee that using a newer library with old mod files is going to work at all. Is this what you are doing? I would not recommend it!

Got it, I'll be careful ;). I'm mostly using dynamic linking in package manager or environment manager controlled setups to avoid hours of recompiling dozens of interdependent libraries and executables. Of course I'm going for static linking if I can't have a package manager handling the version constraints and ensuring compatibility.