caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Telling Ocamlbuild to link seemingly unreferenced modules
@ 2011-05-06 14:34 Dario Teixeira
  2011-05-06 15:38 ` Gabriel Scherer
  0 siblings, 1 reply; 4+ messages in thread
From: Dario Teixeira @ 2011-05-06 14:34 UTC (permalink / raw)
  To: caml-list

Hi,

I have a couple of plugin modules (say, "Foo.ml" and "Bar.ml") which become
known to the main programme solely because they register themselves upon
initialisation.  However, because there is no implicit dependency between
the main programme and these plugins, when compiling with Ocamlbuild they
are not linked in.  So what's the cleanest way of telling Ocamlbuild that
these plugins should also be compiled and linked together with the main
programme?

Thanks in advance!
Dario



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Telling Ocamlbuild to link seemingly unreferenced modules
  2011-05-06 14:34 [Caml-list] Telling Ocamlbuild to link seemingly unreferenced modules Dario Teixeira
@ 2011-05-06 15:38 ` Gabriel Scherer
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriel Scherer @ 2011-05-06 15:38 UTC (permalink / raw)
  To: Dario Teixeira; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1654 bytes --]

Hello,

I'm not exactly sure this is a complete answer to your problem (I'm not
familiar with plugin linking and all that), but here is a small test:

a.ml:

> let () = print_endline "I'm 'a'!"
>

b.ml:

> let () = print_endline "I'm 'b'!"
>

myocamlbuild.ml:

> open Ocamlbuild_plugin
>
> let _ = dispatch begin function
>   | After_rules ->
>     dep ["use_b"] ["b.cmo"]
>   | _ -> ()
> end
>

I i run "ocamlbuild a.byte", then executing a.byte will only print "I'm
'a'!".

If I add the following _tags:
  "a.byte": use_b

Then a.byte will print both "I'm 'a'!" and "I'm 'b'!".

I don't know the exact semantics of this 'dispatch' function (After_rules,
etc.), I just imitated it from an other project doing a similar thing. I
suppose you could find more detailed answers in the ocamlbuild
documentation.

Hope it helps.

On Fri, May 6, 2011 at 4:34 PM, Dario Teixeira <darioteixeira@yahoo.com>wrote:

> Hi,
>
> I have a couple of plugin modules (say, "Foo.ml" and "Bar.ml") which become
> known to the main programme solely because they register themselves upon
> initialisation.  However, because there is no implicit dependency between
> the main programme and these plugins, when compiling with Ocamlbuild they
> are not linked in.  So what's the cleanest way of telling Ocamlbuild that
> these plugins should also be compiled and linked together with the main
> programme?
>
> Thanks in advance!
> Dario
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

[-- Attachment #2: Type: text/html, Size: 3004 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Telling Ocamlbuild to link seemingly unreferenced modules
@ 2011-05-06 19:34 Dario Teixeira
  0 siblings, 0 replies; 4+ messages in thread
From: Dario Teixeira @ 2011-05-06 19:34 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

Hi,

> Thanks for the input, Gabriel.  Directly hacking the
> myocamlbuild.ml file
> does work, and the process may be even further simplified
> with just a
> couple of lines:
> 
> dep ["ocaml"; "link"; "native"] ["foo.cmx"];
> dep ["ocaml"; "link"; "byte"] ["foo.cmo"];

I may have spoken too soon regarding this problem being solved.  The issue
now is that foo.cmx is linked *after* the "main" module, main.ml.  I thought
I could influence Ocamlbuild's dependency graph by adding the following
extra after_rule:

dep ["ocaml"; "ocamldep"; "file:main.ml"] ["foo.ml"];

However, this does not seem to work.  Any ideas on how I can convince
Ocamlbuild to link foo.cmx and to do it before main.cmx?

On a related note, if there's one tool in the Ocaml ecosystem that
desperately needs a manual is Ocamlbuild.  I find myself mostly
cargo-culting when I interact with it: the documentation is sparse
and all over the place, making it very difficult to grok how the
whole fits together. /end rant.

Best regards,
Dario Teixeira



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Telling Ocamlbuild to link seemingly unreferenced modules
@ 2011-05-06 17:09 Dario Teixeira
  0 siblings, 0 replies; 4+ messages in thread
From: Dario Teixeira @ 2011-05-06 17:09 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

Hi,

> I'm not exactly sure this is a complete answer to your problem (I'm not > familiar with plugin linking and all that), but here is a small test:
>
> (...)
>
> I don't know the exact semantics of this 'dispatch' function
> (After_rules, etc.), I just imitated it from an other project doing a
> similar thing. I suppose you could find more detailed answers in the
> ocamlbuild documentation.

Thanks for the input, Gabriel.  Directly hacking the myocamlbuild.ml file
does work, and the process may be even further simplified with just a
couple of lines:

dep ["ocaml"; "link"; "native"] ["foo.cmx"];
dep ["ocaml"; "link"; "byte"] ["foo.cmo"];

However, I still wonder if there's some other incantation that would tell
Ocamlbuild to link in a given module without requiring tweaking myocamlbuild.ml.
Also, I suspect it is possible to further condense the two lines above
into a single one.

cheers,
Dario



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-06 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-06 14:34 [Caml-list] Telling Ocamlbuild to link seemingly unreferenced modules Dario Teixeira
2011-05-06 15:38 ` Gabriel Scherer
2011-05-06 17:09 Dario Teixeira
2011-05-06 19:34 Dario Teixeira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).