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

Compile flags #3679

Closed
wants to merge 8 commits into from
Closed

Compile flags #3679

wants to merge 8 commits into from

Conversation

lubegasimon
Copy link
Collaborator

addressing #766 .

@lubegasimon lubegasimon requested review from a user and shonfeder August 5, 2020 13:56
@lubegasimon lubegasimon force-pushed the compile-flags branch 2 times, most recently from 4652398 to 5874753 Compare August 5, 2020 17:50
Copy link
Collaborator

@shonfeder shonfeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

I think som irrelevant commits may have slipped in here, and we need to work out the tests, but it looks like we're parsing the field as desired!

@@ -1,4 +1,5 @@
open Printf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be part of the PR.

Copy link
Collaborator Author

@lubegasimon lubegasimon Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, it should not be part of it @shonfeder, am not so certain why such git history reflects in here, I have done git reset <commitID>, but all in vain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd either rebase just the relevant changes onto master or create a fresh branch off of master and just cherry pick in the relevant commits from here.


We run the inline tests with a program that passes in specifc compile flags:

$ export OCAMLPATH=$PWD/_install/lib; dune runtest --root dune-file-compile-flags
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not %100 sure what the best way to test this will be, but I think something like the following might work:

  • Create a new test file under the inline_tests directory called something like /compiler-flags.t/run.t
  • Set up a backend runner there that just works to detect whether certain conspicuous compiler flags have been set
  • Set up one or two example targets that build the tests using different compiler flags

Do you have any thoughts for a more elegant test set up @jeremiedimino?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems about right. You could also pass a flag that you are sure the compiler doesn't accept and observe the compilation failure.

BTW, the above test is using the OCAMLPATH trick to test that inline test backends work even when installed on the system. But since we already tested that, we don't need to use this method again and we can instead use a locally defined backend. So the shell command could just be: dune runtest dune-file-compile-flags.

… tests

Signed-off-by: lubegasimon <lubegasimon73@gmail.com>
(Ocaml_flags.of_list [ "-w"; "-24"; "-g" ])
~compile_flags:
(Ocaml_flags.append_common
(Super_context.ocaml_flags sctx ~dir lib.buildable.flags)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the problem. lib.buildable.flags corresponds to the flags attached to the library stanza. These are used to compiler the various modules of the library. Here, we want to use the flags specifically given by the user to compiler the test runner, which should be in info.compile_flags.

Copy link
Collaborator Author

@lubegasimon lubegasimon Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which means compile_flags is now of type Ocaml_flags.Spec.t and following this path, I again hit

+  File "dune", line 11, characters 5-18:
+  11 |     (compile_flags -flag-that-is-not-accepted-by-ocaml)))
+            ^^^^^^^^^^^^^
+  Error: Unknown field compile_flags

and you addressed that issue here

Copy link

@ghost ghost Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, is it clear how to make progress?

The idea is that when you write let+ <var> = flag "<name>" decoder or and+ <var> = flag "<name>" decoder, you are telling how to parse a field named <name>. decoder explains how to parse the argument of this field. Ocaml_flags.Spec.decode explains how to parse a set of three field and instead we want to parse a single compile_flags field of type Ordered_set_lang.Unexpanded.t

Copy link
Collaborator Author

@lubegasimon lubegasimon Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, is it clear how to make progress?

now it seems clear, thanks.

Copy link
Collaborator Author

@lubegasimon lubegasimon Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremiedimino, am afraid, having compile_flags field to be of type Ordered_set_lang.Unexpanded.t will require us to pass lib.buildable.flags as a third arg to Super_context.ocaml_flag ( which expects the arg to be of type Ocaml_flags.Spec.t ), yet we intend to use info.compile_flags as you suggested above. This will call for changes in the type of Super_context.ocaml_flag which will subsequently result in type changes in many files which may cause breaking changes, am afraid.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at Ocaml_flags.Spect.t, it is a set of three things:

  • a list of flags to pass to ocamlc
  • a list of flags to pass to ocamlopt
  • a common list of flags to pass to both ocamlc and ocamlopt

These three fields have the type Ordered_set_lang.Unexpanded.t. Since we are only adding one field compile_flags, it should correspond to a common list of flags to pass to both ocamlc and ocamlopt. So what we need is a way to create an Ocaml_flags.Spec.t value from a list of common flags. You can add a new function in Ocaml_flags.Spec for that.

@lubegasimon
Copy link
Collaborator Author

closed in favour of #3747

@lubegasimon lubegasimon self-assigned this Sep 11, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Jan 13, 2021
…ne-action-plugin, dune-private-libs and dune-glob (2.8.0)

CHANGES:

- `dune rules` accepts aliases and other non-path rules (ocaml/dune#4063, @mrmr1993)

- Action `(diff reference test_result)` now accept `reference` to be absent and
  in that case consider that the reference is empty. Then running `dune promote`
  will create the reference file. (ocaml/dune#3795, @bobot)

- Ignore special files (BLK, CHR, FIFO, SOCKET), (ocaml/dune#3570, fixes ocaml/dune#3124, ocaml/dune#3546,
  @ejgallego)

- Experimental: Simplify loading of additional files (data or code) at runtime
  in programs by introducing specific installation sites. In particular it allow
  to define plugins to be installed in these sites. (ocaml/dune#3104, ocaml/dune#3794, fixes ocaml/dune#1185,
  @bobot)

- Move all temporary files created by dune to run actions to a single directory
  and make sure that actions executed by dune also use this directory by setting
  `TMPDIR` (or `TEMP` on Windows). (ocaml/dune#3691, fixes ocaml/dune#3422, @rgrinberg)

- Fix bootstrap script with custom configuration. (ocaml/dune#3757, fixes ocaml/dune#3774, @marsam)

- Add the `executable` field to `inline_tests` to customize the compilation
  flags of the test runner executable (ocaml/dune#3747, fixes ocaml/dune#3679, @lubegasimon)

- Add `(enabled_if ...)` to `(copy_files ...)` (ocaml/dune#3756, @nojb)

- Make sure Dune cleans up the status line before exiting (ocaml/dune#3767,
  fixes ocaml/dune#3737, @alan-j-hu)

- Add `{gitlab,bitbucket}` as options for defining project sources with `source`
  stanza `(source (<host> user/repo))` in the `dune-project` file.  (ocaml/dune#3813,
  @rgrinberg)

- Fix generation of `META` and `dune-package` files when some targets (byte,
  native, dynlink) are disabled. Previously, dune would generate all archives
  for regardless of settings. (ocaml/dune#3829, ocaml/dune#4041, @rgrinberg)

- Do not run ocamldep to for single module executables & libraries. The
  dependency graph for such artifacts is trivial (ocaml/dune#3847, @rgrinberg)

- Fix cram tests inside vendored directories not being interpreted correctly.
  (ocaml/dune#3860, fixes ocaml/dune#3843, @rgrinberg)

- Add `package` field to private libraries. This allows such libraries to be
  installed and to be usable by other public libraries in the same project
  (ocaml/dune#3655, fixes ocaml/dune#1017, @rgrinberg)

- Fix the `%{make}` variable on Windows by only checking for a `gmake` binary
  on UNIX-like systems as a unrelated `gmake` binary might exist on Windows.
  (ocaml/dune#3853, @kit-ty-kate)

- Fix `$ dune install` modifying the build directory. This made the build
  directory unusable when `$ sudo dune install` modified permissions. (fix
  ocaml/dune#3857, @rgrinberg)

- Fix handling of aliases given on the command line (using the `@` and `@@`
  syntax) so as to correctly handle relative paths. (ocaml/dune#3874, fixes ocaml/dune#3850, @nojb)

- Allow link time code generation to be used in preprocessing executable. This
  makes it possible to use the build info module inside the preprocessor.
  (ocaml/dune#3848, fix ocaml/dune#3848, @rgrinberg)

- Correctly call `git ls-tree` so unicode files are not quoted, this fixes
  problems with `dune subst` in the presence of unicode files. Fixes ocaml/dune#3219
  (ocaml/dune#3879, @ejgallego)

- `dune subst` now accepts common command-line arguments such as
  `--debug-backtraces` (ocaml/dune#3878, @ejgallego)

- `dune describe` now also includes information about executables in addition to
  that of libraries. (ocaml/dune#3892, ocaml/dune#3895, @nojb)

- instrumentation backends can now receive arguments via `(instrumentation
  (backend <name> <args>))`. (ocaml/dune#3906, ocaml/dune#3932, @nojb)

- Tweak auto-formatting of `dune` files to improve readability. (ocaml/dune#3928, @nojb)

- Add a switch argument to opam when context is not default. (ocaml/dune#3951, @tmattio)

- Avoid pager when running `$ git diff` (ocaml/dune#3912, @AltGr)

- Add `(root_module ..)` field to libraries & executables. This makes it
  possible to use library dependencies shadowed by local modules (ocaml/dune#3825,
  @rgrinberg)

- Allow `(formatting ...)` field in `(env ...)` stanza to set per-directory
  formatting specification. (ocaml/dune#3942, @nojb)

- [coq] In `coq.theory`, `:standard` for the `flags` field now uses the
  flags set in `env` profile flags (ocaml/dune#3931 , @ejgallego @rgrinberg)

- [coq] Add `-q` flag to `:standard` `coqc` flags , fixes ocaml/dune#3924, (ocaml/dune#3931 , @ejgallego)

- Add support for Coq's native compute compilation mode (@ejgallego, ocaml/dune#3210)

- Add a `SUFFIX` directive in `.merlin` files for each dialect with no
  preprocessing, to let merlin know of additional file extensions (ocaml/dune#3977,
  @vouillon)

- Stop promoting `.merlin` files. Write per-stanza Merlin configurations in
  binary form. Add a new subcommand `dune ocaml-merlin` that Merlin can use to
  query the configuration files. The `allow_approximate_merlin` option is now
  useless and deprecated. Dune now conflicts with `merlin < 3.4.0` and
  `ocaml-lsp-server < 1.3.0` (ocaml/dune#3554, @voodoos)

- Configurator: fix a bug introduced in 2.6.0 where the configurator V1 API
  doesn't work at all when used outside of dune. (ocaml/dune#4046, @aalekseyev)

- Fix `libexec` and `libexec-private` variables. In cross-compilation settings,
  they now point to the file in the host context. (ocaml/dune#4058, fixes ocaml/dune#4057,
  @TheLortex)

- When running `$ dune subst`, use project metadata as a fallback when package
  metadata is missing. We also generate a warning when `(name ..)` is missing in
  `dune-project` files to avoid failures in production builds.

- Remove support for passing `-nodynlink` for executables. It was bypassed in
  most cases and not correct in other cases in particular on arm32.
  (ocaml/dune#4085, fixes ocaml/dune#4069, fixes ocaml/dune#2527, @emillon)

- Generate archive rules compatible with 4.12. Dune longer attempt to generate
  an archive file if it's unnecessary (ocaml/dune#3973, fixes ocaml/dune#3766, @rgrinberg)

- Fix generated Merlin configurations when multiple preprocessors are defined
  for different modules in the same folder. (ocaml/dune#4092, fixes ocaml/dune#2596, ocaml/dune#1212 and
  ocaml/dune#3409, @voodoos)

- Add the option `use_standard_c_and_cxx_flags` to `dune-project` that 1.
  disables the unconditional use of the `ocamlc_cflags` and `ocamlc_cppflags`
  from `ocamlc -config` in C compiler calls, these flags will be present in the
  `:standard` set instead; and 2. enables the detection of the C compiler family
  and populates the `:standard` set of flags with common default values when
  building CXX stubs. (ocaml/dune#3875, ocaml/dune#3802, fix ocaml/dune#3718 and ocaml/dune#3528, @voodoos)
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

Successfully merging this pull request may close these issues.

2 participants