Comments (12)
Regarding C support: a full solution there is this: mamba-org/mamba#223.
What we could do for fpm
is not the full solution, but provide functionality for simple C source files, not full packages with a complicated build system.
We have to decide on a layout for C sources:
-
Should the
.c
files be simply files in src/ folder? (I vote yes.) -
Where should the header files be? Either in
src/
or ininclude/
. -
What about dependencies and their header files? (I would suggest Conda and that you can use anything from there, so
fpm
will create an internal environment and you can use any header file from there.) -
What about linking of dependencies?
-
Given that we will support C, why not C++ also? Supporting C++ would be very useful to provide Fortran wrappers: we would write a simple C wrapper that calls into a 3rd party C++ library, and call that C wrapper from Fortran, so it requires compiling of a C++ code.
-
Also one needs to link libc properly for C, and libc++ properly for C++. I think we have to do this anyway anytime we depend on a C or C++ library.
There will be more issues. Some of them similar to what we have to deal with anyway for Fortran sources. So I think let's keep this option open when we are designing fpm
, although I still suggest to concentrate on Fortran sources first.
from fpm.
The low hanging fruit here seems to be handling the mixed C and Fortran source in a single project.
Just let .c
and .h
sit in src/
by default, use gcc by default (like we do now with gfortran), link all object files into a static library and executable (like we do now).
Linking to external (binary) dependencies seems orthogonal to this. Nevertheless important, but we could tackle these incrementally.
from fpm.
I agree, this sounds quite reasonable as a first stab. Thank you for the research.
My personal sorted list of most used non-Fortran dependencies: MPI, HDF5, NetCDF, zlib, libpng.
If everybody here listed their most used dependencies, we could have an idea of top candidates which to design for and test first.
from fpm.
@everythingfunctional, @milancurcic and I discussed this point on the phone and we think so far that the best way forward is to work with Conda (or Mamba to be specific) together with their developers (@wolfv and others) to provide all non-Fortran dependencies. fpm
would link with mamba
and from a user perspective things would just work (users would not need to handle Conda environments explicitly).
Regarding C support, I would suggest initially to handle them via Conda, just to keep things simple.
We can think if if want to later extend fpm
to handle not only Fortran compilers but also C and C++ compilers.
from fpm.
I definitely would like to be able to handle some non-Fortran dependencies. As it's currently designed, I think it won't be that difficult.
The end result of building a library in FPM is just a .a
file, and all of the relevant .mod
files. So, if your package specifies a build script for that, FPM will just call it. There is a small set of things that FPM would like to dictate to that script though. Those being:
- The compiler to use
- The compiler flags to use (mostly to ensure the flags are compatible with the given compiler)
- Where to put the archive and module files
- Where to find any of the dependencies
In this way, almost anything could be wrapped into an FPM package. Best practice would be to entirely wrap the package into a Fortran API, so consumers don't necessarily even have to know it's not Fortran, but this may not be strictly necessary in every case.
For the build scripts, I really like Rust's way of having the build scripts be written in Rust too. Not sure if Fortran would really be doable for that, but it would make sure building a package doesn't have additional external requirements. We could special case Makefiles and CMakeLists to use the typical environment variables I think.
from fpm.
I don't foresee issues with building C alongside Fortran. It may be even simpler as there are no modules to deal with.
from fpm.
I had in mind the "simple" use case of one or a few c files that indeed "just get compiled" as part of the Fortran module. Making the shared C libraries available to other Fortran "consumer code" is probably out of scope. Anyway, thank you for the replies :-)
from fpm.
C has a special relationship to Fortran though. Thanks to the compatibility section, it makes sense for a Fortran developer to include C code in a Fortan project. Could that be taken into account?
My "pet" usage for this is to write a PRNG in C with a Fortran wrapper module. PRNGs often use unsigned integers whose usage is possible in C.
A fpm package could thus, in this scenario, contain Fortran and C source.
from fpm.
@pdebuyl , my recommendation would be to put the C parts of your project in a separate project so that fpm
can easily build the "pure Fortran" part of your project with ease.
We're planning to support make and Cmake as separate build scripts, so supporting linking with (almost) any other language and still having it be an fpm
package would be possible.
from fpm.
@everythingfunctional , @certik , what are the disadvantages/difficulties with natively supporting c sources in fpm
? Many projects do need to include c code from time to time and this is quite normal for Fortran (even before iso_c_binding
came along). I think this would be a good feature.
(I'm not talking about whole package dependencies, just self-contained projects with mixed c/Fortran code).
from fpm.
@pdebuyl thanks for bringing it up, I think we can do that. Looking at my own code here: https://github.com/certik/hfsolver/tree/master/src, I have .f90
files, .c
and .h
files and also .cpp
files all in the src
directory. So if fpm
could eventually compile all that correctly, that would go a long way. The reason I have the C and C++ files are just to interface 3rd party libraries, typically there is no way around that, as one must write some simpler wrapper that is ready to be called from Fortran using the iso_c_binding interface.
So I like this.
from fpm.
The Fortran fpm version does support compiling C code and we can link against native libraries already. I'll close this issue as resolved for now.
from fpm.
Related Issues (20)
- fails with non-standard Fortran usage using ifx(1) compiler
- ordering of link flags before archive, thus flag ignored by linker
- Compilation fails with BOZ literal constant
- `-ffree-line-length-none` should be used by default in tests HOT 1
- Dependency level macro definitions continuously trigger dependency state changes
- Issue with running multiple examples in fpm version 0.10.1 HOT 2
- Issue with running multiple examples in fpm version 0.10.1 HOT 2
- Memory profiling reveals multiple "Conditional jump or move depends on uninitialised value(s)" errors HOT 2
- Release candidate fpm.F90 uses gfortran-specific backslash line continuations HOT 1
- CI for Metapackages broken for Macos openmpi and mpich
- build issue with ambiguous generic `OPERATOR(==)` interface HOT 1
- [build] Nonportable usage in fpm-0.10.1.F90 HOT 2
- App is not installed if source is not main.f90 HOT 1
- MPI-code can not be built with Intel compiler when using standard flags HOT 6
- target option being ignored
- Preprocess macros not work when building via `fpm build` or `fpm run` HOT 1
- fpm test with --runner HOT 8
- bug(ci): uploaded artefacts not pinned to specific GCC version HOT 2
- Implicit interface not working with lfortran HOT 2
- Linker flags are not parsed correctly by the command-line interface HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fpm.