diff --git a/.gitattributes b/.gitattributes index 0d7fefb049cf..882d913f2003 100644 --- a/.gitattributes +++ b/.gitattributes @@ -103,7 +103,11 @@ yacc/*.[ch] ocaml-typo=long-line,very-long-line,unused-prop *.precheck text eol=lf *.runner text eol=lf +clone-flexdll text eol=lf configure text eol=lf +configure-windows text eol=lf +esy-configure text eol=lf +esy-build text eol=lf config/auto-aux/hasgot text eol=lf config/auto-aux/hasgot2 text eol=lf config/auto-aux/runtest text eol=lf diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index dca1e0d28f7a..000000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "flexdll"] - path = flexdll - url = https://github.com/alainfrisch/flexdll.git diff --git a/clone-flexdll b/clone-flexdll new file mode 100755 index 000000000000..fbeb13c607ae --- /dev/null +++ b/clone-flexdll @@ -0,0 +1,16 @@ +#! /bin/sh + +# clone-flexdll +# +# Brings in flexdll, if necessary + +if [ -d "flexdll" ]; then + echo "[Flexdll] Already present, no need to clone." +else + echo "[Flexdll] Cloning..." + git clone https://github.com/esy-ocaml/flexdll.git + cd flexdll + git checkout f84baaeae463f96f9582883a9cfb7dd1096757ff + cd .. + echo "[Flexdll] Clone successful!" +fi diff --git a/config/Makefile.mingw64 b/config/Makefile.mingw64 index 0466e63c0b60..8403fef58af1 100644 --- a/config/Makefile.mingw64 +++ b/config/Makefile.mingw64 @@ -32,7 +32,7 @@ BINDIR=$(PREFIX)/bin BYTERUN=ocamlrun ### Where to install the standard library -LIBDIR=$(PREFIX)/lib +LIBDIR=$(PREFIX)/lib/ocaml ### Where to install the stub DLLs STUBLIBDIR=$(LIBDIR)/stublibs diff --git a/configure-windows b/configure-windows new file mode 100755 index 000000000000..ae6ca8ce6672 --- /dev/null +++ b/configure-windows @@ -0,0 +1,34 @@ +#! /bin/sh + +# configure-windows +# +# Creates a native Windows MingW build, based on: +# https://github.com/ocaml/ocaml/blob/trunk/README.win32.adoc + + +export prefix=C:/ocamlmgw64 +while : ; do + case "$1" in + "") break;; + -prefix|--prefix) + prefix=$2; shift;; + esac + shift +done + +echo "[configure-windows] Prefix path: $prefix" + +echo "[configure-windows] Copying architecture headers." +cp config/m-nt.h byterun/caml/m.h +cp config/s-nt.h byterun/caml/s.h + +# TODO: Differentiate based on architecture - use 'Makefile.mingw' for 32-bit environments +echo "[configure-windows] Bringing over mingw64 Makefile." +cp config/Makefile.mingw64 config/Makefile + +echo "[configure-windows] Replace prefix path with: $prefix." +sed -i "s#PREFIX=C:/ocamlmgw64#PREFIX=$prefix#g" config/Makefile + +echo "[configure-windows] Setting up flexdll" +./clone-flexdll +make flexdll diff --git a/esy-build b/esy-build new file mode 100755 index 000000000000..789edc99874e --- /dev/null +++ b/esy-build @@ -0,0 +1,24 @@ +#! /bin/bash + +# esy-build +# +# Wrapper to execute appropriate build strategy, based on platform + +set -u +set -e +set -o pipefail + +case "$(uname -s)" in + CYGWIN*|MINGW32*|MSYS*) + echo "[esy-build] Detected windows environment..." + make -j1 world.opt + make flexlink.opt + ;; + *) + echo "[esy-build] Detected OSX / Linux environment" + make -j4 world.opt + ;; +esac + +# Common build steps +make install diff --git a/esy-configure b/esy-configure new file mode 100755 index 000000000000..85a8d2da80c1 --- /dev/null +++ b/esy-configure @@ -0,0 +1,29 @@ +#! /bin/bash + +# esy-configure +# +# Wrapper to delegate to configuration to the +# appropriate `configure` strategy based on the active platform. +# +# Today, OCaml has separate build strategies: +# - Linux, OSX, Cygwin (gcc) - https://github.com/ocaml/ocaml/blob/trunk/INSTALL.adoc +# - Windows, Cygin (mingw) - https://github.com/ocaml/ocaml/blob/trunk/README.win32.adoc +# +# We want `esy` to work cross-platform, so this is a shim script that will delegate to the +# appropriate script depending on the platform. We assume that if the platform is `CYGWIN` +# that the `mingw` (native executable) strategy is desired. + +set -u +set -e +set -o pipefail + +case "$(uname -s)" in + CYGWIN*|MINGW32*|MSYS*) + echo "[esy-configure] Detected windows environment..." + ./configure-windows "$@" + ;; + *) + echo "[esy-configure] Detected OSX / Linux environment" + ./configure "$@" + ;; +esac diff --git a/flexdll b/flexdll deleted file mode 160000 index 7f565ef8647a..000000000000 --- a/flexdll +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7f565ef8647a16e6a2cd2b30c8e6a4894558eaaa diff --git a/package.json b/package.json index 719b5aa920b8..c6f8e1ad05c3 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,50 @@ "description": "BuckleScript's OCaml Compiler as an npm Package", "esy": { "build": [ - "./configure -no-cfi -prefix $cur__install", - "make -j world.opt" - ], - "install": [ - "make install" + "./esy-configure -no-cfi -prefix #{self.install}", + "./esy-build", + [ + "cp", + "-r", + "-f", + "#{self.root / 'utils'}", + "#{self.install / 'utils'}" + ], + [ + "cp", + "-r", + "-f", + "#{self.root / 'parsing'}", + "#{self.install / 'parsing'}" + ], + [ + "cp", + "-r", + "-f", + "#{self.root / 'typing'}", + "#{self.install / 'typing'}" + ], + [ + "cp", + "-r", + "-f", + "#{self.root / 'bytecomp'}", + "#{self.install / 'bytecomp'}" + ], + [ + "cp", + "-r", + "-f", + "#{self.root / 'driver'}", + "#{self.install / 'driver'}" + ], + [ + "cp", + "-r", + "-f", + "#{self.root / 'tools'}", + "#{self.install / 'tools'}" + ] ], "buildsInSource": true, "exportedEnv": {