Skip to content

Commit

Permalink
Add --with-private-runtime configure option
Browse files Browse the repository at this point in the history
If opam is compiled with the mingw-w64 version of Windows OCaml and an
internal solver, then additional DLLs are required at runtime. These can
either:

 1. Be included in a directory in PATH (this is very bad, if done by
    other packages)
 2. Be included in the same directory as opam.exe (this is similarly
    bad, because opam.exe is likely to end up in PATH)
 3. Be manifested in another directory

The --with-private-runtime option sets up the appropriate DLLs in the
directory Opam.Runtime.amd64 (or Opam.Runtime.x86) and adds them and the
manifest to opam.install. It also overrides the manifest automatically
included by gcc to instruct the Windows loader to search for the DLLs in
the runtime directory.
  • Loading branch information
dra27 committed Apr 5, 2018
1 parent c8c39af commit 4ac97e7
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ src_ext/archives/*
src_ext/*.*download
src_ext/*.pkgbuild
src_ext/jbuild-ignore
Opam.Runtime.*/
*.tar.bz2
*.annot
*.tar.gz
Expand Down Expand Up @@ -65,6 +66,9 @@ config.status
aclocal.m4
autom4te.cache
src/*/.merlin
src/client/manifest.inc
src/client/opamManifest.inc
src/client/*.dll
src/stubs/jbuild
src/tools/opam-putenv.inc
# doc
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ jbuilder: $(JBUILDER_DEP)

opam: $(JBUILDER_DEP) opam.install
$(LN_S) -f _build/default/src/client/opamMain.exe $@$(EXE)
ifneq ($(MANIFEST_ARCH),)
@mkdir -p Opam.Runtime.$(MANIFEST_ARCH)
@cp -f src/client/Opam.Runtime.$(MANIFEST_ARCH).manifest Opam.Runtime.$(MANIFEST_ARCH)/
@cd Opam.Runtime.$(MANIFEST_ARCH) && $(LN_S) -f ../src/client/libstdc++-6.dll .
@cd Opam.Runtime.$(MANIFEST_ARCH) && $(LN_S) -f ../src/client/libwinpthread-1.dll .
@cd Opam.Runtime.$(MANIFEST_ARCH) && $(LN_S) -f ../src/client/$(RUNTIME_GCC_S).dll .
endif

opam-installer: $(JBUILDER_DEP)
$(JBUILDER) build $(JBUILDER_ARGS) src/tools/opam_installer.exe
Expand Down Expand Up @@ -61,12 +68,13 @@ clean-ext:
clean:
$(MAKE) -C doc $@
rm -f *.install *.env *.err *.info *.out opam$(EXE) opam-admin.top$(EXE) opam-installer$(EXE)
rm -rf _build
rm -rf _build Opam.Runtime.*

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/stubs/jbuild src/tools/opam-putenv.inc
rm -f src/*.META src/*/.merlin src/stubs/jbuild src/client/*.dll
rm -f src/tools/opam-putenv.inc src/client/manifest.inc src/client/opamManifest.inc

OPAMINSTALLER_FLAGS = --prefix "$(DESTDIR)$(prefix)"
OPAMINSTALLER_FLAGS += --mandir "$(DESTDIR)$(mandir)"
Expand Down
3 changes: 3 additions & 0 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ LIB_PREFIX = @LIB_PREFIX@
CPATH = @CPATH@
LIBRARY_PATH = @LIBRARY_PATH@

MANIFEST_ARCH = @MANIFEST_ARCH@
RUNTIME_GCC_S = @RUNTIME_GCC_S@

export OCAMLVERSION OCAMLFIND OCAML OCAMLC OCAMLOPT EXE PATH INCLUDE LIB CPATH LIBRARY_PATH OCAMLLIB
78 changes: 77 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ OCAML_PKG_re
OCAML_PKG_extlib
OCAML_PKG_bigarray
OCAML_PKG_unix
CONF_MANIFEST_O
RUNTIME_GCC_S
MANIFEST_ARCH
TOOL_ARCH
fetch
LN_S
JBUILDER
Expand All @@ -625,6 +629,7 @@ CPPFLAGS
LDFLAGS
CFLAGS
CC
SYSTEM
AWK
LIBRARY_PATH
CPATH
Expand Down Expand Up @@ -693,6 +698,7 @@ enable_version_check
enable_checks
enable_developer_mode
with_mccs
with_private_runtime
enable_certificate_check
'
ac_precious_vars='build_alias
Expand Down Expand Up @@ -1342,6 +1348,8 @@ Optional Packages:
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--without-mccs Compile without a built-in Cudf solver (only works
if 'mccs' is not otherwise installed)
--with-private-runtime For a mingw-w64 build, manifest the runtime DLLs
locally in Opam.Runtime.arch
Some influential environment variables:
CC C compiler command
Expand Down Expand Up @@ -3150,6 +3158,16 @@ else
fi
# Check whether --with-private_runtime was given.
if test "${with_private_runtime+set}" = set; then :
withval=$with_private_runtime;
else
with_private_runtime=no
fi
if test "x" != "x$LIB_PREFIX"; then :
CPATH=$CPATH:$LIB_PREFIX/include
Expand Down Expand Up @@ -3273,6 +3291,12 @@ else
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ARCH" >&5
$as_echo "$ARCH" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler system" >&5
$as_echo_n "checking for compiler system... " >&6; }
SYSTEM=`$OCAML shell/print_config.ml system 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/system: //p"`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SYSTEM" >&5
$as_echo "$SYSTEM" >&6; }
LIB_PREPEND=
INC_PREPEND=
Expand Down Expand Up @@ -4546,6 +4570,46 @@ elif test x"${enable_checks}" != x"no" ; then
as_fn_error $? "You must have either curl or wget installed." "$LINENO" 5
fi
if test "x${with_private_runtime}" != "xno"; then :
if test ${WIN32} -eq 1 -a "x${CCOMP_TYPE}" = "xcc"; then :
CONF_MANIFEST_O=opam-manifest.o
if test "$ARCH" = "i386" ; then :
TOOL_ARCH=i686
MANIFEST_ARCH=x86
RUNTIME_GCC_S=libgcc_s_sjlj-1
else
TOOL_ARCH=x86_64
MANIFEST_ARCH=amd64
RUNTIME_GCC_S=libgcc_s_seh-1
fi
RUNTIME=`${TOOL_ARCH}-w64-mingw32-gcc -print-sysroot`/mingw/bin
echo Linking ${SYSTEM} runtime DLLs
${LN_S} -fv ${RUNTIME}/${RUNTIME_GCC_S}.dll src/client/${RUNTIME_GCC_S}.dll
${LN_S} -fv ${RUNTIME}/libstdc++-6.dll src/client/libstdc++-6.dll
${LN_S} -fv ${RUNTIME}/libwinpthread-1.dll src/client/libwinpthread-1.dll
else
CONF_MANIFEST_O=
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --with-private-runtime ignored (not building on mingw)" >&5
$as_echo "$as_me: WARNING: --with-private-runtime ignored (not building on mingw)" >&2;}
fi
else
CONF_MANIFEST_O=
fi
echo
Expand Down Expand Up @@ -5188,7 +5252,17 @@ else
> src/tools/opam-putenv.inc
fi
ac_config_files="$ac_config_files Makefile.config"
if test -n "${CONF_MANIFEST_O}" ; then :
ac_config_files="$ac_config_files src/client/manifest.inc"
else
> src/client/manifest.inc
fi
ac_config_files="$ac_config_files Makefile.config src/client/opamManifest.inc"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
Expand Down Expand Up @@ -5897,7 +5971,9 @@ for ac_config_target in $ac_config_targets
do
case $ac_config_target in
"src/tools/opam-putenv.inc") CONFIG_FILES="$CONFIG_FILES src/tools/opam-putenv.inc" ;;
"src/client/manifest.inc") CONFIG_FILES="$CONFIG_FILES src/client/manifest.inc" ;;
"Makefile.config") CONFIG_FILES="$CONFIG_FILES Makefile.config" ;;
"src/client/opamManifest.inc") CONFIG_FILES="$CONFIG_FILES src/client/opamManifest.inc" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
Expand Down
46 changes: 45 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ AC_ARG_WITH([mccs],
[Compile without a built-in Cudf solver (only works if 'mccs' is not otherwise installed)]),[],[MCCS_DEFAULT=yes]
)

AC_ARG_WITH([private_runtime],
AC_HELP_STRING([--with-private-runtime],
[For a mingw-w64 build, manifest the runtime DLLs locally in Opam.Runtime.arch]),,[with_private_runtime=no]
)

AS_IF([test "x" != "x$LIB_PREFIX"], [
CPATH=$CPATH:$LIB_PREFIX/include
LIBRARY_PATH=$LIBRARY_PATH:$LIB_PREFIX/lib
Expand All @@ -80,6 +85,10 @@ AC_MSG_CHECKING([for compiler architecture])
ARCH=`$OCAML shell/print_config.ml arch 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/architecture: //p"`
AS_IF([ test "$?" -eq 0 ],,[AC_MSG_ERROR([failed])] )
AC_MSG_RESULT([$ARCH])
AC_MSG_CHECKING([for compiler system])
SYSTEM=`$OCAML shell/print_config.ml system 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/system: //p"`
AC_MSG_RESULT([$SYSTEM])
AC_SUBST(SYSTEM)

LIB_PREPEND=
INC_PREPEND=
Expand Down Expand Up @@ -224,6 +233,33 @@ elif test x"${enable_checks}" != x"no" ; then
AC_MSG_ERROR([You must have either curl or wget installed.])
fi

AS_IF([test "x${with_private_runtime}" != "xno"],[
AS_IF([test ${WIN32} -eq 1 -a "x${CCOMP_TYPE}" = "xcc"],[
CONF_MANIFEST_O=opam-manifest.o
AS_IF([ test "$ARCH" = "i386" ],[
TOOL_ARCH=i686
MANIFEST_ARCH=x86
RUNTIME_GCC_S=libgcc_s_sjlj-1
],[
TOOL_ARCH=x86_64
MANIFEST_ARCH=amd64
RUNTIME_GCC_S=libgcc_s_seh-1
])
RUNTIME=`${TOOL_ARCH}-w64-mingw32-gcc -print-sysroot`/mingw/bin
echo Linking ${SYSTEM} runtime DLLs
${LN_S} -fv ${RUNTIME}/${RUNTIME_GCC_S}.dll src/client/${RUNTIME_GCC_S}.dll
${LN_S} -fv ${RUNTIME}/libstdc++-6.dll src/client/libstdc++-6.dll
${LN_S} -fv ${RUNTIME}/libwinpthread-1.dll src/client/libwinpthread-1.dll
AC_SUBST(TOOL_ARCH)
AC_SUBST(MANIFEST_ARCH)
AC_SUBST(RUNTIME_GCC_S)
],[
CONF_MANIFEST_O=
AC_MSG_WARN([--with-private-runtime ignored (not building on mingw)])
])
],[CONF_MANIFEST_O=])
AC_SUBST(CONF_MANIFEST_O)

echo

AC_CHECK_OCAML_PKG([unix])
Expand Down Expand Up @@ -303,7 +339,15 @@ AS_IF([ test ${BUILD_PUTENV} -eq 1],[
],[
> src/tools/opam-putenv.inc
])
AC_CONFIG_FILES(Makefile.config)
AS_IF([ test -n "${CONF_MANIFEST_O}" ],[
AC_CONFIG_FILES(src/client/manifest.inc)
],[
> src/client/manifest.inc
])
AC_CONFIG_FILES(
Makefile.config
src/client/opamManifest.inc
)
AC_OUTPUT

AS_IF([ test ${WIN32} -eq 1],[
Expand Down
1 change: 1 addition & 0 deletions shell/print_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ match List.tl (Array.to_list Sys.argv) with
| ["lib"] -> print_endline Config.ext_lib
| ["arch"] -> print_endline Config.architecture
| ["ccomp_type"] -> print_endline Config.ccomp_type
| ["system"] -> print_endline Config.system
| ["os_type"] -> print_endline Sys.os_type
| _ -> prerr_endline "print_config.ml: wrong usage"; exit 2
7 changes: 7 additions & 0 deletions src/client/Opam.Runtime.amd64.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Opam.Runtime.amd64" version="1.0.0.0" processorArchitecture="amd64"/>
<file name="libstdc++-6.dll"/>
<file name="libgcc_s_seh-1.dll"/>
<file name="libwinpthread-1.dll"/>
</assembly>
7 changes: 7 additions & 0 deletions src/client/Opam.Runtime.x86.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Opam.Runtime.x86" version="1.0.0.0" processorArchitecture="x86"/>
<file name="libstdc++-6.dll"/>
<file name="libgcc_s_sjlj-1.dll"/>
<file name="libwinpthread-1.dll"/>
</assembly>
23 changes: 23 additions & 0 deletions src/client/default-manifest.xmlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- git://sourceware.org/git/cygwin-apps/windows-default-manifest.git
Tag release-6_4 transcribed from default-manifest.rc -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates application support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--The ID below indicates application support for Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--The ID below indicates application support for Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
14 changes: 12 additions & 2 deletions src/client/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
((name opam_client)
(public_name opam-client)
(synopsis "OCaml Package Manager client and CLI library")
(modules (:standard \ opamMain get-git-version))
(modules (:standard \ opamMain opamManifest get-git-version))
(libraries (opam-state opam-solver re cmdliner))
(flags (:standard
(:include ../ocaml-flags-standard.sexp)
Expand All @@ -15,13 +15,23 @@
((name opamMain)
(public_name opam)
(package opam)
(modules opamMain)
(modules (opamMain opamManifest))
(flags (:standard
(:include ../ocaml-flags-standard.sexp)
(:include ../ocaml-context-flags.sexp)
(:include linking.sexp)))
(link_flags (:include manifest.sexp))
(libraries (opam-client))))

(rule
((targets (manifest.sexp))
(deps (../../shell/subst_var.ml ../../config.status manifest.sexp.in))
(action (with-stdout-to ${@} (run ocaml ../../shell/subst_var.ml CONF_MANIFEST_O "" manifest.sexp.in)))))

(include opamManifest.inc)

(include manifest.inc)

(rule
((targets (git-sha))
(deps ((universe)))
Expand Down
26 changes: 26 additions & 0 deletions src/client/manifest.inc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(rule
((targets (opam-manifest.o))
(deps (opam.rc))
(action (run @TOOL_ARCH@-w64-mingw32-windres ${^} ${@}))))

(rule
(with-stdout-to opam.exe.manifest
(progn (echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n")
(echo "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n")
(cat opam-@[email protected])
(cat default-manifest.xmlf)
(echo "</assembly>"))))

(rule
((targets (opam.rc))
(deps (opam.exe.manifest))
(action (with-stdout-to opam.rc (echo "#include <winuser.h>\nCREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST opam.exe.manifest")))))

(install
((section bin)
(files ((Opam.Runtime.@[email protected] as Opam.Runtime.@MANIFEST_ARCH@\Opam.Runtime.@[email protected])
(libstdc++-6.dll as Opam.Runtime.@MANIFEST_ARCH@\libstdc++-6.dll)
(libwinpthread-1.dll as Opam.Runtime.@MANIFEST_ARCH@\libwinpthread-1.dll)
(@[email protected] as Opam.Runtime.@MANIFEST_ARCH@\@[email protected])))
(package opam)))

1 change: 1 addition & 0 deletions src/client/manifest.sexp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(@CONF_MANIFEST_O@)
7 changes: 7 additions & 0 deletions src/client/opam-mingw.xmlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<assemblyIdentity type="win32" name="opam" version="1.0.0.0" processorArchitecture="x86"/>
<description>OCaml Package Manager</description>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Opam.Runtime.x86" version="1.0.0.0" language="*" processorArchitecture="x86"/>
</dependentAssembly>
</dependency>
7 changes: 7 additions & 0 deletions src/client/opam-mingw64.xmlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<assemblyIdentity type="win32" name="opam" version="1.0.0.0" processorArchitecture="amd64"/>
<description>OCaml Package Manager</description>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Opam.Runtime.amd64" version="1.0.0.0" language="*" processorArchitecture="amd64"/>
</dependentAssembly>
</dependency>
Loading

0 comments on commit 4ac97e7

Please sign in to comment.