diff --git a/bench/micro/dune b/bench/micro/dune index f19e6da16ec5..e66f2bb7369b 100644 --- a/bench/micro/dune +++ b/bench/micro/dune @@ -29,7 +29,7 @@ (library_flags -linkall) (preprocess (pps ppx_bench)) - (libraries dune_thread_pool threads.posix core_bench.inline_benchmarks)) + (libraries dune_thread_pool unix threads.posix core_bench.inline_benchmarks)) (executable (name thread_pool_bench_main) diff --git a/doc/changes/10935.md b/doc/changes/10935.md new file mode 100644 index 000000000000..d6b1a2bf0f83 --- /dev/null +++ b/doc/changes/10935.md @@ -0,0 +1 @@ +- Forward the linkall flag to jsoo in whole program compilation as well (#10935, @hhugo) \ No newline at end of file diff --git a/flake.lock b/flake.lock index f9a4467cee66..00b118912a57 100644 --- a/flake.lock +++ b/flake.lock @@ -121,11 +121,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726142289, - "narHash": "sha256-Jks8O42La+nm5AMTSq/PvM5O+fUAhIy0Ce1QYqLkyZ4=", + "lastModified": 1727524699, + "narHash": "sha256-k6YxGj08voz9NvuKExojiGXAVd69M8COtqWSKr6sQS4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "280db3decab4cbeb22a4599bd472229ab74d25e1", + "rev": "b5b2fecd0cadd82ef107c9583018f381ae70f222", "type": "github" }, "original": { diff --git a/otherlibs/stdune/src/stdune.ml b/otherlibs/stdune/src/stdune.ml index 37f7e7cdf262..1ea7da7ef618 100644 --- a/otherlibs/stdune/src/stdune.ml +++ b/otherlibs/stdune/src/stdune.ml @@ -1,5 +1,11 @@ -[@@@alert unstable "The API of this library is not stable and may change without notice."] -[@@@alert "-unstable"] +include struct + [@@@ocaml.warning "-53"] + + [@@@alert + unstable "The API of this library is not stable and may change without notice."] + + [@@@alert "-unstable"] +end module Appendable_list = Appendable_list module Nonempty_list = Nonempty_list diff --git a/src/dune_lang/package_version.mli b/src/dune_lang/package_version.mli index 186931ed2a09..31c51d13cbb4 100644 --- a/src/dune_lang/package_version.mli +++ b/src/dune_lang/package_version.mli @@ -4,6 +4,7 @@ type t val of_string : string -> t val of_string_opt : string -> t option +val of_string_user_error : Loc.t * string -> (t, User_message.t) result val to_string : t -> string val equal : t -> t -> bool val to_dyn : t -> Dyn.t diff --git a/src/dune_pkg/opam_file.ml b/src/dune_pkg/opam_file.ml index cec17d64e9ca..c28ec969749f 100644 --- a/src/dune_pkg/opam_file.ml +++ b/src/dune_pkg/opam_file.ml @@ -57,13 +57,15 @@ let parse = let parse_value = parse_gen OpamBaseParser.value -let get_field t name = +let get_field_with_pos t name = List.find_map t.file_contents ~f:(fun value -> match value.pelem with - | Variable (var, value) when var.pelem = name -> Some value + | Variable (var, value) when var.pelem = name -> Some (value, var.pos) | _ -> None) ;; +let get_field t name = get_field_with_pos t name |> Option.map ~f:fst + let absolutify_positions ~file_contents t = let bols = ref [ 0 ] in String.iteri file_contents ~f:(fun i ch -> if ch = '\n' then bols := (i + 1) :: !bols); @@ -225,15 +227,16 @@ let load_opam_file_with_contents ~contents:opam_file_string file name = None in let open Option.O in - let get_one name = - let* value = + let get_one_with_loc name = + let* value, pos = let* opam = opam in - get_field opam name + get_field_with_pos opam name in match value.pelem with - | String s -> Some s + | String s -> Some (loc_of_opam_pos pos, s) | _ -> None in + let get_one name = get_one_with_loc name >>| snd in let get_many name = let* value = let* opam = opam in @@ -270,7 +273,10 @@ let load_opam_file_with_contents ~contents:opam_file_string file name = ~name ~dir ~loc - ~version:(get_one "version" |> Option.map ~f:Package_version.of_string) + ~version: + (get_one_with_loc "version" + |> Option.map ~f:Package_version.of_string_user_error + >>| User_error.ok_exn) ~conflicts:[] ~depends:[] ~depopts:[] diff --git a/src/dune_pkg/package_version.mli b/src/dune_pkg/package_version.mli index 723bdafaf3a6..a95cf9fbf3d4 100644 --- a/src/dune_pkg/package_version.mli +++ b/src/dune_pkg/package_version.mli @@ -3,6 +3,7 @@ open! Stdune type t = Dune_lang.Package_version.t val of_string : string -> t +val of_string_user_error : Loc.t * string -> (t, User_message.t) result val to_string : t -> string val equal : t -> t -> bool val to_dyn : t -> Dyn.t diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index 52f7941c75f1..148479f7c788 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -291,10 +291,25 @@ let standalone_runtime_rule cc ~javascript_files ~target ~flags = ~config:(Some config) ;; -let exe_rule cc ~javascript_files ~src ~target ~flags = +let exe_rule cc ~linkall ~javascript_files ~src ~target ~flags = let dir = Compilation_context.dir cc in let sctx = Compilation_context.super_context cc in let libs = Compilation_context.requires_link cc in + let linkall = + let open Action_builder.O in + let+ linkall = linkall + and+ jsoo_version = + let* jsoo = jsoo ~dir sctx in + Action_builder.of_memo @@ Version.jsoo_version jsoo + in + Command.Args.As + (match jsoo_version, linkall with + | Some version, true -> + (match Version.compare version (5, 1) with + | Lt -> [] + | Gt | Eq -> [ "--linkall" ]) + | None, _ | _, false -> []) + in let spec = Command.Args.S [ Resolve.Memo.args @@ -303,6 +318,7 @@ let exe_rule cc ~javascript_files ~src ~target ~flags = Command.Args.Deps (jsoo_runtime_files libs)) ; Deps (List.map ~f:Path.build javascript_files) ; Dep (Path.build src) + ; Dyn linkall ] in js_of_ocaml_rule sctx ~sub_command:Compile ~dir ~spec ~target ~flags ~config:None @@ -549,7 +565,7 @@ let build_exe in () | Whole_program -> - exe_rule cc ~javascript_files ~src ~target ~flags ~sourcemap + exe_rule cc ~linkall ~javascript_files ~src ~target ~flags ~sourcemap |> Super_context.add_rule sctx ~loc ~dir ~mode ;; diff --git a/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t b/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t index fba35fdc48ea..873862126715 100644 --- a/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t +++ b/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t @@ -16,6 +16,7 @@ Run inline tests using node js inline tests (JS) $ dune runtest --profile release + Warning: your program contains effect handlers; you should probably run js_of_ocaml with option '--enable=effects' inline tests (JS) inline tests (JS) inline tests (Native) diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/dune-project b/test/blackbox-tests/test-cases/package-version-empty.t/dune-project new file mode 100644 index 000000000000..ddef0c5dd505 --- /dev/null +++ b/test/blackbox-tests/test-cases/package-version-empty.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.16) diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/foo.opam b/test/blackbox-tests/test-cases/package-version-empty.t/foo.opam new file mode 100644 index 000000000000..19f54b313421 --- /dev/null +++ b/test/blackbox-tests/test-cases/package-version-empty.t/foo.opam @@ -0,0 +1,2 @@ +opam-version: "2.0" +version: "" diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/run.t b/test/blackbox-tests/test-cases/package-version-empty.t/run.t new file mode 100644 index 000000000000..c0df696fbdd5 --- /dev/null +++ b/test/blackbox-tests/test-cases/package-version-empty.t/run.t @@ -0,0 +1,9 @@ +Testing dune #10674 where an empty version in an opam file caused a code error +in dune. We should make sure that this case is handled gracefully. + + $ dune build + File "foo.opam", line 2, characters 0-7: + 2 | version: "" + ^^^^^^^ + Error: "" is an invalid package version. + [1] diff --git a/test/expect-tests/dune_file_watcher/dune b/test/expect-tests/dune_file_watcher/dune index 47e7b7d3b5c8..4971217ff885 100644 --- a/test/expect-tests/dune_file_watcher/dune +++ b/test/expect-tests/dune_file_watcher/dune @@ -14,6 +14,7 @@ (deps (sandbox always))) (libraries + unix dune_file_watcher dune_file_watcher_tests_lib ppx_expect.config diff --git a/test/expect-tests/fsevents/dune b/test/expect-tests/fsevents/dune index 27a004e9d937..00dcee572959 100644 --- a/test/expect-tests/fsevents/dune +++ b/test/expect-tests/fsevents/dune @@ -8,6 +8,7 @@ (deps (sandbox always))) (libraries + unix fsevents stdune threads.posix diff --git a/test/unit-tests/fswatch_win/dune b/test/unit-tests/fswatch_win/dune index 28fdea3af730..247fce6d959a 100644 --- a/test/unit-tests/fswatch_win/dune +++ b/test/unit-tests/fswatch_win/dune @@ -1,6 +1,6 @@ (executable (name fswatch_win_tests) - (libraries fswatch_win stdune)) + (libraries fswatch_win unix stdune)) (rule (alias fswatch_win_tests)