-
Notifications
You must be signed in to change notification settings - Fork 412
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
confused by Dune foreign_libraries doc: how to define a C library used by C stubs? #4409
Comments
I haven't looked carefully at all the attemps, but the first attempt should work if you add
This missing dependency explains why it seems to work depending on the parallelization choice. I agree that many people struggle with how to use the foreign stubs stanzas, and that the doc should be improved! |
My understanding was that |
Maybe there is room for improvement here, but the |
As far as I understand, I don't think any such (moral) restriction is intended :) |
Here is why I had the impression that
I understand this as saying:
|
Note: reading the documentation again, maybe |
Fourth iteration: foreign_library+(simple)library library, include_dirs+foreign_archive dependency--- a/lib-foo/dune
+++ b/lib-foo/dune
@@ -1,6 +1,5 @@
(library
(name foo)
- (foreign_archives foo)
)
--- a/prog/dune
+++ b/prog/dune
@@ -2,7 +2,7 @@
(name prog)
(foreign_stubs (language c)
(names prog_stubs)
+ (include_dirs (lib foo))
)
- (libraries foo)
(foreign_archives ../lib-foo/foo)
) |
To move forward, I think that it would be helpful to know what are the recommend ways to implement this (simple?) use-case of hybrid C/OCaml project. Is it one of the current attempts, or something else? We could document that. I think in an ideal world my preference would be for having a solution looking like this:
Note:
|
I believe the simplest is attempt 1 + Anyway cc-ing @snowleopard who implemented foreign library/stubs support (see #2650 for some of the rationale). |
Right now the simplest way forward is the first attempt with the @gasche I agree that there is a room for improvement here, especially in terms of documentation. Would you like to help with that, on the basis of the difficulties you just experienced? I'll be happy to review the changes. The current implementation of foreign code support grew out of an RFC that I wrote some time ago: #2650. I think that we should avoid "automagic" solutions in foreign code support as much as possible, because things here can be (and admittedly already are) very confusing even without any magic. Still, feel free to write up a new RFC for a higher-level support for foreign code if you think it will be a net positive change for Dune users. |
I'm happy to help with the documentation if I can, but:
I understand the benefits of encouraging Dune users to contribute to its development. But (in the small part of the development I see, which is only my own issues) I also notice that active contributors are not actively improving documentation or fixing usability issues, and I think that this is correlated with the fact that the documentation is of unequal quality and usability is disappointing in various places. You have a Crowd-sourcing documentation contributions is great, but if the people implementing new features are not considering documentation a priority, why would we expect future documentation to be better than the current documentation? (Usability issues are even less likely to be fixed this way, given that the barrier to entry for a fix is much higher than for documentation.) |
I will change my build system to use |
@gasche You can use the I personally do care about good documentation, and as the implementer of this feature I feel responsible for documenting it well. If you don't have any specific improvements in mind at present, I'll go over the corresponding sections and make them better when I find some time. I wouldn't be surprised if some parts just got stale and need refreshing. Maintaining good documentation is hard.
I agree that it would be nice to avoid relative paths here but the devil is in the details, which is why I think a change like this deserves a new RFC. Anyway, I self-assigned for now. If anyone has bandwidth to move this issue forward, please feel free to take over. |
I'm upgrading this issue to 3.0 milestone so that we don't forget it. The reference section could be improved, and particularly the limitations as also found in #4883 . |
Is this issue still relevant, or were people able to improve the documentation of C libraries? |
I'm not aware of any improvements specifically in the documentation of C libraries. However, there was some general work on improving Dune's documentation. I know that @voodoos is currently looking at the foreign stubs code as part of #5649, so perhaps he has a better idea of the state of docs here. What's your take, @voodoos? Personally, I won't be able to look into this issue any time soon, so I unassigned myself, to make it clear that no one is actively working on it right now. |
I have a simple project that consists of:
foo
prog
that uses C stubs that themselves use functions provided byfoo
It took me several attempts, and many confused looks at the Dune documentation for dealing with foreign libraries, to get something working. And then, a few weeks later, I realized that the thing was not working (whether it builds or not depends on parallelization choices). Then I went to read the doc on dealing with foreign libraries again, and I got a new solution that was not working. And then another solution that seems to be working, but seems unnecessarily redundant. What is going on?
Project layout (see the complete repro case at https://gitlab.com/gasche-snippets/dune-c-library-repro-case ):
First iteration: declare the library with
foreign_library
, declare the dependency withforeign_archives
My first iteration declares a
foreign_library
forfoo
inlib-foo/dune
:and then uses a
foreign_archives
stanza to declare thatprog
depends onfoo
:This seems to work (it prints 42 as expected):
But in fact it does not work:
It looks like Dune does not understand (?) that
prog
depends onfoo
.Reproduction repository: https://gitlab.com/gasche-snippets/dune-c-library-repro-case/-/tree/first-iteration
Second iteration: declare the library with both
foreign_library
andlibrary
, declare the dependency withlibrary
Hidden of the middle of some documentation on foreign build sandboxing (which is clearly not what I'm doing here), there is this suggestion:
I thought that maybe I needed this: maybe depending on
bar
in this way, I "will be able to use C functions from libfoo". So I did just that: inlib-foo/dune
, define both aforeign_library
and alibrary
, and inprog/dune
, use(libraries foo)
instead of(foreign_archives ../foo/foo)
.But again this does not work:
It looks like the issue is that dune detects
foo
as a dependency, but does not link it into the resulting library. (This may come from the fact thatfoo
is used in C files, but not explicitly in the OCaml code.)Several Dune issues have discussed the difficulty to basically do what
-linkpkg
does in ocamlfind (Discuss: dune problems using dynlink plugins, #3141, #2417). But as far as I can tell, none of the solutions proposed in the dynlink case give an easy way to tell dune thatprog/prog.exe
should link with thefoo
library.Reproduction repository: https://gitlab.com/gasche-snippets/dune-c-library-repro-case/-/tree/second-iteration
Third iteration: declare the library with
foreign_library
andlibrary
, declare the dependency withforeign_archives
andlibraries
Declaring the dependency by using both
(libraries foo)
and(foreign_archives ../lib-foo/foo)
inprog/dune
seems to work.Questions:
Reproduction repository: https://gitlab.com/gasche-snippets/dune-c-library-repro-case/-/tree/third-iteration
The text was updated successfully, but these errors were encountered: