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

feature(coq): coq_version variable #5913

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dune_lang/pform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Var = struct
| Corrected_suffix
| Inline_tests
| Toolchain
| Coq_version
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we could add a parameter to this to have a %{coq:var} form, WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ejgallego I am currently working on a coq-config macro that will subsume all of this


let compare : t -> t -> Ordering.t = Poly.compare

Expand Down Expand Up @@ -97,6 +98,7 @@ module Var = struct
| Corrected_suffix -> "Corrected_suffix"
| Inline_tests -> "Inline_tests"
| Toolchain -> "Toolchain"
| Coq_version -> "Coq_version"
in
Dyn.Variant (cstr, [])
end
Expand Down Expand Up @@ -299,6 +301,7 @@ let encode_to_latest_dune_lang_version t =
| Corrected_suffix -> Some "corrected-suffix"
| Inline_tests -> Some "inline_tests"
| Toolchain -> Some "toolchain"
| Coq_version -> Some "coq_version"
with
| None -> Pform_was_deleted
| Some name -> Success { name; payload = None })
Expand Down Expand Up @@ -482,6 +485,7 @@ module Env = struct
; ("corrected-suffix", No_info Corrected_suffix)
; ("inline_tests", No_info Inline_tests)
; ("toolchains", since ~version:(3, 0) Var.Toolchain)
; ("coq_version", since ~version:(3, 4) Var.Coq_version)
]
in
String.Map.of_list_exn (List.concat [ lowercased; uppercased; other ])
Expand Down
1 change: 1 addition & 0 deletions src/dune_lang/pform.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Var : sig
| Corrected_suffix
| Inline_tests
| Toolchain
| Coq_version

val compare : t -> t -> Ordering.t

Expand Down
16 changes: 16 additions & 0 deletions src/dune_rules/coq_config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open Import
open Memo.O

let impl bin =
let* _ = Build_system.build_file bin in
let+ line =
Memo.of_non_reproducible_fiber
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean that even within a single run we will re-exec?

All Coq config is deterministic, just set a Coq configure time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And guarantee to change only if the hash changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It should only run once since it is memoed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is memoed as non reproducible tho.

@@ Process.run_capture_line Process.Strict bin [ "--print-version" ]
in
match String.lsplit2 ~on:' ' line with
| Some (coq, _ocaml) -> Some coq
| None -> None

let memo = Memo.create "coq-version" ~input:(module Path) impl

let version ~bin = Memo.exec memo bin
3 changes: 3 additions & 0 deletions src/dune_rules/coq_config.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
open Import

val version : bin:Path.t -> string option Memo.t
15 changes: 15 additions & 0 deletions src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ let expand_pform_gen ~(context : Context.t) ~bindings ~dir ~source
With
(let* cc = Action_builder.of_memo (cc t) in
cc.c))
| Coq_version ->
Need_full_expander
(fun t ->
Without
(let open Memo.O in
let* bin =
Artifacts.Bin.binary t.bin_artifacts_host ~loc:None "coqc"
in
match bin with
| Error _ -> failwith "TODO"
| Ok bin -> (
let+ res = Coq_config.version ~bin in
match res with
| None -> failwith "bad version"
| Some s -> [ Value.String s ])))
| Cxx ->
Need_full_expander
(fun t ->
Expand Down
19 changes: 19 additions & 0 deletions test/blackbox-tests/test-cases/coq/coq-version/coq-version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$ cat >dune-project <<EOF
> (lang dune 3.4)
> EOF

$ cat >dune <<EOF
> (rule
> (action (with-stdout-to file (echo "8.15.2")))
> (enabled_if (= %{coq_version} "8.15.2")))
> (rule
> (action (with-stdout-to file (echo "8.15.1")))
> (enabled_if (= %{coq_version} "8.15.1")))
> EOF

$ dune build ./file

$ cat _build/default/file
8.15.2

(>= 8.15.0-x12gn1 8.15.1) => false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "1.2.3 x_x_x"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(libraries axsxasdsdads)
(public_name coqc))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(lang dune 3.4)

(package
(name foo))
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# $ cat >dune <<EOF
# > (rule
# > (action (with-stdout-to file (echo %{coq_version}))))
# > EOF
#
# $ dune build ./file
# $ cat _build/default/file

$ mkdir sub
$ cat >sub/dune <<EOF
> (rule
> (enabled_if (>= %{coq_version} 8.15))
> (action (with-stdout-to file (echo 123))))
> EOF

$ cat >dune <<EOF
> (rule
> (action (with-stdout-to alwayspresent (echo 123))))
> EOF

$ dune build ./alwayspresent

(coq.theory
(name foo)
(native_theories mathcomp)
(theories mathcomp))