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

modes not respected in combination with library with public_name #3467

Open
jberdine opened this issue May 7, 2020 · 10 comments
Open

modes not respected in combination with library with public_name #3467

jberdine opened this issue May 7, 2020 · 10 comments

Comments

@jberdine
Copy link
Contributor

jberdine commented May 7, 2020

Expected Behavior

With a dune file such as:

(env
 (_
  (flags ())))

(subdir
 lib
 (library
  (name test_lib)
  (public_name test_package.test_lib)
  (modes native)))

(executable
 (name test_exe)
 (public_name test_exe)
 (package test_package)
 (libraries test_lib)
 (modes native))

I expect that executing dune build will not run ocamlc on implementation files. I realize that it might compile interface files with ocamlc even when building for native code only.

Actual Behavior

In the case above, dune build does run ocamlc on implementation files. Curiously, if (public_name test_package.test_lib) is removed, it does not.

Reproduction

Here is a small project that shows this: dune-bc-test.tar.gz

Specifications

  • Version of dune (output of dune --version): 2.5
  • Version of ocaml (output of ocamlc --version): 4.08.1
  • Operating system (distribution and version): macos 10.14.6
@rgrinberg
Copy link
Member

Try writing an empty mil for your executable. Does it fix the problem?

@jberdine
Copy link
Contributor Author

jberdine commented May 8, 2020

It already has one. :-)

@ghost
Copy link

ghost commented May 11, 2020

It's the same problem as described in #3182. Adding a public name pulls in the cmt files since they are installed, and cmt files are produced by ocamlc.

Also, this time I'm really adding the topic to the next meeting (I forgot it last time): https://github.com/ocaml/dune/wiki/dev-meeting-next

@jberdine
Copy link
Contributor Author

Ah, I see, thanks.

For context, in the actual usage this example is reduced from, the library is 'public' just so that a directory of the repo can be used from several others. That is, the 'install' that we rely on is only within dune-land, and need not make it to opam-land. In case that helps or is relevant.

Also, the motivation for not compiling with ocamlc is one to reduce build times, but mostly to avoid getting duplicate warnings from both ocamlc and ocamlopt. Turning off warnings in ocamlc_flags doesn't work since .mli files are only compiled with ocamlc. So for this particular case, a way to pass different flags to ocamlc when compiling .ml and .mli would be a workaround.

@ghost
Copy link

ghost commented May 12, 2020

Hmm, if you only use the public library only inside the workspace but don't install it, then the cmt files shouldn't be pulled in 🤔

@jberdine
Copy link
Contributor Author

Ah, but a dune "install" is needed to version-stamp the binaries, so that is always done (except in watch mode).

@ghost
Copy link

ghost commented May 13, 2020

Note that you can also version-stamp the binaries by promoting them to the source tree via:

(executable
 (name foo)
 (promote unitl_clean)
 ...)

That only works if you are using a single build context though.

@ghost
Copy link

ghost commented Oct 1, 2020

@jberdine BTW, while looking at #3701 we just remembered that Dune does caching of error messages to avoid getting the same error twice when compiling in both bytecode and native code. So normally you already should not get the same warnings and errors twice.

@jberdine
Copy link
Contributor Author

jberdine commented Oct 1, 2020

Interesting. I don't know if I always see potential duplicate messages, but I definitely started out hunting this due to seeing duplicated messages in practice. There might be something nontrivial in the definition of "duplicated" though, I'm not sure. Is the scope of the cache the whole workspace? The duplicates I saw may have been coming from different contexts (with different ppx configs leading to different preprocessed code). Is there any info on the caching mechanism that you can point me to that would help me to find a small repro more efficiently than a monkey at a keyboard? :-)

@ghost
Copy link

ghost commented Oct 5, 2020

Just the code really, the caching is done there:

let hash = Digest.generic msg in
if not (Digest.Set.mem !reported hash) then (

If one message as one more trailing whitespace, they won't be deduplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants