This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,118 @@
open StdLabels
open Printf
(* This program performs version checking of the compiler and switches to the
secondary compiler if necessary. The script should execute in OCaml 4.08! *)
let min_supported_natively = 4, 08, 0
let keep_generated_files =
let anon s = raise (Arg.Bad (sprintf "don't know what to do with %s\n" s)) in
let keep_generated_files = ref false in
Arg.parse
[ "-j", Arg.Int ignore, "JOBS Concurrency"
; "--verbose", Arg.Unit ignore, " Set the display mode"
; "--keep-generated-files", Arg.Set keep_generated_files, " Keep generated files"
; "--debug", Arg.Unit ignore, " Enable various debugging options"
; ( "--force-byte-compilation"
, Arg.Unit ignore
, " Force bytecode compilation even if ocamlopt is available" )
; "--static", Arg.Unit ignore, " Build a static binary"
; "--boot-dir", Arg.String (fun _ -> ()), " set the boot directory"
]
anon
"Usage: ocaml bootstrap.ml <options>\nOptions are:";
!keep_generated_files
;;
let modules = [ "boot/libs"; "boot/duneboot" ]
let duneboot = ".duneboot"
let prog = duneboot ^ ".exe"
let () =
at_exit (fun () ->
Array.iter (Sys.readdir "boot") ~f:(fun fn ->
let fn = Filename.concat "boot" fn in
if Filename.check_suffix fn ".cmi" || Filename.check_suffix fn ".cmo"
then (
try Sys.remove fn with
| Sys_error _ -> ())));
if not keep_generated_files
then
at_exit (fun () ->
Array.iter (Sys.readdir ".") ~f:(fun fn ->
if
String.length fn >= String.length duneboot
&& String.sub fn ~pos:0 ~len:(String.length duneboot) = duneboot
then (
try Sys.remove fn with
| Sys_error _ -> ())))
;;
let runf fmt =
ksprintf
(fun cmd ->
prerr_endline cmd;
Sys.command cmd)
fmt
;;
let exit_if_non_zero = function
| 0 -> ()
| n -> exit n
;;
let read_file fn =
let ic = open_in_bin fn in
let s = really_input_string ic (in_channel_length ic) in
close_in ic;
s
;;
let () =
let v = Scanf.sscanf Sys.ocaml_version "%d.%d.%d" (fun a b c -> a, b, c) in
let compiler, which =
if v >= min_supported_natively
then "ocamlc", None
else (
let compiler = "ocamlfind -toolchain secondary ocamlc" in
let output_fn, out = Filename.open_temp_file "duneboot" "ocamlfind-output" in
let n = runf "%s 2>%s" compiler output_fn in
let s = read_file output_fn in
close_out out;
prerr_endline s;
if n <> 0 || s <> ""
then (
Format.eprintf
"@[%a@]@."
Format.pp_print_text
(let a, b, _ = min_supported_natively in
sprintf
"The ocamlfind's secondary toolchain does not seem to be correctly installed.\n\
Dune requires OCaml %d.%02d or later to compile.\n\
Please either upgrade your compile or configure a secondary OCaml compiler \
(in opam, this can be done by installing the ocamlfind-secondary package)."
a
b);
exit 2);
compiler, Some "--secondary")
in
exit_if_non_zero
(runf
"%s %s -g -o %s -I boot %sunix.cma %s"
compiler
(* Make sure to produce a self-contained binary as dlls tend to cause
issues *)
(if v < (4, 10, 1) then "-custom" else "-output-complete-exe")
prog
(if v >= (5, 0, 0) then "-I +unix " else "")
(List.map modules ~f:(fun m -> m ^ ".ml") |> String.concat ~sep:" "));
let args = List.tl (Array.to_list Sys.argv) in
let args =
match which with
| None -> args
| Some x -> x :: args
in
let args = Filename.concat "." prog :: args in
exit (runf "%s" (String.concat ~sep:" " args))
;;

View file

@ -0,0 +1,148 @@
#!/usr/bin/env ocaml
open StdLabels
open Printf
let list f l = sprintf "[%s]" (String.concat ~sep:"; " (List.map l ~f))
let string s = sprintf "%S" s
let option f = function
| None -> "None"
| Some x -> sprintf "Some %s" (f x)
;;
let out =
match Sys.getenv_opt "DUNE_CONFIGURE_OUTPUT" with
| None -> "src/dune_rules/setup.ml"
| Some out -> out
;;
let default_toggles : (string * [ `Disabled | `Enabled ]) list =
[ "toolchains", `Enabled
; "pkg_build_progress", `Disabled
; "lock_dev_tool", `Disabled
; "bin_dev_tools", `Disabled
; "portable_lock_dir", `Disabled
]
;;
let toggles = ref default_toggles
let toggle name v =
toggles := List.map !toggles ~f:(fun (x, y) -> x, if x = name then v else y)
;;
let toggle =
let toggles = [ "enable", `Enabled; "disable", `Disabled ] in
let options = List.map toggles ~f:fst in
fun name -> Arg.Symbol (options, fun s -> List.assoc s toggles |> toggle name)
;;
let () =
let bad fmt = ksprintf (fun s -> raise (Arg.Bad s)) fmt in
let prefix = ref None in
let library_path = ref [] in
let library_destdir = ref None in
let mandir = ref None in
let docdir = ref None in
let etcdir = ref None in
let bindir = ref None in
let sbindir = ref None in
let libexecdir = ref None in
let datadir = ref None in
let cwd = lazy (Sys.getcwd ()) in
let dir_of_string s =
if Filename.is_relative s then Filename.concat (Lazy.force cwd) s else s
in
let set_libdir s =
let dir = dir_of_string s in
library_path := dir :: !library_path;
library_destdir := Some dir
in
let set_dir v s =
let dir = dir_of_string s in
v := Some dir
in
let args =
[ "--prefix", Arg.String (set_dir prefix), "DIR where files are copied"
; ( "--libdir"
, Arg.String set_libdir
, "DIR where public libraries are looked up in the default build context. Can be \
specified multiple times new one taking precedence. The last is used as default \
destination directory for public libraries." )
; ( "--bindir"
, Arg.String (set_dir bindir)
, "DIR where public binaries are installed for the default build context" )
; ( "--sbindir"
, Arg.String (set_dir sbindir)
, "DIR where files for sbin section are installed for the default build context" )
; ( "--mandir"
, Arg.String (set_dir mandir)
, "DIR where man pages are installed for the default build context" )
; ( "--docdir"
, Arg.String (set_dir docdir)
, "DIR where documentation is installed for the default build context" )
; ( "--etcdir"
, Arg.String (set_dir etcdir)
, "DIR where configuration files are installed for the default build context" )
; ( "--libexecdir"
, Arg.String (set_dir libexecdir)
, "DIR where files for the libexec_root section are installed for the default \
build context. Use --libdir if specified" )
; ( "--datadir"
, Arg.String (set_dir datadir)
, "DIR where files for the share_root section are installed for the default build \
context" )
; ( "--toolchains"
, toggle "toolchains"
, " Enable the toolchains behaviour, allowing dune to install the compiler in a \
user-wide directory." )
; ( "--pkg-build-progress"
, toggle "pkg_build_progress"
, " Enable the displaying of package build progress.\n\
\ This flag is experimental and shouldn't be relied on by packagers." )
; ( "--lock-dev-tool"
, toggle "lock_dev_tool"
, " Enable ocamlformat dev-tool, allows 'dune fmt' to build ocamlformat and use \
it, independently from the project dependencies.\n\
\ This flag is experimental and shouldn't be relied on by packagers." )
; ( "--bin-dev-tools"
, toggle "bin_dev_tools"
, " Enable obtaining dev-tools binarys from the binary package opam repository. \
Allows fast installation of dev-tools. \n\
\ This flag is experimental and shouldn't be relied on by packagers." )
; ( "--portable-lock-dir"
, toggle "portable_lock_dir"
, "Generate portable lock dirs. If this feature is disabled then lock dirs will be \
specialized to the machine where they are generated." )
]
in
let anon s = bad "Don't know what to do with %s" s in
Arg.parse (Arg.align args) anon "Usage: ocaml configure.ml [OPTIONS]\nOptions are:";
(match !libexecdir with
| None -> libexecdir := !library_destdir
| Some _ -> ());
let oc = open_out out in
let pr fmt = fprintf oc (fmt ^^ "\n") in
pr "let library_path = %s\n" ((list string) !library_path);
pr "let roots : string option Install.Roots.t =";
pr " { lib_root = %s" (option string !library_destdir);
pr " ; man = %s" (option string !mandir);
pr " ; doc_root = %s" (option string !docdir);
pr " ; etc_root = %s" (option string !etcdir);
pr " ; share_root = %s" (option string !datadir);
pr " ; bin = %s" (option string !bindir);
pr " ; sbin = %s" (option string !sbindir);
pr " ; libexec_root = %s" (option string !libexecdir);
pr " }";
pr "";
pr "let prefix : string option = %s" (option string !prefix);
List.iter !toggles ~f:(fun (name, value) ->
pr
"let %s = `%s"
name
(match value with
| `Enabled -> "Enabled"
| `Disabled -> "Disabled"));
close_out oc
;;

View file

@ -0,0 +1,34 @@
(rule
(mode promote)
(action
(copy ../bin/bootstrap-info libs.ml)))
(alias
(name runtest)
(deps libs.ml))
(alias
(name check)
(deps libs.ml))
(executable
(name duneboot)
(modules :standard \ configure bootstrap)
(libraries unix))
(executable
(name configure)
(preprocess
(action
(run tail -n +2 %{input-file})))
(modules configure))
(executable
(name bootstrap)
(modules bootstrap))
;; For unused value warnings. We don't write a plain empty
;; duneboot.mli to simplify ../bootstrap.ml
(rule
(with-stdout-to duneboot.mli (progn)))

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,429 @@
type library =
{ path : string
; main_module_name : string option
; include_subdirs_unqualified : bool
; special_builtin_support : string option
}
let external_libraries = [ "unix"; "threads" ]
let local_libraries =
[ { path = "otherlibs/ordering"
; main_module_name = Some "Ordering"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/pp/src"
; main_module_name = Some "Pp"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dyn"
; main_module_name = Some "Dyn"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/csexp/src"
; main_module_name = Some "Csexp"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/stdune/src"
; main_module_name = Some "Stdune"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_graph"
; main_module_name = Some "Dune_graph"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/incremental-cycles/src"
; main_module_name = Some "Incremental_cycles"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dag"
; main_module_name = Some "Dag"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/fiber/src"
; main_module_name = Some "Fiber"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_console"
; main_module_name = Some "Dune_console"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/memo"
; main_module_name = Some "Memo"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_config"
; main_module_name = Some "Dune_config"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_async_io"
; main_module_name = Some "Dune_async_io"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/re/src"
; main_module_name = Some "Dune_re"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-glob/src"
; main_module_name = Some "Dune_glob"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_metrics"
; main_module_name = Some "Dune_metrics"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/ocaml-blake3-mini"
; main_module_name = Some "Blake3_mini"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/chrome-trace/src"
; main_module_name = Some "Chrome_trace"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/spawn/src"
; main_module_name = Some "Dune_spawn"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_stats"
; main_module_name = Some "Dune_stats"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/xdg"
; main_module_name = Some "Xdg"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/build_path_prefix_map/src"
; main_module_name = Some "Build_path_prefix_map"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/uutf"
; main_module_name = Some "Dune_uutf"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_sexp"
; main_module_name = Some "Dune_sexp"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_util"
; main_module_name = Some "Dune_util"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_digest"
; main_module_name = Some "Dune_digest"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/predicate_lang"
; main_module_name = Some "Predicate_lang"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/fiber_util"
; main_module_name = Some "Fiber_util"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_cache_storage"
; main_module_name = Some "Dune_cache_storage"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_targets"
; main_module_name = Some "Dune_targets"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_cache"
; main_module_name = Some "Dune_cache"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/ocamlc-loc/src"
; main_module_name = Some "Ocamlc_loc"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-rpc/private"
; main_module_name = Some "Dune_rpc_private"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-action-plugin/src"
; main_module_name = Some "Dune_action_plugin"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_output_truncation"
; main_module_name = Some "Dune_output_truncation"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/csexp_rpc"
; main_module_name = Some "Csexp_rpc"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_rpc_client"
; main_module_name = Some "Dune_rpc_client"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_thread_pool"
; main_module_name = Some "Dune_thread_pool"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/fsevents"
; main_module_name = Some "Fsevents"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/ocaml-inotify/src"
; main_module_name = Some "Ocaml_inotify"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/async_inotify_for_dune"
; main_module_name = Some "Async_inotify_for_dune"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/fswatch_win"
; main_module_name = Some "Fswatch_win"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_file_watcher"
; main_module_name = Some "Dune_file_watcher"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_engine"
; main_module_name = Some "Dune_engine"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/action_ext"
; main_module_name = Some "Action_ext"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/promote"
; main_module_name = Some "Promote"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/ocaml-config"
; main_module_name = Some "Ocaml_config"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/ocaml"
; main_module_name = Some "Ocaml"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/sha"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/opam/src/core"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/opam-file-format"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/opam/src/format"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-private-libs/section"
; main_module_name = Some "Dune_section"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_lang"
; main_module_name = Some "Dune_lang"
; include_subdirs_unqualified = true
; special_builtin_support = None
}
; { path = "src/fiber_event_bus"
; main_module_name = Some "Fiber_event_bus"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-private-libs/meta_parser"
; main_module_name = Some "Dune_meta_parser"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/fs"
; main_module_name = Some "Fs"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_findlib"
; main_module_name = Some "Dune_findlib"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_vcs"
; main_module_name = Some "Dune_vcs"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-build-info/src"
; main_module_name = Some "Build_info"
; include_subdirs_unqualified = false
; special_builtin_support = Some "Build_info_data"
}
; { path = "src/sat"
; main_module_name = Some "Sat"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_pkg"
; main_module_name = Some "Dune_pkg"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/install"
; main_module_name = Some "Install"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_threaded_console"
; main_module_name = Some "Dune_threaded_console"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/lwd/lwd"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/notty/src"
; main_module_name = None
; include_subdirs_unqualified = true
; special_builtin_support = None
}
; { path = "vendor/notty/src-unix"
; main_module_name = None
; include_subdirs_unqualified = true
; special_builtin_support = None
}
; { path = "vendor/lwd/nottui"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_tui"
; main_module_name = Some "Dune_tui"
; include_subdirs_unqualified = true
; special_builtin_support = None
}
; { path = "src/dune_config_file"
; main_module_name = Some "Dune_config_file"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_patch"
; main_module_name = Some "Dune_patch"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "otherlibs/dune-site/src/private"
; main_module_name = Some "Dune_site_private"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/scheme"
; main_module_name = Some "Scheme"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/source"
; main_module_name = Some "Source"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_rules"
; main_module_name = Some "Dune_rules"
; include_subdirs_unqualified = true
; special_builtin_support = None
}
; { path = "src/upgrader"
; main_module_name = Some "Dune_upgrader"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "vendor/cmdliner/src"
; main_module_name = None
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_rpc_server"
; main_module_name = Some "Dune_rpc_server"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_rpc_impl"
; main_module_name = Some "Dune_rpc_impl"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
; { path = "src/dune_rules_rpc"
; main_module_name = Some "Dune_rules_rpc"
; include_subdirs_unqualified = false
; special_builtin_support = None
}
]
let build_flags =
[ ([ "win32"; "win64"; "mingw"; "mingw64" ],
[ "-ccopt"; "-D_UNICODE"; "-ccopt"; "-DUNICODE" ])
]
let link_flags =
[ ([ "macosx" ],
[ "-cclib"
; "-framework CoreFoundation"
; "-cclib"
; "-framework CoreServices"
])
; ([ "win32"; "win64"; "mingw"; "mingw64" ],
[ "-cclib"; "-lshell32"; "-cclib"; "-lole32"; "-cclib"; "-luuid" ])
; ([ "beos" ], [ "-cclib"; "-lbsd" ])
]