Skip to content

Commit

Permalink
Add (link_flags ...) to (cinaps) stanza (#7423)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
  • Loading branch information
nojb authored Mar 29, 2023
1 parent 9ff9ddd commit 4162b3e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Unreleased
- Speed up file copying on macos by using `clonefile` when available
(@rgrinberg, #7210)

- Adds support for loading plugins in toplevels (#6082, fixes #6081,
- Adds support for loading plugins in toplevels (#6082, fixes #6081,
@ivg, @richardlford)

- Support commands that output 8-bit and 24-bit colors in the terminal (#7188,
Expand Down Expand Up @@ -83,6 +83,9 @@ Unreleased
- Fix segfault on MacOS when dune was being shutdown while in watch mode.
(#7312, fixes #6151, @gridbugs, @emillon)

- Support `(link_flags ...)` in `(cinaps ...)` stanza. (#7423, fixes #7416,
@nojb)

3.7.0 (2023-02-17)
------------------

Expand Down
15 changes: 14 additions & 1 deletion src/dune_rules/cinaps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type t =
; runtime_deps : Dep_conf.t list
; cinaps_version : Syntax.Version.t
; alias : Alias.Name.t option
; link_flags : Link_flags.Spec.t
}

let name = "cinaps"
Expand Down Expand Up @@ -38,6 +39,7 @@ let decode =
(Dune_lang.Syntax.since syntax (1, 1) >>> repeat Dep_conf.decode)
and+ cinaps_version = Dune_lang.Syntax.get_exn syntax
and+ alias = field_o "alias" Alias.Name.decode
and+ link_flags = Link_flags.Spec.decode ~since:(Some (3, 8))
(* TODO use this field? *)
and+ _flags = Ocaml_flags.Spec.decode in
{ loc
Expand All @@ -48,6 +50,7 @@ let decode =
; runtime_deps
; cinaps_version
; alias
; link_flags
})

let () =
Expand Down Expand Up @@ -139,7 +142,17 @@ let gen_rules sctx t ~dir ~scope =
~js_of_ocaml:None ~package:None
in
let* (_ : Exe.dep_graphs) =
Exe.build_and_link cctx
let link_args =
let open Action_builder.O in
let* link_flags =
Action_builder.of_memo (Super_context.link_flags sctx ~dir t.link_flags)
in
let+ link_args =
Link_flags.get ~use_standard_cxx_flags:false link_flags
in
Command.Args.As link_args
in
Exe.build_and_link cctx ~link_args
~program:{ name; main_module_name; loc }
~linkages:[ Exe.Linkage.native_or_custom (Super_context.context sctx) ]
~promote:None
Expand Down
17 changes: 17 additions & 0 deletions test/blackbox-tests/test-cases/cinaps/link-flags.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Link-time flags for running cinaps

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using cinaps 1.1)
> EOF

$ cat > dune <<EOF
> (cinaps
> (files *.ml)
> (link_flags -linkall))
> EOF

$ touch test.ml

$ dune build --verbose @cinaps 2>&1 | sed -n 's#.*/cinaps.exe.*\(-linkall\).*#\1#p'
-linkall

0 comments on commit 4162b3e

Please sign in to comment.