Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005951OCamlOCamlbuild (the tool)public2013-03-14 23:082014-07-30 20:52
ReporterDanGrayson 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version4.00.0 
Target Version4.03.0+devFixed in Version 
Summary0005951: ocamlbuild is incompatible with -cflags -S
Descriptionocamlbuild, when building a native executable, builds both the *.cmo files and the *.cmx files. It ensures that both were compiled with the same command line options by remaking both whenever the command line options change. But there is a misfeature associated with the option -cflags -S. That is the flag that tells ocamlopt not to delete the intermediate *.s assembler files. The problem is that ocamlbuild insists on passing the flag -S also to ocamlc, and ocamlc doesn't accept the flag and returns an error code. The upshot is that there is no way to use ocamlbuild in such a way that the assembly code can be examined!
Steps To Reproduce   touch foo.ml
   ocamlbuild -cflags -S foo.cmx
TagsNo tags attached.
Attached Files

- Relationships
related to 0005549assigned add tags for all build-related ocamlbuild command-line options 

-  Notes
(0008968)
meyer (developer)
2013-03-14 23:38
edited on: 2013-03-14 23:38

Command line options that have different meaning or don't exist in both versions of the compiler should not be supplied directly to ocamlbuild. The usual way of making ocamlbuild to use different set of command line options based on the compiler chosen is to use tags. Your example could be:

myocamlbuild.ml:
flag ["ocaml"; "compile"; "native"] (A "-S");;

While I agree that we could have `s' tag to do it, and maybe also -optflag option, here normally at the moment I can't see any immediate gain of doing that in the core of ocamlbuild, but I am open for any suggestions.

(0008969)
DanGrayson (reporter)
2013-03-15 00:06

Thanks! But I can't make it work. And the reference manual mentions myocamlbuild.ml in just one non-useful place.

$ ocamlbuild -I src -I src/tactics -lflags -g -yaccflag -v -menhir 'menhir --explain --error-recovery' -use-menhir -cflags -g,-annot,-w,@8 src/checker.native
/Users/dan/src/coq-builder/bin/ocamlopt.opt -I /Users/dan/src/coq-builder/lib/ocaml/ocamlbuild unix.cmxa /Users/dan/src/coq-builder/lib/ocaml/ocamlbuild/ocamlbuildlib.cmxa myocamlbuild.ml /Users/dan/src/coq-builder/lib/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
+ /Users/dan/src/coq-builder/bin/ocamlopt.opt -I /Users/dan/src/coq-builder/lib/ocaml/ocamlbuild unix.cmxa /Users/dan/src/coq-builder/lib/ocaml/ocamlbuild/ocamlbuildlib.cmxa myocamlbuild.ml /Users/dan/src/coq-builder/lib/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
File "myocamlbuild.ml", line 1, characters 0-4:
Error: Unbound value flag
(0008970)
DanGrayson (reporter)
2013-03-15 00:09

PS: Simpler than fixing ocamlbuild to filter -S from the command line so ocamlc doesn't get it would be to make ocamlc accept -S and do nothing.
(0008971)
meyer (developer)
2013-03-15 00:11

You have to open Ocamlbuild_plugin.
(0008972)
DanGrayson (reporter)
2013-03-15 13:09

Thanks, opening Ocamlbuild_plugin worked.

It might be a good idea to add information about myocamlbuild to the reference manual.
(0008974)
meyer (developer)
2013-03-17 01:29

Actually, it might be going to be good to add -optflag command line option.
(0008975)
gasche (developer)
2013-03-17 17:12

Wojciech, I'm assigning you the bug because you've be very helpful with the OCamlbuild development in the past, so I assume you may be interested in tackling this one as well. Feel free to de-assign if you're overloaded.



The problem is also present with all other flags that ocamlopt supports but ocamlc doesn't, such as -inline.

I'm not sure however that -optflags is the right way to go. In some sense the distinction between ocamlc and ocamlopt is *orthogonal* to the distinction between compilation and linking (as those compilers are also invoked for linking). Assuming we may have options supported by ocamlopt but not ocamlc for linking as well as compilation, splitting flags between -cflags, -lflags and -optflags seems awkward.

We could have -optcflags and -optlflags. But wouldn't be simpler if ocamlbuild took care of checking which flags can be passed to ocamlc (and ocamldep, etc.) and not pass the other?

The behavior I would expect is:
- have "ocamlbuild -cflags -inline,999 foo.native" work out of the box
- (optionally) have "ocamlbuild -cflags -inline,999 foo.byte" warn me about -inline not being meaningful in this context


Finally, in the specific case of the -S option, I'm not sure what's the best interface from ocamlbuild. I would rather have expected "ocamlbuild foo.s" to produce the assembly file, rather than "ocamlbuild -cflags -S foo.native". This could suggest having new targets for -S, and also possibly other temporary output (I would appreciate a .cmm target for example).
This is fairly orthogonal and I think we want both (because the target feature has smaller self-discoverability, so we should expect our users to try "-clfags -S" first and support that). Do you think that needs a separate bugtracker item?
(0008981)
meyer (developer)
2013-03-17 18:30

Gabriel, thanks for looking into that.

> I'm not sure however that -optflags is the right way to go. In some
> sense the distinction between ocamlc and ocamlopt is *orthogonal* to
> the distinction between compilation and linking (as those compilers
> are also invoked for linking). Assuming we may have options supported
> by ocamlopt but not ocamlc for linking as well as compilation,
> splitting flags between -cflags, -lflags and -optflags seems awkward.

I agree.

> We could have -optcflags and -optlflags. But wouldn't be simpler if
> ocamlbuild took care of checking which flags can be passed to ocamlc
> (and ocamldep, etc.) and not pass the other?

That makes sense, however then ocamlbuild will not be anymore agnostic, and just substitute the options. To solve this problem, options should just create the right flags for tags. Maybe we then should have more generic -- dynamic way of specifying options -- but I suppose the best would be to keep the backward compatibility.

> The behavior I would expect is:
> - have "ocamlbuild -cflags -inline,999 foo.native" work out of the box
> - (optionally) have "ocamlbuild -cflags -inline,999 foo.byte" warn me about -inline not being meaningful in this context

> Finally, in the specific case of the -S option, I'm not sure what's
> the best interface from ocamlbuild. I would rather have expected
> "ocamlbuild foo.s" to produce the assembly file, rather than
> "ocamlbuild -cflags -S foo.native". This could suggest having new
> targets for -S, and also possibly other temporary output (I would
> appreciate a .cmm target for example).

Makes sense.

So we have two pieces to improve ocamlbuild:
- drop mutable options and do as much as possible using standard ocamlbuild interface. And make people aware of that when using options inside plugins.
- support more targets (.s, .cmm, .lambda, etc.)

> This is fairly orthogonal and I think we want both (because the target
> feature has smaller self-discoverability, so we should expect our
> users to try "-clfags -S" first and support that). Do you think that
> needs a separate bugtracker item?

No, no need separate issue, at the moment, but perhaps your opinion matters here about the implementation detail I highlighted above.
(0008982)
gasche (developer)
2013-03-17 18:41

I'm not sure how your suggestion for options would work. Are you suggesting, for example, to map "-cflag g -lflag -g" into setting the "debug" tag compilation-wide?
How does that relate to http://caml.inria.fr/mantis/view.php?id=5549 [^] ?


Another cheap option would be to change ocamlc to accept flags only supported by ocamlopt, and ignore them with a warning instead of failing. It's a bit quick&dirty, but it could also be useful in other scenarios: sometimes I want to replace "ocamlopt" by "ocamlc" in a command-line for a quick test, and I'm annoyed when it fails because I used -inline.
(0008983)
meyer (developer)
2013-03-17 18:50
edited on: 2013-03-17 18:52

>I'm not sure how your suggestion for options would work. Are you suggesting,
> for example, to map "-cflag g -lflag -g" into setting the "debug" tag
> compilation-wide?

No. Almost, it would just set S("-g") for the right set of tags:

let g_option_handler = fun () => flag ["compile"] (S("-g"); flag ["link"] (S("-g")

and I think treating options as flags is most consistent way. I'd prefer not doing too much logic using custom ocaml code. Just don't implement it as a simple concatenation of the sequence of flags for the compiler.

(0008987)
meyer (developer)
2013-03-17 19:16

> How does that relate to http://caml.inria.fr/mantis/view.php?id=5549 [^] [^] ?

It looks that we've drawn the same implementation specific conclusions, I've missed this bug report, sorry.
(0008988)
meyer (developer)
2013-03-17 19:56

So the way how it's implemented at the moment, is that Options module collect the options. Then Ocaml_specific sets appropriate compilation environment based on that.

The way I'd like to see is to reduce options to bare minimum of options that the compilation doesn't dependent on. Then use is consistently in the API. So Ocaml_specific would add options and flags, but will not run any conditional code. Maybe just making the user aware about tags_with_option is also another good idea which we could consider in the end.
(0009863)
meyer (developer)
2013-07-26 10:36

Changed target release to 4.01, especially latest comments are valid, making the flags work with tags nicer.

- Issue History
Date Modified Username Field Change
2013-03-14 23:08 DanGrayson New Issue
2013-03-14 23:38 meyer Note Added: 0008968
2013-03-14 23:38 meyer Note Edited: 0008968 View Revisions
2013-03-15 00:06 DanGrayson Note Added: 0008969
2013-03-15 00:09 DanGrayson Note Added: 0008970
2013-03-15 00:11 meyer Note Added: 0008971
2013-03-15 13:09 DanGrayson Note Added: 0008972
2013-03-17 01:29 meyer Note Added: 0008974
2013-03-17 17:12 gasche Note Added: 0008975
2013-03-17 17:12 gasche Assigned To => meyer
2013-03-17 17:12 gasche Status new => acknowledged
2013-03-17 18:30 meyer Note Added: 0008981
2013-03-17 18:41 gasche Note Added: 0008982
2013-03-17 18:50 meyer Note Added: 0008983
2013-03-17 18:52 meyer Note Edited: 0008983 View Revisions
2013-03-17 19:16 meyer Note Added: 0008987
2013-03-17 19:56 meyer Note Added: 0008988
2013-03-18 03:38 meyer Relationship added related to 0005549
2013-07-12 14:16 doligez Target Version => 4.02.0+dev
2013-07-12 18:15 doligez Target Version 4.02.0+dev => 4.01.1+dev
2013-07-26 10:36 meyer Note Added: 0009863
2014-01-21 11:54 doligez Assigned To meyer =>
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev
2014-07-30 20:52 doligez Target Version 4.02.0+dev => 4.03.0+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker