Skip to content

Commit

Permalink
Merge branch 'main' into target-hints
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon authored Dec 1, 2022
2 parents c638cc4 + 1e835d9 commit 82468d4
Show file tree
Hide file tree
Showing 34 changed files with 345 additions and 139 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Unreleased

- Fix configurator when using the MSVC compiler (#6538, fixes #6537, @nojb)

- Fix missing dependencies when detecting the kind of C compiler we're using
(#6610, fixes #6415, @emillon)

3.6.0 (2022-11-14)
------------------

Expand Down
8 changes: 4 additions & 4 deletions bin/arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ module Dep = struct

let parser s =
match parse_alias s with
| Some dep -> `Ok dep
| Some dep -> Ok dep
| None -> (
match
Dune_lang.Decoder.parse dep_parser Univ_map.empty
(Dune_lang.Parser.parse_string ~fname:"command line"
~mode:Dune_lang.Parser.Mode.Single s)
with
| x -> `Ok x
| exception User_error.E msg -> `Error (User_message.to_string msg))
| x -> Ok x
| exception User_error.E msg -> Error (User_message.to_string msg))

let string_of_alias ~recursive sv =
let prefix = if recursive then "@" else "@@" in
Expand All @@ -88,7 +88,7 @@ module Dep = struct
in
Format.pp_print_string ppf s

let conv = (parser, printer)
let conv = conv' (parser, printer)

let to_string_maybe_quoted t =
String.maybe_quoted (Format.asprintf "%a" printer t)
Expand Down
11 changes: 6 additions & 5 deletions bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,12 @@ let install_uninstall ~what =
let doc = Format.asprintf "%a packages." pp_what what in
let name_ = Arg.info [] ~docv:"PACKAGE" in
let absolute_path =
( (fun path ->
if Filename.is_relative path then
`Error "the path must be absolute to avoid ambiguity"
else `Ok path)
, snd Arg.string )
Arg.conv'
( (fun path ->
if Filename.is_relative path then
Error "the path must be absolute to avoid ambiguity"
else Ok path)
, Arg.conv_printer Arg.string )
in
let term =
let+ common = Common.term
Expand Down
5 changes: 4 additions & 1 deletion dune-file
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@

(env
(_
(flags :standard -alert -unstable)))
(flags :standard -alert -unstable)
(env-vars
; Workaround for #6607
(CLICOLOR_FORCE 0))))
2 changes: 1 addition & 1 deletion src/dune_rules/cxx_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let rules ~sctx ~dir =
[ (match Ocaml_config.ccomp_type ocfg with
| Msvc -> A "/EP"
| Other _ -> As [ "-E"; "-P" ])
; A Path.(to_absolute_filename (build header_file))
; Path (Path.build header_file)
]
in
let action =
Expand Down
9 changes: 5 additions & 4 deletions src/dune_rules/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,11 @@ end
include Load

let modules_of_lib sctx lib =
let dir = Lib_info.src_dir (Lib.info lib) in
match Path.as_in_build_dir dir with
| None -> Memo.return None
| Some dir ->
let info = Lib.info lib in
match Lib_info.modules info with
| External modules -> Memo.return modules
| Local ->
let dir = Lib_info.src_dir info |> Path.as_in_build_dir_exn in
let* t = get sctx ~dir in
let+ ml_sources = ocaml t in
let name = Lib.name lib in
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,8 @@ module Library = struct
~requires ~foreign_objects ~plugins ~archives ~ppx_runtime_deps
~foreign_archives ~native_archives ~foreign_dll_files ~jsoo_runtime
~jsoo_archive ~preprocess ~enabled ~virtual_deps ~dune_version ~virtual_
~entry_modules ~implements ~default_implementation ~modes ~wrapped
~special_builtin_support ~exit_module ~instrumentation_backend
~entry_modules ~implements ~default_implementation ~modes ~modules:Local
~wrapped ~special_builtin_support ~exit_module ~instrumentation_backend
end

module Plugin = struct
Expand Down
34 changes: 19 additions & 15 deletions src/dune_rules/dune_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@ let fn = "dune-package"
module Lib = struct
type t =
{ info : Path.t Lib_info.t
; modules : Modules.t option
; main_module_name : Module_name.t option
}

let make ~info ~main_module_name ~modules =
let make ~info ~main_module_name =
let obj_dir = Lib_info.obj_dir info in
let dir = Obj_dir.dir obj_dir in
let map_path p =
if Path.is_managed p then Path.relative dir (Path.basename p) else p
in
let info = Lib_info.map_path info ~f:map_path in
{ info; main_module_name; modules }
{ info; main_module_name }

let of_dune_lib ~info ~main_module_name ~modules =
make ~info ~main_module_name ~modules:(Some modules)
let of_dune_lib ~info ~main_module_name = make ~info ~main_module_name

let of_findlib info = make ~info ~main_module_name:None ~modules:None
let of_findlib info = make ~info ~main_module_name:None

let dir_of_name name =
let _, components = Lib_name.split name in
Path.Local.L.relative Path.Local.root components

let encode ~package_root { info; main_module_name; modules } =
let encode ~package_root { info; main_module_name } =
let open Dune_lang.Encoder in
let no_loc f (_loc, x) = f x in
let path = Dpath.Local.encode ~dir:package_root in
Expand Down Expand Up @@ -59,6 +57,11 @@ module Lib = struct
| External e -> e
| Local -> assert false
in
let modules =
match Lib_info.modules info with
| External ms -> ms
| Local -> None
in
let jsoo_runtime = Lib_info.jsoo_runtime info in
let virtual_ = Option.is_some (Lib_info.virtual_ info) in
let instrumentation_backend = Lib_info.instrumentation_backend info in
Expand Down Expand Up @@ -189,31 +192,32 @@ module Lib = struct
in
let entry_modules = Lib_info.Source.External (Ok entry_modules) in
let modes = { Lib_mode.Map.ocaml = modes; melange = false } in
let modules = Lib_info.Source.External (Some modules) in
Lib_info.create ~path_kind:External ~loc ~name ~kind ~status ~src_dir
~orig_src_dir ~obj_dir ~version ~synopsis ~main_module_name
~sub_systems ~requires ~foreign_objects ~plugins ~archives
~ppx_runtime_deps ~foreign_archives
~native_archives:(Files native_archives) ~foreign_dll_files:[]
~jsoo_runtime ~jsoo_archive ~preprocess ~enabled ~virtual_deps
~dune_version ~virtual_ ~entry_modules ~implements
~default_implementation ~modes ~wrapped ~special_builtin_support
~exit_module:None ~instrumentation_backend
~default_implementation ~modes ~modules ~wrapped
~special_builtin_support ~exit_module:None ~instrumentation_backend
in
{ info; main_module_name; modules = Some modules })

let modules t = t.modules
{ info; main_module_name })

let main_module_name t = t.main_module_name

let wrapped t = Option.map t.modules ~f:Modules.wrapped
let wrapped t =
match Lib_info.modules t.info with
| External modules -> Option.map modules ~f:Modules.wrapped
| Local -> None

let info dp = dp.info

let to_dyn { info; modules; main_module_name } =
let to_dyn { info; main_module_name } =
let open Dyn in
record
[ ("info", Lib_info.to_dyn Path.to_dyn info)
; ("modules", option Modules.to_dyn modules)
; ("main_module_name", option Module_name.to_dyn main_module_name)
]
end
Expand Down
7 changes: 1 addition & 6 deletions src/dune_rules/dune_package.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ val fn : string
module Lib : sig
type t

val modules : t -> Modules.t option

val main_module_name : t -> Module_name.t option

val dir_of_name : Lib_name.t -> Path.Local.t
Expand All @@ -21,10 +19,7 @@ module Lib : sig
val of_findlib : Path.t Lib_info.t -> t

val of_dune_lib :
info:Path.t Lib_info.t
-> main_module_name:Module_name.t option
-> modules:Modules.t
-> t
info:Path.t Lib_info.t -> main_module_name:Module_name.t option -> t

val to_dyn : t Dyn.builder
end
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/exe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let link_exe ~loc ~name ~(linkage : Linkage.t) ~cm_files ~link_time_code_gen
let fdo_linker_script = Fdo.Linker_script.create cctx (Path.build exe) in
let open Memo.O in
let* action_with_targets =
let ocaml_flags = Ocaml_flags.get (CC.flags cctx) mode in
let ocaml_flags = Ocaml_flags.get (CC.flags cctx) (Ocaml mode) in
let prefix =
Cm_files.top_sorted_objects_and_cms cm_files ~mode
|> Action_builder.dyn_paths_unit
Expand Down
3 changes: 2 additions & 1 deletion src/dune_rules/findlib/findlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,15 @@ end = struct
| Ok s -> Ok (Some s)
| Error e -> Error (User_error.E e)))))
in
let modules = Lib_info.Source.External None in
Lib_info.create ~path_kind:External ~loc ~name:t.name ~kind ~status
~src_dir ~orig_src_dir ~obj_dir ~version ~synopsis ~main_module_name
~sub_systems ~requires ~foreign_objects ~plugins ~archives
~ppx_runtime_deps ~foreign_archives
~native_archives:(Files native_archives) ~foreign_dll_files:[]
~jsoo_runtime ~jsoo_archive ~preprocess ~enabled ~virtual_deps
~dune_version ~virtual_ ~implements ~default_implementation ~modes
~wrapped ~special_builtin_support ~exit_module:None
~modules ~wrapped ~special_builtin_support ~exit_module:None
~instrumentation_backend:None ~entry_modules
in
Dune_package.Lib.of_findlib info
Expand Down
23 changes: 12 additions & 11 deletions src/dune_rules/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,22 @@ let gen_rules sctx dir_contents cctxs expander
| true -> (
let* ml_sources = Dir_contents.ocaml dir_contents in
match
List.find_map (Menhir_rules.module_names m) ~f:(fun name ->
Option.bind (Ml_sources.find_origin ml_sources name)
~f:(fun origin ->
List.find_map cctxs ~f:(fun (loc, cctx) ->
Option.some_if
(Loc.equal loc (Ml_sources.Origin.loc origin))
cctx)))
Menhir_rules.module_names m
|> List.find_map ~f:(fun name ->
let open Option.O in
let* origin = Ml_sources.find_origin ml_sources name in
List.find_map cctxs ~f:(fun (loc, cctx) ->
Option.some_if
(Loc.equal loc (Ml_sources.Origin.loc origin))
cctx))
with
| Some cctx -> Menhir_rules.gen_rules cctx m ~dir:ctx_dir
| None ->
(* This happens often when passing a [-p ...] option that hides a
library *)
let file_targets =
List.map (Menhir_stanza.targets m)
~f:(Path.Build.relative ctx_dir)
Menhir_stanza.targets m
|> List.map ~f:(Path.Build.relative ctx_dir)
in
Super_context.add_rule sctx ~dir:ctx_dir
(Action_builder.fail
Expand All @@ -278,8 +280,7 @@ let gen_rules sctx dir_contents cctxs expander
files produced by this stanza are part of."
])
}
|> Action_builder.with_file_targets ~file_targets)
| Some cctx -> Menhir_rules.gen_rules cctx m ~dir:ctx_dir))
|> Action_builder.with_file_targets ~file_targets)))
| Coq_stanza.Theory.T m -> (
Expander.eval_blang expander m.enabled_if >>= function
| false -> Memo.return ()
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ let to_dune_lib ({ info; _ } as lib) ~modules ~foreign_objects ~dir :
~foreign_objects ~obj_dir ~implements ~default_implementation ~sub_systems
~modules
in
Dune_package.Lib.of_dune_lib ~info ~modules ~main_module_name
Dune_package.Lib.of_dune_lib ~info ~main_module_name

module Local : sig
type t = private lib
Expand Down
12 changes: 11 additions & 1 deletion src/dune_rules/lib_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ type 'path t =
; wrapped : Wrapped.t Inherited.t option
; main_module_name : Main_module_name.t
; modes : Lib_mode.Map.Set.t
; modules : Modules.t option Source.t
; special_builtin_support : Special_builtin_support.t option
; exit_module : Module_name.t option
; instrumentation_backend : (Loc.t * Lib_name.t) option
Expand Down Expand Up @@ -358,6 +359,7 @@ let equal (type a) (t : a t)
; wrapped
; main_module_name
; modes
; modules
; special_builtin_support
; exit_module
; instrumentation_backend
Expand Down Expand Up @@ -410,6 +412,7 @@ let equal (type a) (t : a t)
&& Option.equal (Inherited.equal Wrapped.equal) wrapped t.wrapped
&& Main_module_name.equal main_module_name t.main_module_name
&& Lib_mode.Map.Set.equal modes t.modes
&& Source.equal (Option.equal Modules.equal) modules t.modules
&& Option.equal Special_builtin_support.equal special_builtin_support
t.special_builtin_support
&& Option.equal Module_name.equal exit_module t.exit_module
Expand All @@ -436,6 +439,8 @@ let sub_systems t = t.sub_systems

let modes t = t.modes

let modules t = t.modules

let archives t = t.archives

let foreign_archives t = t.foreign_archives
Expand Down Expand Up @@ -513,6 +518,7 @@ let for_dune_package t ~name ~ppx_runtime_deps ~requires ~foreign_objects
let native_archives =
Files (eval_native_archives_exn t ~modules:(Some modules))
in
let modules = Source.External (Some modules) in
{ t with
ppx_runtime_deps
; name
Expand All @@ -524,6 +530,7 @@ let for_dune_package t ~name ~ppx_runtime_deps ~requires ~foreign_objects
; sub_systems
; orig_src_dir
; native_archives
; modules
}

let user_written_deps t =
Expand All @@ -535,7 +542,7 @@ let create ~loc ~path_kind ~name ~kind ~status ~src_dir ~orig_src_dir ~obj_dir
~plugins ~archives ~ppx_runtime_deps ~foreign_archives ~native_archives
~foreign_dll_files ~jsoo_runtime ~jsoo_archive ~preprocess ~enabled
~virtual_deps ~dune_version ~virtual_ ~entry_modules ~implements
~default_implementation ~modes ~wrapped ~special_builtin_support
~default_implementation ~modes ~modules ~wrapped ~special_builtin_support
~exit_module ~instrumentation_backend =
{ loc
; name
Expand Down Expand Up @@ -567,6 +574,7 @@ let create ~loc ~path_kind ~name ~kind ~status ~src_dir ~orig_src_dir ~obj_dir
; implements
; default_implementation
; modes
; modules
; wrapped
; special_builtin_support
; exit_module
Expand Down Expand Up @@ -642,6 +650,7 @@ let to_dyn path
; implements
; default_implementation
; modes
; modules
; wrapped
; special_builtin_support
; exit_module
Expand Down Expand Up @@ -683,6 +692,7 @@ let to_dyn path
; ("wrapped", option (Inherited.to_dyn Wrapped.to_dyn) wrapped)
; ("main_module_name", Main_module_name.to_dyn main_module_name)
; ("modes", Lib_mode.Map.Set.to_dyn modes)
; ("modules", Source.to_dyn (Dyn.option Modules.to_dyn) modules)
; ( "special_builtin_support"
, option Special_builtin_support.to_dyn special_builtin_support )
; ("exit_module", option Module_name.to_dyn exit_module)
Expand Down
3 changes: 3 additions & 0 deletions src/dune_rules/lib_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ val special_builtin_support : _ t -> Special_builtin_support.t option

val modes : _ t -> Lib_mode.Map.Set.t

val modules : _ t -> Modules.t option Source.t

val implements : _ t -> (Loc.t * Lib_name.t) option

val requires : _ t -> Lib_dep.t list
Expand Down Expand Up @@ -236,6 +238,7 @@ val create :
-> implements:(Loc.t * Lib_name.t) option
-> default_implementation:(Loc.t * Lib_name.t) option
-> modes:Lib_mode.Map.Set.t
-> modules:Modules.t option Source.t
-> wrapped:Wrapped.t Inherited.t option
-> special_builtin_support:Special_builtin_support.t option
-> exit_module:Module_name.t option
Expand Down
Loading

0 comments on commit 82468d4

Please sign in to comment.