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

Build executable for either native or byte code in dune #5443

Closed
shakthimaan opened this issue Feb 16, 2022 · 2 comments
Closed

Build executable for either native or byte code in dune #5443

shakthimaan opened this issue Feb 16, 2022 · 2 comments

Comments

@shakthimaan
Copy link

shakthimaan commented Feb 16, 2022

I have the dune file for building decompress benchmarks at https://github.com/ocaml-bench/sandmark/blob/main/benchmarks/decompress/dune.

(executable
 (name test_decompress)
  (modules test_decompress)
  (libraries bigstringaf checkseum.ocaml decompress.zl))

(executable
 (name test_decompress_multicore)
  (modules test_decompress_multicore)
  (libraries bigstringaf checkseum.ocaml decompress.zl domainslib))

(alias (name buildbench)
       (deps test_decompress.exe))
(alias (name multibench_parallel)
       (deps test_decompress.exe test_decompress_multicore.exe))

I would like to now build either native or byte code executables based on a runtime flag. I tried adding an alias for bytebench as follows:

(executable
 (name test_decompress)
  (modules test_decompress)
  (libraries bigstringaf checkseum.ocaml decompress.zl))

(executable
 (name test_decompress_multicore)
  (modules test_decompress_multicore)
  (libraries bigstringaf checkseum.ocaml decompress.zl domainslib))

(executable
 (name test_decompress_byte)
  (modes (byte exe))
  (modules test_decompress)
  (libraries bigstringaf checkseum.ocaml decompress.zl domainslib))

(alias (name buildbench)
       (deps test_decompress.exe))
(alias (name multibench_parallel)
       (deps test_decompress.exe test_decompress_multicore.exe))
(alias (name bytebench)
       (deps test_decompress.exe))

I get the following error:

Error: Module "Test_decompress" is used in several stanzas:
- benchmarks/decompress/dune:1
- benchmarks/decompress/dune:11
To fix this error, you must specify an explicit "modules" field in every
library, executable, and executables stanzas in this dune file. Note that
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.

If I copy test_decompress to a test_decompress_byte file and use it with the new alias, it runs fine. I would like to avoid duplicating the file just to use a different module name.

Is there a way to use the same module to build for native and/or byte code executables?

References

  1. 'Variables for selecting builds` (variables for selecting builds based on compiler/arch/os #838) is related.
  2. Analyse bytecode performance. Analyse bytecode performance ocaml-bench/sandmark#282
@bobot
Copy link
Collaborator

bobot commented Feb 18, 2022

As described in https://dune.readthedocs.io/en/stable/dune-files.html#linking-modes the compilation modes are not exclusive, so if you use: (modes native byte) you can run both dune exec -- src/bin/main.exe and dune exec -- src/bin/main.bc. Is it sufficient?

@shakthimaan
Copy link
Author

I am able to now build the sequential benchmarks in Sandmark in byte mode with the following PR ocaml-bench/sandmark#298. This issue can be closed.

Thanks!

@nojb nojb closed this as completed Feb 28, 2022
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

3 participants