-
Notifications
You must be signed in to change notification settings - Fork 63
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
Build with dune #212
Build with dune #212
Conversation
I'm all in favor of moving everything to Dune, so 👍 for me. Can we do something about the ctypes test? Dune folks promised an easier way to build ctypes programs but as far as I know they haven't come up with the "automatic" solution. What do other people do with ctypes and dune? |
There is some relevant discussion here: hacl-star/hacl-star#426 |
I see that ocaml/dune#3905 was merged and there is now very nice documentation here: https://dune.readthedocs.io/en/latest/foreign-code.html#ctypes-stubgen Is there any chance we could try to use this to finish this PR? |
Thank you for the update. However, that doc reads (emphasis mine):
So I'd suggest to wait until Dune 3.0 (along with its official opam package) is officially released. If anyone were to resume work on this PR right now, then CI changes would be needed to reinstall Dune with |
The purpose of this commit is to show that ctypes stubs generated by Karamel's `-ctypes` option can be compiled and used with dune. However, this is not the recommended way to compile a program with ctypes stubs. Indeed, here, all dependencies are written manually in dune files (the ctypes.depend file generated by Karamel is not used.) By contrast, dune itself can automatically generate ctypes stubs etc., which might be a substitute to Karamel's `-ctypes` option, but this is not the purpose of this commit.
The ctypes test now builds with dune instead of ocamlbuild. However, I had to write all dependencies by hand in dune files, and the By the way, I have an Everest green: project-everest/everest@b12d6f0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Tahina for the updated PR.
I'm trying to make sense of your proposed changes and I don't understand the relationship between test/ctypes/dune
and https://dune.readthedocs.io/en/stable/foreign-code.html#stub-generation-with-dune-ctypes -- it looks like you explicitly set out to avoid dune's built-in support for ctypes.
Are there any deep reasons why you don't rely on this? Did you encounter any difficulties? It would good to document and understand, since right now your proposed build seems harder to maintain than the previous one.
Thanks
Actually, this is not true, ctypes users still need to write a type description functor and a function description functor, so in our case,
After hours of trying and failing, here are my road blocks:
I am not sure it is worth investing so much time and energy in a dune feature that is explicitly meant as experimental:
So, a saner alternative could be to enrich Karamel's |
Thanks, this is great to document. @victor-dumitrescu you authored a bunch of this, what do you think? do you think, in addition to ctypes.depend, that we should generate a dune file? or is there a better way to solve Tahina's issues? |
If I remember correctly (although it's been a while) the main difficulty with building with |
Thanks a lot Victor for chiming in! In all cases, this should be out of the scope of this PR. So, @msprotz, are we ready to merge this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay, I was on vacation then traveling. This overall looks good. Some remarks:
- I'm confused by your usage of
+
in make recipes, see my various comments - I think we should get rid of krmllib's OCaml build, I have no clue what purpose this serves
- please remove the top-level myocamlbuild.ml at the root of krml
- I will submit a commit directly on your branch that builds ctypes just like hacl-star-raw is built, and avoids that un-ergonomic dune build
- I'm seeing a lot more warnings now in the build, notably warning 7 -- do you know what's up?
once all of the above are done, we can merge. thanks for your patience
Makefile
Outdated
|
||
krmllib: minimal | ||
$(MAKE) -C krmllib | ||
+$(MAKE) -C krmllib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the GNU make manual, "5.7.1 How the MAKE Variable Works":
Using the MAKE variable has the same effect as using a ‘+’ character at the beginning of the recipe line.
Is there a reason why you added these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can remove this redundant +
for clarity, thanks for pointing out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, f3fac5a introduced +$(MAKE)
for the test rule, but it was keeping a pre-existing +
, so I could remove it from there as well
@@ -144,8 +153,7 @@ $(MINI_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(MINI_DIR) $(wildcard c/fstar | |||
# Extracted (and verified) uint128s; copied into generic and minimal. Note that | |||
# FStar.UInt64 shares the same bundle name, meaning that | |||
# FStar_UInt128_Verified.h can be dropped in any of the two krmllibs above. | |||
$(UINT128_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(MINI_DIR) ../_build/src/Karamel.native | |||
KRML_HOME=$(shell pwd)/.. \ | |||
$(UINT128_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(MINI_DIR) ../src/_build/default/Karamel.exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for removing KRML_HOME when it's present in the other recipe above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably an overlook, let me restore that. Thanks!
krmllib/Makefile
Outdated
@@ -6,6 +6,12 @@ | |||
|
|||
all: verify-all compile-all | |||
|
|||
extra: | |||
+dune build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
based on my understanding of the GNU Make manual, section "9.3 Instead of Executing Recipes": adding a
+
here means that if someone runs, e.g.,make -n extra
to see what would be done by make, thendune
is still invoked... do I understand this right, and is this a desired behavior? -
do you know who uses C.ml and TestLib.ml? I don't, and the last reference to them comes from 2017. Can we just remove those files, and the corresponding targets and dune-project files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I wasn't aware of 9.3, thanks for pointing out. However, I was concerned with Appendix B:
‘warning: jobserver unavailable: using -j1. Add `+' to parent make rule.’
where I initially anticipated dune
to make use of GNU Make's jobserver (which finally dune doesn't), so let me remove this.
(This also means that there is no way to make the jobserver available to a non-Make process while also honoring make -n
)
- I'm not aware of any F* code depending on krmllib being extracted to OCaml using the handwritten C.ml or TestLib.ml. Not even the (now disabled) miTLS extraction to OCaml does that. So yes, let me simplify things and remove that extra rule.
Thanks again for chiming in!
This is done. This means that @tahina-pro's suggestion is now implemented:
|
addressing #212 (comment)
addressing #212 (comment)
Thanks a lot Jonathan for your help! |
Thanks Tahina, much appreciated. |
This PR is a
partialfix to #139 : with this PR, I can now build KaRaMeL with dune instead of ocamlbuild.I moved all .ml files into the
src/
directory and wrote a dune file to cover that directory tree.The only part that still requires ocamlbuild at this point isthe ctypes test also builds with dune instead of ocamlbuild.