Skip to content

Commit

Permalink
Move Windows stubs to opam-core
Browse files Browse the repository at this point in the history
As opam now routinely has stubs, eliminate the complicated dances for
only linking stub libraries on Windows.
  • Loading branch information
dra27 authored and kit-ty-kate committed Sep 17, 2024
1 parent 024e355 commit f180373
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 159 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ src/ocaml-flags-configure.sexp
src/**/.merlin
src/client/linking.sexp
src/client/no-git-version
src/core/cc64
src/core/c-flags.sexp
src/core/developer
src/manifest/dune
src/manifest/install.inc
src/stubs/win32/cc64
src/stubs/win32/dune
src/stubs/c-flags.sexp
# doc
doc/dev-manual/*aux
doc/dev-manual/*.html
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ clean:
distclean: clean clean-ext
rm -rf autom4te.cache bootstrap
rm -f Makefile.config config.log config.status aclocal.m4
rm -f src/*.META src/*/.merlin src/manifest/dune src/manifest/install.inc src/stubs/win32/dune src/stubs/win32/cc64 src/ocaml-flags-configure.sexp
rm -f src/client/linking.sexp src/stubs/c-flags.sexp src/core/developer src/core/version
rm -f src/*.META src/*/.merlin src/manifest/dune src/manifest/install.inc src/stubs/win32/dune src/core/cc64 src/ocaml-flags-configure.sexp
rm -f src/client/linking.sexp src/core/c-flags.sexp src/core/developer src/core/version

OPAMINSTALLER_FLAGS = --prefix "$(call CYGPATH,$(DESTDIR)$(prefix))"
OPAMINSTALLER_FLAGS += --mandir "$(call CYGPATH,$(DESTDIR)$(mandir))"
Expand Down
36 changes: 13 additions & 23 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 12 additions & 19 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ AS_IF([ test ${WIN32} -eq 1 ],[
ac_tool_prefix='x86_64-w64-mingw32-'])])
AC_CHECK_TOOL(CC64,[${T_CC64}],[no])
AS_IF([ test "x${CC64}" != "xno" ],[
echo "${CC64} -o " > src/stubs/win32/cc64
echo " -Wdeclaration-after-statement -municode " >> src/stubs/win32/cc64
echo "${CC64} -o " > src/core/cc64
echo " -Wdeclaration-after-statement -municode " >> src/core/cc64
])
],[
AC_MSG_CHECKING([whether Microsoft Linker needs a PATH shim])
Expand All @@ -223,14 +223,14 @@ AS_IF([ test ${WIN32} -eq 1 ],[
AC_MSG_RESULT([from $MSVS_NAME])
CL_FULL="`PATH="${MSVS_PATH}:${PATH}" which cl | cygpath -f - -w`"
MSVS_PATH="`echo "${MSVS_PATH}" | cygpath -f - -wp`"
echo "cl /nologo /Fe" > src/stubs/win32/cc64
echo " " >> src/stubs/win32/cc64
echo "PATH" >> src/stubs/win32/cc64
echo "${MSVS_PATH}" >> src/stubs/win32/cc64
echo "LIB" >> src/stubs/win32/cc64
echo "${MSVS_LIB}" >> src/stubs/win32/cc64
echo "INCLUDE" >> src/stubs/win32/cc64
echo "${MSVS_INC}" >> src/stubs/win32/cc64
echo "cl /nologo /Fe" > src/core/cc64
echo " " >> src/core/cc64
echo "PATH" >> src/core/cc64
echo "${MSVS_PATH}" >> src/core/cc64
echo "LIB" >> src/core/cc64
echo "${MSVS_LIB}" >> src/core/cc64
echo "INCLUDE" >> src/core/cc64
echo "${MSVS_INC}" >> src/core/cc64
])
])
AS_IF([ test "x${CC64}" = "xno" ],[
Expand Down Expand Up @@ -330,7 +330,7 @@ AS_CASE([$TARGET],
# NOTE: On Windows, the Windows specific dlls should stay dynamic for security reasons
# NOTE: -l:libstdc++.a is necessary (vs. -lstdc++) as flexlink will use libstdc++.dll.a
# which still depends on the DLL at runtime instead of libstdc++.a (that looks like a bug in flexlink)
platform_dependent_stuff="-cclib -lopam_stubs_win32_stubs -cclib -l:libstdc++.a -cclib -l:libpthread.a -cclib -Wl,-static -cclib -ladvapi32 -cclib -lgdi32 -cclib -luser32 -cclib -lshell32 -cclib -lole32 -cclib -luuid -cclib -luserenv"
platform_dependent_stuff="-cclib -l:libstdc++.a -cclib -l:libpthread.a -cclib -Wl,-static -cclib -ladvapi32 -cclib -lgdi32 -cclib -luser32 -cclib -lshell32 -cclib -lole32 -cclib -luuid -cclib -luserenv"
AS_IF([test "x${SYSTEM}" = "xmingw"], [platform_dependent_stuff="${platform_dependent_stuff} -cclib -lwindowsapp"])
])
AS_CASE([${support_static},${enable_static}],
Expand Down Expand Up @@ -433,7 +433,7 @@ fi
AC_CONFIG_FILES(
Makefile.config
src/ocaml-flags-configure.sexp
src/stubs/c-flags.sexp
src/core/c-flags.sexp
)
AC_OUTPUT

Expand All @@ -449,13 +449,6 @@ AS_IF([test "x${with_private_runtime}" != "xno"],[
])
])

rm -f src/stubs/win32/dune
AS_IF([ test ${WIN32} -eq 1],[
cd src/stubs/win32
${LN_S} -f dune-win32 dune
cd ../../..
])

echo

bindir="`eval echo ${bindir}`"
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 2.0)
(lang dune 2.6)
(name opam)

(implicit_transitive_deps true)
Expand Down
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ users)
* Require opam-0install-cudf >= 0.5.0 [#6130 @kit-ty-kate]
* Bump the vendored mccs to 1.1+18 [#6170 @kit-ty-kate]
* Fix Windows builds with OCaml >= 5.0 [#6189 @kit-ty-kate - fix #6148]
* Upgrade the minimum required version for dune from 2.0.0 to 2.6.0 [#5381 @dra27]

## Infrastructure

Expand Down Expand Up @@ -158,6 +159,7 @@ users)
* Speedup OpamVersionCompare by 25% by removing the unused handling of epoch [#5518 @kit-ty-kate]
* Fix error in `OpamSystem.transform_patch` - patches were only applied when debugging [#6182 @dra27 regression since #3449]
* Remove `--with-acl` option from the configure script and its related C stubs (reverts a Cygwin fix in #4265) [#5381 @kit-ty-kate - fix #5373]
* Move Windows stubs to opam-core [#5381 @dra27]

## Internal: Windows

Expand Down
2 changes: 1 addition & 1 deletion opam-client.opam
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ depends: [
"opam-repository" {= version}
"re" {>= "1.10.0"}
"cmdliner" {>= "1.1.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
]
conflicts: [
"extlib" {< "1.7.8"}
Expand Down
2 changes: 1 addition & 1 deletion opam-core.opam
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ depends: [
"base-unix"
"ocamlgraph"
"re" {>= "1.9.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
"sha" {>= "1.13"}
"jsonm"
"swhid_core"
Expand Down
2 changes: 1 addition & 1 deletion opam-devel.opam
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ depends: [
"ocaml" {>= "4.08.0"}
"opam-client" {= version}
"cmdliner" {>= "1.1.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
"conf-openssl" {with-test}
"conf-diffutils" {with-test}
]
Expand Down
2 changes: 1 addition & 1 deletion opam-format.opam
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ depends: [
"opam-core" {= version}
"opam-file-format" {>= "2.1.4"}
"re" {>= "1.9.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
]
2 changes: 1 addition & 1 deletion opam-installer.opam
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ depends: [
"ocaml" {>= "4.08.0"}
"opam-format" {= version}
"cmdliner" {>= "0.9.8"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
]
2 changes: 1 addition & 1 deletion opam-repository.opam
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ build: [
depends: [
"ocaml" {>= "4.08.0"}
"opam-format" {= version}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
]
2 changes: 1 addition & 1 deletion opam-solver.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ depends: [
"dose3" {>= "6.1"}
"cudf" {>= "0.7"}
"re" {>= "1.9.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
"opam-0install-cudf" {>= "0.5.0"}
]
depopts: [
Expand Down
2 changes: 1 addition & 1 deletion opam-state.opam
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ depends: [
"opam-repository" {= version}
"re" {>= "1.9.0"}
"spdx_licenses" {>= "1.0.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.6.0"}
]
File renamed without changes.
File renamed without changes.
42 changes: 32 additions & 10 deletions src/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,39 @@
(public_name opam-core)
(synopsis "OCaml Package Manager core internal stdlib")
; TODO: Remove (re_export ...) when CI uses the OCaml version that includes https://github.com/ocaml/ocaml/pull/11989
(libraries re (re_export ocamlgraph) unix sha jsonm swhid_core uutf
(select opamStubs.ml from
(opam-core.stubs -> opamStubs.win32.ml)
( -> opamStubs.dummy.ml)))
(libraries re (re_export ocamlgraph) unix sha jsonm swhid_core uutf)
(flags (:standard
(:include ../ocaml-flags-standard.sexp)
(:include ../ocaml-flags-configure.sexp)
(:include ../ocaml-context-flags.sexp)))
(foreign_stubs
(language c)
(names opamCommonStubs)
(names opam_stubs)
(flags :standard
-DUNICODE -D_UNICODE -DCAML_NAME_SPACE
(:include ../stubs/c-flags.sexp)))
(:include c-flags.sexp)))
(c_library_flags (:standard
(:include c-libraries.sexp)))
(wrapped false))

(rule
(deps opamWindows.c opamInject.c)
(action (copy# opamCommonStubs.c opam_stubs.c)))

(rule
(copy# opamStubsTypes.ml opamStubsTypes.mli))

(rule
(enabled_if (< %{ocaml_version} "5.0"))
(action (copy# opamStubs.ocaml4.ml opamStubs.win32.ml)))
(enabled_if (<> %{os_type} "Win32"))
(action (copy# opamStubs.unix.ml opamStubs.ml)))

(rule
(enabled_if (>= %{ocaml_version} "5.0"))
(action (copy# opamStubs.ocaml5.ml opamStubs.win32.ml)))
(enabled_if (and (= %{os_type} "Win32") (< %{ocaml_version} "5.0")))
(action (copy# opamStubs.ocaml4.ml opamStubs.ml)))

(rule
(enabled_if (and (= %{os_type} "Win32") (>= %{ocaml_version} "5.0")))
(action (copy# opamStubs.ocaml5.ml opamStubs.ml)))

(rule
(write-file opamCoreConfigDeveloper.ml
Expand All @@ -50,5 +55,22 @@
(mode fallback)
(action (with-stdout-to %{targets} (echo ""))))

(rule
(enabled_if (= %{os_type} "Win32"))
(targets opam-putenv.exe)
(deps opamInject.c)
(action (run ocaml %{dep:../../shell/build-putenv.ml} %{targets} %{dep:opam-putenv.c} %{dep:cc64})))

(install
(enabled_if (= %{os_type} "Win32"))
(section bin)
(package opam)
(files opam-putenv.exe))

(rule
(with-stdout-to c-libraries.sexp (run ocaml %{dep:../../shell/context_flags.ml} clibs)))

(rule
(targets c-flags.sexp)
(mode fallback)
(action (with-stdout-to %{targets} (echo "()"))))
File renamed without changes.
6 changes: 6 additions & 0 deletions src/core/opamCommonStubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ CAMLprim value opam_is_executable(value path)
caml_stat_free(p);
CAMLreturn(Val_bool(ret == 0));
}

/* This is done here as it simplifies the dune file */
#ifdef _WIN32
#include "opamInject.c"
#include "opamWindows.c"
#endif
File renamed without changes.
39 changes: 37 additions & 2 deletions src/core/opamStubs.ocaml4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,44 @@
(**************************************************************************)

include OpamStubsTypes
include OpamWin32Stubs
let getpid () = Int32.to_int (getCurrentProcessID ())

external getCurrentProcessID : unit -> int32 = "OPAMW_GetCurrentProcessID"
let getpid () = Int32.to_int (getCurrentProcessID ())
(* Polymorphic parameters below are used as placeholders for types in
* OpamStubsTypes - it's not worth the effort of propagating the types here,
* even if it does result in some ugly-looking primitives!
*)
external getStdHandle : 'a -> 'b = "OPAMW_GetStdHandle"
external getConsoleScreenBufferInfo : 'a -> 'b = "OPAMW_GetConsoleScreenBufferInfo"
external setConsoleTextAttribute : 'a -> int -> unit = "OPAMW_SetConsoleTextAttribute"
external fillConsoleOutputCharacter : 'a -> char -> int -> int * int -> bool = "OPAMW_FillConsoleOutputCharacter"
external getConsoleMode : 'a -> int = "OPAMW_GetConsoleMode"
external setConsoleMode : 'a -> int -> bool = "OPAMW_SetConsoleMode"
external getWindowsVersion : unit -> int * int * int * int = "OPAMW_GetWindowsVersion"
external getArchitecture : unit -> 'a = "OPAMW_GetArchitecture"
external waitpids : int list -> int -> int * Unix.process_status = "OPAMW_waitpids"
external readRegistry : 'a -> string -> string -> 'b -> 'c option = "OPAMW_ReadRegistry"
external enumRegistry : 'a -> string -> 'b -> (string * 'c) list = "OPAMW_RegEnumValue"
external writeRegistry : 'a -> string -> string -> 'b -> 'c -> unit = "OPAMW_WriteRegistry"
external getConsoleOutputCP : unit -> int = "OPAMW_GetConsoleOutputCP"
external getCurrentConsoleFontEx : 'a -> bool -> 'b = "OPAMW_GetCurrentConsoleFontEx"
external create_glyph_checker : string -> 'a * 'a = "OPAMW_CreateGlyphChecker"
external delete_glyph_checker : 'a * 'a -> unit = "OPAMW_DeleteGlyphChecker"
external has_glyph : 'a * 'a -> Uchar.t -> bool = "OPAMW_HasGlyph"
external getProcessArchitecture : int32 option -> 'a = "OPAMW_GetProcessArchitecture"
external process_putenv : int32 -> string -> string -> bool = "OPAMW_process_putenv"
external getPathToHome : unit -> string = "OPAMW_GetPathToHome"
external getPathToSystem : unit -> string = "OPAMW_GetPathToSystem"
external getPathToLocalAppData : unit -> string = "OPAMW_GetPathToLocalAppData"
external sendMessageTimeout : nativeint -> int -> int -> 'a -> 'b -> 'c -> int * 'd = "OPAMW_SendMessageTimeout_byte" "OPAMW_SendMessageTimeout"
external getProcessAncestry : unit -> (int32 * string) list = "OPAMW_GetProcessAncestry"
external getConsoleAlias : string -> string -> string = "OPAMW_GetConsoleAlias"
external getConsoleWindowClass : unit -> string option = "OPAMW_GetConsoleWindowClass"
external setErrorMode : int -> int = "OPAMW_SetErrorMode"
external getErrorMode : unit -> int = "OPAMW_GetErrorMode"
external setConsoleToUTF8 : unit -> unit = "OPAMW_SetConsoleToUTF8"
external getVersionInfo : string -> 'a option = "OPAMW_GetVersionInfo"
external get_initial_environment : unit -> string list = "OPAMW_CreateEnvironmentBlock"
external win_create_process : string -> string -> string option ->
Unix.file_descr -> Unix.file_descr -> Unix.file_descr -> int
= "win_create_process" "win_create_process_native"
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/opamStubsTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(* *)
(**************************************************************************)

(** Types for C stubs modules. *)
(** Types for C stubs modules and common C stubs. *)

(** CONSOLE_SCREEN_BUFFER_INFO struct
(see https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str)
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions src/stubs/dune

This file was deleted.

Loading

0 comments on commit f180373

Please sign in to comment.