Skip to content
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

example of switching p2a to dune #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

example of switching p2a to dune #6

wants to merge 3 commits into from

Conversation

Isweet
Copy link

@Isweet Isweet commented Aug 7, 2018

I'd like to propose switching to the dune build system for OCaml. This performs the port for the p2a project.

This should not be merged! It is merely to show the diff, and spark a discussion.

Some advantages of this include:

  1. Simpler build configuration
  2. dune integrates with the utop toplevel, so to test the functions in a library (say basics.ml):
8c8590432779:p2a iansweet$ dune utop src
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                                                                      │ Welcome to utop version 2.2.0 (using OCaml version 4.06.1)! │
                                                                                                                                                      └─────────────────────────────────────────────────────────────┘

Type #utop_help for help about using utop.

─( 16:57:30 )─< command 0 >──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # open Basics;;
─( 16:57:30 )─< command 1 >──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # Basics.eq [ 1 ; 2 ; 3 ] [ 2 ; 3; 1 ];;
Exception: Failure "unimplemented".
  1. Running tests is similarly easy:
8c8590432779:p2a iansweet$ dune runtest .
EEEEEEEEEEEEEEE
==============================================================================
Error: public:14:product.

...

Ran: 15 tests in: 0.11 seconds.
FAILED: Cases: 15 Tried: 15 Errors: 15 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.
  1. It has rapidly become the default build system for OCaml packages on OPAM.

The only (potential) obstacle is the submit server. I'd have to investigate a bit to figure out how hard it would be to modify the submit server to accept dune projects. Essentially, the dune binary would need to be available on the submit server. It is available through OPAM.

Let me know what you think.

@camoy
Copy link

camoy commented Aug 27, 2018

This seems like a really good idea. Easy integration with utop is nice (no more forgetting .ocamlinit files!) For P4B we link in pre-compiled .cmo/.cmi files. Do you know off-hand how to do that with dune?

@Isweet
Copy link
Author

Isweet commented Aug 27, 2018

Off the top of my head, no. But I'm sure there is a way, and I'd be happy to look into it.

@camoy
Copy link

camoy commented Aug 27, 2018

Only if it's not too much trouble. I'd greatly appreciate it.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

This is in the p4 directory? Just sets.cmi / sets.cmo -- is that right?

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

See: https://discuss.ocaml.org/t/dune-link-against-cmo-cmi-without-source/2488

Short answer: there isn't a way to do this.
Long answer: is there a good reason you are doing this? If not, it'd be pretty simple to just (a) distribute the source or (b) use an existing Set library (e.g. Jane Street's).

@camoy
Copy link

camoy commented Aug 28, 2018

Yes, for P4 it's not as necessary (it provides a canonical implementation of a prior project they implemented in P2 just so they don't have to learn a new library). It's really more necessary for P3B where we give a correct lexer and parser. During the summer we did away with all this and just suggested they copy in prior code, mainly to avoid bytecode version incompatibilities since many people had different OCaml versions. However for some students, bugs in their prior projects only manifested in later projects. This was a very difficult problem to debug (both for them and in office hours).

I don't really think there's a nice complete solution to all this. Nonetheless, I will definitely talk to Dr. Mamat about switching to dune. I'm pretty sure he will be OK with it.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

I assume that the reason for not giving them the source for the canonical implementation is that you don't want it to be distributed (i.e. cheating, etc.)?

Dune has support for generating lexers / parsers from .mll and .mly files, but if these are also .cmo/cmi files then you will have the same issue.

Another (slightly crazy, but also nice) option is to create an OPAM package for the canonical implementations and then host them on a local UMD server. Then you can do:

(library
  (name regexpi)
  (libraries sets))

in the dune file.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

Actually, now that I think about it, dune uses findlib for the packages in its (libraries ...) clause. So, if you had a way to make the binary version of the modules into findlib packages and register them then you could also do what I suggested above.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

I think this is the best solution, because it would allow you to only distribute binaries but then also depend on them properly as a library. Although it does require someone to fashion the sets.cm* files into a findlib library.

@camoy
Copy link

camoy commented Aug 28, 2018

That definitely sounds like the best option. I'll look into doing that. Thank you so much Ian!

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

Okay, I was able to create an opam package for the sets module. Now I am going to see if I did it correctly, and if dune can access this package... please stand by...

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

Currently I'm imagining things like:

src/
  regexp.ml
  regexp.mli
  nfa.ml
  nfa.mli
  dune
dep/
  sets/
    sets.cmo
    sets.cmi
    Makefile
    sets.opam
bin/
  viz.ml
  dune
test/
  testUtils.ml
  public.ml
  dune

and you'd just need to do:

opam pin add sets ./sets

to register the sets package from opam. Then, the dune file in src/ just has:

(libraries sets)

and everything should work out.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

Then anytime you have things you want to distribute as binary, you stick them in dep and write a quick little .opam file and do a opam pin add and you should be good.

Doing this for p4b now to verify.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

And you can even add an OCaml version constraint for 4.04.x so that when students try to use the wrong version of OCaml, opam will yell at them.

@Isweet
Copy link
Author

Isweet commented Aug 28, 2018

I've added a first crack at my idea. It's here (second commit on the branch):

1f54b08

The basic idea is to turn any dependencies whose source you don't want to distribute into opam and findlib packages, and then opam pin add them so that dune can find them easily.

The stuff in deps/sets is messy but all the other stuff should work once I've got that figured out.

@camoy
Copy link

camoy commented Oct 1, 2018

As noted in your Makefile I'm not sure *.cmxa files can be generated without the original *.ml source (at least I can't find any reference online). And without that it seems you can't run the tests :(

@Isweet
Copy link
Author

Isweet commented Oct 1, 2018

Yeah, in order to build the *.cmxa you need the *.cmx.

Seems strange that you can't run tests, since they should be able to be run via the compiled version just as well as the bytecode.

I'll see if I can find something on this tomorrow.

…bytecode executable for test suite, not native
@@ -1,3 +1,7 @@
(test
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test" --> "executable" will get rid of the cmxa warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants