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 0e74798 commit 1e79693
Show file tree
Hide file tree
Showing 28 changed files with 119 additions and 170 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
14 changes: 3 additions & 11 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,12 @@ <h1>opam %{OPAMVERSION}% API and libraries documentation</h1>
<td>C stubs for Windows. A &ldquo;dummy&rdquo; alternate is provided for Unix, which doesn&rsquo;t require any C code</td></tr>
<tr><th><a href="opam-core/OpamStubsTypes">opamStubsTypes.ml</a></th>
<td>Types in the stubs definitions (shared between both implementations)</td></tr>

<tr class="lib">
<th><code>src/stubs</code></th>
<td><em>opam-stubs</em> library</td>
</tr>

<tr><td colspan="2" class="libnote">
C stubs. This library is built on Windows-only and automatically pulled into opam-core if needed
</td></tr>

<tr><th><a>opamInject.c</a></th>
<td>Code for process injection shared between <a>opamWindows.c</a> and <a>opam-putenv.c</a></td></tr>
<tr><th><a>opamWindows.c</a></th>
<td>C stubs themselves</td></tr>
<td>C stubs for Windows</td></tr>
<tr><th><a>opamCommonStubs.c</a></th>
<td>Common C stubs for Unix and Windows</td></tr>

<tr class="lib">
<th><a href="opam-format"><code>src/format</code></a></th>
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.
Loading

0 comments on commit 1e79693

Please sign in to comment.