solvuu / solvuu-build

DEPRECATED. We recommend Jane Street's dune (formerly jbuilder).
ISC License
24 stars 5 forks source link

Specify additional ocamlbuild arguments #42

Closed copy closed 7 years ago

copy commented 7 years ago

Is it possible to specify additional arguments to ocamlbuild? I'm converting an ocamlbuild project to solvuu-build and would like to specify the following:

-verbose 1
-tag 'optimize(2)'
-tag 'color(always)'
-cflags "-warn-error A-26-39-32-27-45-48-52-58"
-j 3
-no-links
agarwal commented 7 years ago

It won't make sense to support -tag. Tags are a construct of ocamlbuild's default rules, which solvuu-build avoids. We can and should add any missing flags that correspond to ocaml, e.g. conceptually -tag 'color(always)' can be supported but should be done by adding a color field to the lib and app types.

For -tag 'optimize(2)', do you know what ocamlbuild does with that? What ocaml flag does that correspond to?

The -verbose and -j flags are something you could handle yourself. The Makefile we recommend you provide includes a standard one that we distribute. Run cat $(opam config var solvuu-build:lib)/solvuu.mk to see its contents. Notice that the file is actually trivial. You could write it yourself, and add the -verbose flag to ocamlbuild. If you feel the solvuu.mk file we provide should be changed, please go ahead and make an argument for that. (Actually, given how trivial it is, maybe we should stop providing it.)

The -no-links argument similarly doesn't make sense to support. I already effectively do what this flag implies because I don't like how ocamlbuild creates symlinks (see my complaint at ocaml/ocamlbuild#14). The only symlinks solvuu-build creates are for .ocamlinit, .merlin, and .install, which you really do want to do. If for some reason, you disagree even with those, note that we do the symlinking in the generated _build/project.mk. You could go further with my recommendation above about writing your own makefile. Notice that _build/project.mk also isn't all that complicated. You could write your own. Of course, again, if you think what you want should be the default, then please go ahead and make the case for it.

pveber commented 7 years ago

Actually, given how trivial it is, maybe we should stop providing it.

Please let's keep it: I think it's a good thing solvuu-build provides with easy default configurations for the (or a few) most frequent project structure. Actually, I think the API could even provide with more such defaults, to reduce the size of the OCamlbuild plugin.

copy commented 7 years ago

For -tag 'optimize(2)', do you know what ocamlbuild does with that? What ocaml flag does that correspond to?

I agree that tag support itself shouldn't be added.

optimize(2) sets multiple flambda-related options: https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc#compiler-tags-for-native-compilation-using-flambda-4-03-and-newer

The -verbose and -j flags are something you could handle yourself. The Makefile we recommend you provide includes a standard one that we distribute. Run cat $(opam config var solvuu-build:lib)/solvuu.mk to see its contents. Notice that the file is actually trivial. You could write it yourself, and add the -verbose flag to ocamlbuild. If you feel the solvuu.mk file we provide should be changed, please go ahead and make an argument for that. (Actually, given how trivial it is, maybe we should stop providing it.)

This works for me, and should be documented if this is the way we want to move forward. On the other hand, the existing solution has the advantage that we can change the Makefile template, in case that is necessary for any reason. I think the current template is good, it would just be nice to change the verbosity if needed (either using the way you proposed or within myocamlbuild.ml).

The -no-links argument similarly doesn't make sense to support. I already effectively do what this flag implies because I don't like how ocamlbuild creates symlinks (see my complaint at ocaml/ocamlbuild#14). The only symlinks solvuu-build creates are for .ocamlinit, .merlin, and .install, which you really do want to do. If for some reason, you disagree even with those, note that we do the symlinking in the generated _build/project.mk. You could go further with my recommendation above about writing your own makefile. Notice that _build/project.mk also isn't all that complicated. You could write your own. Of course, again, if you think what you want should be the default, then please go ahead and make the case for it.

I agree with you on which symlinks should be created and which ones shouldn't be. However, for a simple application solvuu-build does create a .byte symlink. Has this been fixed recently?

agarwal commented 7 years ago

for a simple application solvuu-build does create a .byte symlink. Has this been fixed recently?

Right, that's a bug. Thanks for pointing it out. 00da2c99ba6404982e9159c48fff622543cadbb4 now uses -no-links in the default solvuu.mk file provided.

agarwal commented 7 years ago

Your original question was "Is it possible to specify additional arguments to ocamlbuild?", and the answer is basically no. The call to ocamlbuild is configured in the provided solvuu.mk file. This file is static and we can't generate it because it is the starting point for make to know what to do. Thus, the only way to modify the call to ocamlbuild is to avoid solvuu.mk by writing your own 4 line Makefile instead of the recommended 1 line Makefile.

However, some of the flags you requested aren't actually about ocamlbuild. They are really ocaml flags, and we should add them to the definition of a Project.lib and Project.app. The -color and -warn-error ones are straightforward and I'll add those.

For optimize(2), we first need to add support for all the underlying flags, which is tedious but easy. Given that is done, you could easily define your own wrapper around Project.lib that applies all the flags implied by optimize(2).

We could provide such a function within solvuu-build, but I'm unsure what to call it. Something like Project.lib_optimize2, but is "optimize(2)" a term recognized by the compiler team, or is it an ocamlbuild specific concept?

agarwal commented 7 years ago

or within myocamlbuild.ml

Oh right, there is that. So in theory we could it. We could add ocamlbuild arguments to Project.basic1, and make whatever call ocamlbuild requires to set the corresponding command line flag. I'm still not sure it's a good idea. Writing your own 4 line Makefile seems easy enough, and avoids making Project.basic1's signature dependent on ocamlbuild's constructs. (I can imagine replacing ocamlbuild's rule engine some day, and ideally no code would break.) Also I'm not keen to figure out what the code is to do the equivalent of the command line flag, and whether that code should be added to Before_options or After_hygiene, etc.

agarwal commented 7 years ago

5392ae677a5db8f3a8bf683ce9701a13ba5b0975 added support for -color and -warn-error.

copy commented 7 years ago

I think this solution is good, it supports all flags that I need.

For optimize(2), we first need to add support for all the underlying flags, which is tedious but easy. Given that is done, you could easily define your own wrapper around Project.lib that applies all the flags implied by optimize(2).

We could provide such a function within solvuu-build, but I'm unsure what to call it. Something like Project.lib_optimize2, but is "optimize(2)" a term recognized by the compiler team, or is it an ocamlbuild specific concept?

Actually the ocamlbuild manual is a bit misleading, optimize(2) only translates to -O2, which is a flag for ocamlopt and documented here.

agarwal commented 7 years ago

I finally read the Flambda chapter and added the main flags corresponding to it in 01975187944f15c694844dbd6fed8f90a810bee9. I believe that resolves this issue, so closing. Feel free create new issues for additional flags you'd like supported.

agarwal commented 7 years ago

The -no-links flag introduced other problems. I pushed an alternative workaround. See #47.