Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] ocamlbuild: ml -> cmx & cmi & o ?

2 views
Skip to first unread message

Josh Berdine

unread,
Oct 15, 2008, 7:01:02 AM10/15/08
to caml...@yquem.inria.fr
Hi,

I observe that ocamlbuild does not build cmx cmi and o files from a ml file (which has no associated mli) directly. Do others see different behavior? Instead it builds cmo and cmi from the ml using ocamlc, and then builds the cmx and o files from there using ocamlopt. Is there a reason I'm missing that ocamlbuild does not have a default rule for this case, using only one call to ocamlopt? If so, is there an easy way to do this with a plugin?

Cheers, Josh

Romain Bardou

unread,
Oct 16, 2008, 4:30:24 AM10/16/08
to Josh Berdine, caml...@yquem.inria.fr

I observe the same behavior. I think it's just a matter of reordering
the rules in ocaml_specific.ml, as the following plug-in solves the
problem thanks to "~insert: `top":

open Ocamlbuild_plugin

let () = dispatch begin function
| After_rules ->
rule "ml -> cmx"
~dep: "%.ml"
~prods: ["%.cmx"; "%.o"; "%.cmi"]
~insert: `top
begin fun env _ ->
let ml = env "%.ml" in
Cmd(S[!Options.ocamlopt; A "-c"; P ml])
end
| _ -> ()
end

--
Romain Bardou

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Nicolas Pouillard

unread,
Oct 16, 2008, 4:44:05 AM10/16/08
to romain.bardou, Caml_mailing list
Excerpts from romain.bardou's message of Thu Oct 16 10:30:49 +0200 2008:

> > I observe that ocamlbuild does not build cmx cmi and o files from a ml
> > file (which has no associated mli) directly. Do others see different
> > behavior? Instead it builds cmo and cmi from the ml using ocamlc, and
> > then builds the cmx and o files from there using ocamlopt. Is there a
> > reason I’m missing that ocamlbuild does not have a default rule for this
> > case, using only one call to ocamlopt? If so, is there an easy way to
> > do this with a plugin?

There is a deep reason for this, the short answer is:

"if you want native-compilation only, then all your .ml files must have a
.mli"

Indeed ocamlbuild only generates .cmi from .ml using ocamlc, this is to avoid
conflicting defaulting rules in the engine.

> I observe the same behavior. I think it's just a matter of reordering
> the rules in ocaml_specific.ml, as the following plug-in solves the
> problem thanks to "~insert: `top":
>
> open Ocamlbuild_plugin
>
> let () = dispatch begin function
> | After_rules ->
> rule "ml -> cmx"
> ~dep: "%.ml"
> ~prods: ["%.cmx"; "%.o"; "%.cmi"]
> ~insert: `top
> begin fun env _ ->
> let ml = env "%.ml" in
> Cmd(S[!Options.ocamlopt; A "-c"; P ml])
> end
> | _ -> ()
> end

I won't recommend that.

--
Nicolas Pouillard aka Ertai

Romain Bardou

unread,
Oct 16, 2008, 4:53:32 AM10/16/08
to Nicolas Pouillard, Caml_mailing list
> There is a deep reason for this, the short answer is:
>
> "if you want native-compilation only, then all your .ml files must have a
> .mli"
>
> Indeed ocamlbuild only generates .cmi from .ml using ocamlc, this is to avoid
> conflicting defaulting rules in the engine.

Are conflicting rules a problem?

--
Romain Bardou

0 new messages