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

Change compiler flags based on OCaml version #90

Closed
talex5 opened this issue May 23, 2017 · 4 comments
Closed

Change compiler flags based on OCaml version #90

talex5 opened this issue May 23, 2017 · 4 comments

Comments

@talex5
Copy link

talex5 commented May 23, 2017

I'd like to compile a library with -O3. Since OCaml 4.02 doesn't support that flag, I'd like to skip it for that version of the compiler.

I tried using :include, but it looks like ocamlopt_flags doesn't support that (undefined symbol :include). Is there another way (short of switching to the OCaml jbuild syntax)?

I guess #56 would also solve my problem, if implemented.

@ghost
Copy link

ghost commented May 23, 2017

:include is only supported for C compilation/link flags for historical reasons. I guess we could support it everywhere for uniformity, although you rarely need complex computation to determine the ocaml flags.

I don't think #56 will ever be implemented. It won't be enough in the long term; jbuilder will have to support OCaml plugins properly.

For simple things, I have been working on a small meta-programming language for jbuild files, see this jbuild for instance. Eventually there'll also be a way to change the default flags for a given scope, so you'll be able to write this in a toplevel jbuild file:

(set_defaults
 ((ocamlopt_flags
   (:standard
    (:if (:ver> %{ocaml_version} 4.02) -O3)
    (:if %{dev} -w @a)))))

In the meantine, you indeed need to resort to the OCaml syntax.

@dra27
Copy link
Member

dra27 commented Aug 25, 2017

#235 makes the suggestion that we could automate the removal of flags (which I think is a good idea)

@kit-ty-kate
Copy link
Member

Here is an example where this can be useful: ocurrent/ocaml-ci#265
Also I just noticed that the documentation says this feature is definitely coming in the future: https://dune.readthedocs.io/en/stable/concepts.html?highlight=flags#ordered-set-language.

Note that inside an ordered set, the first element of a list cannot be an atom except if it starts with -
or :. The reason for this is that we are planning to add simple programmatic features in the futures
so that one may write:

(flags (if (>= %{ocaml_version} 4.06) ...))

Any news on that?

@emillon
Copy link
Collaborator

emillon commented Jan 11, 2024

:include in all flags has been added in #153, so I'm closing this. Thanks!

@emillon emillon closed this as completed Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants