Skip to content

Commit 52d81e4

Browse files
committed
Explicitly set MSVS environment
I've found out that opam won't bootstrap OCaml without this under MSVC.
1 parent c64ced1 commit 52d81e4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src-opam/opam.ml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,26 @@ let install_opam_from_source ?(add_default_link = true) ?(prefix = "/usr/local")
4949

5050
(* Build opam in a separate worktree from an already cloned opam *)
5151
let install_opam_from_source_windows ?cyg ?prefix
52-
?(enable_0install_solver = false) ~branch ~hash () =
52+
?(enable_0install_solver = false) ?(msvs = false) ~branch ~hash () =
53+
(* Although opam's readme states it can autodetec the environment
54+
with MSVS, it doesn't always work. It's set explicitly here. *)
55+
let msvs_env =
56+
{|eval $(msvs-detect --arch=x64) && export PATH="$MSVS_PATH:$PATH" && export LIB="$MSVS_LIB" && export INCLUDE="$MSVS_INC" && |}
57+
and ocaml_port = "OCAML_PORT=msvc64 " in
5358
Windows.Cygwin.run_sh ?cyg
5459
"cd /tmp/opam-sources && cp -P -R -p . ../opam-build-%s && cd \
5560
../opam-build-%s && git checkout %s && git config --global --add \
5661
safe.directory /tmp/opam-build-%s"
5762
branch branch hash branch
5863
@@ Windows.Cygwin.run_sh ?cyg
59-
"cd /tmp/opam-build-%s && make compiler && make lib-pkg" branch
64+
"cd /tmp/opam-build-%s && %smake compiler %s&& make lib-pkg" branch
65+
(if msvs then msvs_env else "")
66+
(if msvs then ocaml_port else "")
6067
@@ Windows.Cygwin.run_sh ?cyg
61-
"cd /tmp/opam-build-%s && ./configure --enable-cold-check \
68+
"cd /tmp/opam-build-%s && %s./configure --enable-cold-check \
6269
--with-private-runtime%s%s && make && make install"
6370
branch
71+
(if msvs then msvs_env else "")
6472
(Option.fold prefix ~none:"" ~some:(fun prefix ->
6573
Printf.sprintf {| --prefix="%s"|} prefix))
6674
(if enable_0install_solver then " --with-0install-solver" else "")
@@ -247,7 +255,7 @@ let install_opams ?prefix opam_master_hash opam_branches =
247255
~enable_0install_solver ~branch ~hash ())
248256
empty opam_branches
249257

250-
let install_opams_windows ?cyg ?prefix opam_master_hash opam_branches =
258+
let install_opams_windows ?cyg ?prefix ?msvs opam_master_hash opam_branches =
251259
Windows.Cygwin.Git.init ?cyg ~repos:[ "/tmp/opam-sources" ] ()
252260
@@ Windows.Cygwin.run_sh ?cyg
253261
"git clone https://github.com/ocaml/opam /tmp/opam && cd /tmp/opam && \
@@ -256,7 +264,7 @@ let install_opams_windows ?cyg ?prefix opam_master_hash opam_branches =
256264
@@ List.fold_left
257265
(fun acc { branch; hash; enable_0install_solver; _ } ->
258266
acc
259-
@@ install_opam_from_source_windows ?cyg ?prefix
267+
@@ install_opam_from_source_windows ?cyg ?prefix ?msvs
260268
~enable_0install_solver ~branch ~hash ())
261269
empty opam_branches
262270

@@ -484,8 +492,8 @@ let windows_msvc_opam2 ?win10_revision ?winget ?(labels = []) ~opam_hashes
484492
Windows.header ~alias:"opam-builder" ?win10_revision ~version ()
485493
@@ Windows.sanitize_reg_path ()
486494
@@ vs_build_tools
487-
@@ Windows.Cygwin.install_cygwin ~extra:packages ()
488-
@@ install_opams_windows opam_master_hash opam_branches
495+
@@ Windows.Cygwin.install_cygwin ~msvs_tools:true ~extra:packages ()
496+
@@ install_opams_windows ~msvs:true opam_master_hash opam_branches
489497
in
490498
(* 2022-10-12: Docker Engine 20.10.18 on Windows fails copying
491499
C:\cygwin64, so we cannot build Cygwin in a separate image. *)

0 commit comments

Comments
 (0)