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

sub-sub-module building fails for native code compilation #5084

Closed
vicuna opened this Issue Jun 22, 2010 · 9 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

vicuna commented Jun 22, 2010

Original bug ID: 5084
Reporter: mww
Assigned to: @protz
Status: closed (set by @xavierleroy on 2015-12-11T18:04:33Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.12.0+beta1 or 3.12.0+rc1
Fixed in version: 4.00.0+dev
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Monitored by: abdallah mehdi @ygrek

Bug description

when building a sub-sub-module with the for-pack option, compilation fails ("was not compiled with the for-pack subXX option)

This works on 3.11.2 -- for 3.12.0+beta1 only when building bytecode..

Additional information

this is Mac OS X 10.6.4/amd64;

the attached tarball has a sub-sub module and demonstrates the error:

ocamlbuild main.native

compiles and works with 3.11.2 but fails on 3.12.0+beta with:

File "sub1.cmx", line 1, characters 0-1:
Error: File sub1/sub2.cmx
was not compiled with the `-for-pack Sub1' option
Command exited with code 1.
Compilation unsuccessful after building 9 targets (0 cached) in 00:00:00.

File attachments

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jul 23, 2010

Comment author: mww

This is still the case with 3.12.0+rc1

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 13, 2010

Comment author: mww

This is still the case with 3.12.0 (release)

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 21, 2010

Comment author: @xclerc

My understanding of this report is that it is not an ocamlbuild-specific problem.
Indeed, contrary to the bytecode compiler, the native compiler does not allow
one to "compose" pack operations. Moreover, the native compiler requires (where
the bytecode one only accepts) the '-for-pack' option to specify the final module
into which the compiled unit will be packed.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 4, 2011

Comment author: mww

It didn't occur to me that this could be the native compilers fault -- why would this feature get removed in 3.12.0?

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 12, 2011

Comment author: abdallah

This is still the case with 3.12.1 (release)

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Sep 16, 2011

Comment author: @protz

GOOD:

commit 71ba631c28d7398cb78a5fcfcb1c1b00b8472722
Author: frisch frisch@f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Date: Wed Jan 20 12:48:34 2010 +0000

Fix ocamldep for 1st class modules.

git-svn-id: file:///net/yquem/devel/caml/svn/ocaml/trunk@9538 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

BAD:

commit ee5f671c834da0eee1b28412313628556f9ddc10
Author: xclerc xclerc@f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Date: Mon Jan 25 13:47:28 2010 +0000

Infrastructure for test suite.


git-svn-id: file:///net/yquem/devel/caml/svn/ocaml/trunk@9562 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

These two revisions are approximately 7 commits apart. It's hard to bisect in that range because someone (I'm looking at you xclerc ;-)) forgot to add files for ocamlbuild parameterized tags, so I basically can't compile in that range.

I'm going to try right before and right after the parameterized tags stuff, just to confirm.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Sep 16, 2011

Comment author: @protz

GOOD:

commit d71b23f614d913a84ab75f6d83feb499a787b4d9
Author: doligez doligez@f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Date: Fri Jan 22 12:48:24 2010 +0000

clean up spaces and tabs

git-svn-id: file:///net/yquem/devel/caml/svn/ocaml/trunk@9547 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

BAD:
commit 15ff52580e4b985103fe4fa9731c6123c2796f0b
Author: xclerc xclerc@f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Date: Fri Jan 22 14:36:57 2010 +0000

Support for parametrized tags (N. Pouillard et al.)


git-svn-id: file:///net/yquem/devel/caml/svn/ocaml/trunk@9548 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

with the files from

commit 87cd319c69653b747ea3ae40c527c145049517d0
Author: xclerc xclerc@f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Date: Mon Jan 25 08:16:23 2010 +0000

Added some missing files for parameterized tags.


git-svn-id: file:///net/yquem/devel/caml/svn/ocaml/trunk@9558 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

So the problem is in one of the two commits above.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented May 7, 2012

Comment author: @protz

Mantis erased my comment by accident. How I hate you Mantis!

This is definitely a bug in OCamlbuild that was introduced when we committed parameterized flags. Here's the output of ocamlbuild on 3.11

/usr/local/bin/ocamldep.opt -modules main.ml > main.ml.depends
/usr/local/bin/ocamldep.opt -modules sub1/sub2/sub3.ml > sub1/sub2/sub3.ml.depends
/usr/local/bin/ocamlc.opt -c -I sub1/sub2 -o sub1/sub2/sub3.cmo sub1/sub2/sub3.ml
/usr/local/bin/ocamlc.opt -pack sub1/sub2/sub3.cmo -o sub1/sub2.cmo
/usr/local/bin/ocamlc.opt -pack sub1/sub2.cmo -o sub1.cmo
/usr/local/bin/ocamlc.opt -c -o main.cmo main.ml
/usr/local/bin/ocamlopt.opt -c -for-pack Sub1.Sub2 -I sub1/sub2 -o sub1/sub2/sub3.cmx sub1/sub2/sub3.ml
touch sub1/sub2.mli ; if /usr/local/bin/ocamlopt.opt -pack -I sub1/sub2 sub1/sub2/sub3.cmx -for-pack Sub1 -o sub1/sub2.cmx ; then rm -f sub1/sub2.mli ; else rm -f sub1/sub2.mli ; exit 1; fi
touch sub1.mli ; if /usr/local/bin/ocamlopt.opt -pack -I sub1 sub1/sub2.cmx -o sub1.cmx ; then rm -f sub1.mli ; else rm -f sub1.mli ; exit 1; fi
/usr/local/bin/ocamlopt.opt -c -o main.cmx main.ml
/usr/local/bin/ocamlopt.opt sub1.cmx main.cmx -o main.native

Here is the output on trunk:

usr/local/bin/ocamldep.opt -modules main.ml > main.ml.depends
/usr/local/bin/ocamldep.opt -modules sub1/sub2/sub3.ml > sub1/sub2/sub3.ml.depends
/usr/local/bin/ocamlc.opt -c -I sub1/sub2 -o sub1/sub2/sub3.cmo sub1/sub2/sub3.ml
/usr/local/bin/ocamlc.opt -pack sub1/sub2/sub3.cmo -o sub1/sub2.cmo
/usr/local/bin/ocamlc.opt -pack sub1/sub2.cmo -o sub1.cmo
/usr/local/bin/ocamlc.opt -c -o main.cmo main.ml
/usr/local/bin/ocamlopt.opt -c -for-pack Sub1.Sub2 -I sub1/sub2 -o sub1/sub2/sub3.cmx sub1/sub2/sub3.ml
touch sub1/sub2.mli ; if /usr/local/bin/ocamlopt.opt -pack -I sub1/sub2 sub1/sub2/sub3.cmx -o sub1/sub2.cmx ; then rm -f sub1/sub2.mli ; else rm -f sub1/sub2.mli ; exit 1; fi

  • touch sub1/sub2.mli ; if /usr/local/bin/ocamlopt.opt -pack -I sub1/sub2 sub1/sub2/sub3.cmx -o sub1/sub2.cmx ; then rm -f sub1/sub2.mli ; else rm -f sub1/sub2.mli ; exit 1; fi
    File "sub1/sub2.cmx", line 1:
    Error: File sub1/sub2/sub3.cmx
    was not compiled with the `-for-pack Sub2' option
    Command exited with code 1.

Please note that in the latter case, the -for-pack argument is missing, on the line that starts with "touch".

Here's what happens (beware, this is just a theory).

The code that is responsible for adding the -for-pack flag to the command line is in ocaml_specific.ml:454

let () =
pflag ["ocaml"; "native"; "compile"] "for-pack"
(fun param -> S [A "-for-pack"; A param]);

However,

protzenk@sauternes:/tmp/exemple $ ocamlbuild -show-tags sub1/sub2.cmx
Tags for "sub1/sub2.cmx":
{. extension:cmx, file:sub1/sub2.cmx, for-pack(Sub1), native, ocaml,
pkg_unix, quiet, traverse .}

That is to say, when ocamlbuild builds the sub2.cmx file, there should be a -for-pack flag, but since sub2.cmx does not have a "compile" tag, the -for-pack flag is not added. Xclerc, do you have any idea how we could add an extra line in ocaml_specific.ml that triggers the -for-pack flag when building a .cmx? Adding another rule that matches on "extension:cmx" instead of "compile" doesn't work (the -for-pack flag gets passed as an argument to -pp when building ocamlbuild itself...).

In this case, the -for-pack tag is present, so I think the least we could do is honor the user's instructions and actually pass the -for-pack flag to the compiler. How do we write this in ocamlbuild?

Thanks,

jonathan

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented May 7, 2012

Comment author: @protz

r12437 and r12438, on 4.00 and trunk respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.