Skip to content

Commit

Permalink
Use bootstrap ocamlc.opt
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Jan 21, 2023
1 parent 269f7d6 commit f7d8d59
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
13 changes: 12 additions & 1 deletion dkml-base-compiler.opam
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ build: [
] { !dkml-option-debuginfo:installed & !dkml-option-minsize:installed }
# tar through pipe is essentially an rsync (without requiring rsync)
["sh" "-eufc" "tar cCf src/ - . | tar xCf dkmldir/vendor/dkml-compiler/src/ -"]

# <dkmldir>/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe
# to speed up compile
["install" "-d" "dkmldir/vendor/dkml-compiler/bin"]
["install" "dl/windows_x86-ocamlc.opt.exe" "dkmldir/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"] { os = "win32" & (arch = "x86_32" | ocaml-option-32bit:installed) }
["install" "dl/windows_x86_64-ocamlc.opt.exe" "dkmldir/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"] { os = "win32" & (arch = "x86_64" & !ocaml-option-32bit:installed) }
["install" "dl/linux_x86-ocamlc.opt" "dkmldir/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"] { os = "linux" & (arch = "x86_32" | ocaml-option-32bit:installed) }
["install" "dl/linux_x86_64-ocamlc.opt" "dkmldir/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"] { os = "linux" & (arch = "x86_64" & !ocaml-option-32bit:installed) }
["install" "dl/darwin_x86_64-ocamlc.opt" "dkmldir/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"] { os = "macos" & arch = "x86_64" }
["install" "dl/darwin_arm64-ocamlc.opt" "dkmldir/vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"] { os = "macos" & arch = "arm64" }
]
install: [
# Run r-c-ocaml-1-setup.sh
Expand All @@ -92,6 +102,7 @@ install: [
"-f" "src-ocaml"
"-g" "%{_:share}%/mlcross"
"-v" "dl/ocaml"
"-c" "vendor/dkml-compiler/bin/bootstrap-ocamlc.opt.exe"
"-z"
# Windows flexlink flags that affect the built ocaml.exe, ocamlc.opt.exe, etc.
# It is nice with the toplevel ocaml.exe to be able to debug it when the toplevel
Expand All @@ -100,7 +111,7 @@ install: [
" -link /DEBUG:FULL" { os = "win32" & dkml-option-debuginfo:installed }
# Host architectures
"-ewindows_x86" { os = "win32" & (arch = "x86_32" | ocaml-option-32bit:installed) }
"-ewindows_x86_64" { os = "win32" & (arch = "x86_64" & !ocaml-option-32bit:installed) }
"-ewindows_x86_64" { os = "win32" & (arch = "x86_64" & !ocaml-option-32bit:installed) }
"-elinux_x86" { os = "linux" & (arch = "x86_32" | ocaml-option-32bit:installed) }
"-elinux_x86_64" { os = "linux" & (arch = "x86_64" & !ocaml-option-32bit:installed) }
"-edarwin_x86_64" { os = "macos" & arch = "x86_64" }
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ while getopts ":hp:s:" opt; do
done
shift $((OPTIND -1))

if [ -n "$PREFIX" ]; then usage; exit 2; fi
if [ -n "$SCRIPT" ]; then usage; exit 2; fi
if [ -z "$PREFIX" ]; then usage; exit 2; fi
if [ -z "$SCRIPT" ]; then usage; exit 2; fi

# Run script
cd "$PREFIX"
Expand Down
23 changes: 20 additions & 3 deletions src/r-c-ocaml-1-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ usage() {
printf "%s\n" " -v COMMIT_OR_DIR: Git commit or tag or directory for https://github.com/ocaml/ocaml. Strongly prefer a commit id"
printf "%s\n" " instead of a git tag for much stronger reproducibility guarantees"
printf "%s\n" " -u COMMIT: (Deprecated). Git commit or tag for https://github.com/ocaml/ocaml for the host ABI. Defaults to -v COMMIT"
printf "%s\n" " -c OCAMLC_OPT_EXE: Optional relative path from [-d DIR] to a possibly older 'ocamlc.opt'. It speeds up compilation"
printf "%s\n" " of the new OCaml compiler. If the executable does not exist it is not an error; it is silently dropped"
printf "%s\n" " -a TARGETABIS: Optional. A named list of self-contained Posix shell script that can be sourced to set the"
printf "%s\n" " compiler environment variables for the target ABI. If not specified then the OCaml environment"
printf "%s\n" " will be purely for the host ABI. All path should use the native host platform's path"
Expand Down Expand Up @@ -163,8 +165,8 @@ usage() {
printf "%s\n" " the environment variable DKML_HOST_ABI, or if not defined then an autodetection of the host architecture."
printf "%s\n" " -i OCAMLCARGS: Optional. Extra arguments passed to ocamlc like -g to save debugging"
printf "%s\n" " -j OCAMLOPTARGS: Optional. Extra arguments passed to ocamlopt like -g to save debugging"
printf "%s\n" " -k HOSTABISCRIPT: Optional. A self-contained Posix shell script that can be sourced to set the"
printf "%s\n" " compiler environment variables for the host ABI. See '-a TARGETABIS' for the shell script semantics."
printf "%s\n" " -k HOSTABISCRIPT: Optional. A self-contained Posix shell script relative to [-d DIR] that can be sourced to"
printf "%s\n" " set the compiler environment variables for the host ABI. See '-a TARGETABIS' for the shell script semantics."
printf "%s\n" " -l FLEXLINKFLAGS: Options added to flexlink while building ocaml, ocamlc, etc. native Windows executables"
printf "%s\n" " -m HOSTCONFIGUREARGS: Optional. Extra arguments passed to OCaml's ./configure for the host ABI. --with-flexdll"
printf "%s\n" " and --host will have already been set appropriately, but you can override the --host heuristic by adding it"
Expand Down Expand Up @@ -200,7 +202,8 @@ MSVS_PREFERENCE="$OPT_MSVS_PREFERENCE"
RUNTIMEONLY=OFF
TEMPLATEDIR=
HOSTABISCRIPT=
while getopts ":d:v:u:t:a:b:e:i:j:k:l:m:n:rf:p:g:o:xzh" opt; do
OCAMLC_OPT_EXE=
while getopts ":d:v:u:t:a:b:c:e:i:j:k:l:m:n:rf:p:g:o:xzh" opt; do
case ${opt} in
h )
usage
Expand Down Expand Up @@ -240,6 +243,7 @@ while getopts ":d:v:u:t:a:b:e:i:j:k:l:m:n:rf:p:g:o:xzh" opt; do
MSVS_PREFERENCE="$OPTARG"
SETUP_ARGS+=( -b "$OPTARG" )
;;
c) OCAMLC_OPT_EXE="$OPTARG" ;;
e )
DKMLHOSTABI="$OPTARG"
;;
Expand Down Expand Up @@ -412,6 +416,16 @@ else
OCAMLSRC_MIXED="$OCAMLSRC_UNIX"
fi

# Handle: -c OCAMLC_OPT_EXE
if [ -n "$OCAMLC_OPT_EXE" ]; then
if [ -e "$OCAMLC_OPT_EXE" ]; then
SETUP_ARGS+=( -c "$OCAMLC_OPT_EXE" )
BUILD_HOST_ARGS+=( -c "$OCAMLC_OPT_EXE" )
else
OCAMLC_OPT_EXE=
fi
fi

# Set DKMLSYS_CAT and other things
autodetect_system_binaries

Expand Down Expand Up @@ -790,6 +804,9 @@ install_reproducible_file vendor/dkml-compiler/src/r-c-ocaml-get_sak
if [ -n "$HOSTABISCRIPT" ]; then
install_reproducible_file "$HOSTABISCRIPT"
fi
if [ -n "$OCAMLC_OPT_EXE" ]; then
install_reproducible_file "$OCAMLC_OPT_EXE"
fi
for patchfile in "${ALL_PATCH_FILES[@]}"; do
install_reproducible_file "$patchfile"
done
Expand Down
23 changes: 22 additions & 1 deletion src/r-c-ocaml-2-build_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ usage() {
printf "%s\n" " -d DIR: DKML directory containing a .dkmlroot file"
printf "%s\n" " -t DIR: Target directory for the reproducible directory tree"
printf "%s\n" " -b PREF: Required and used only for the MSVC compiler. See r-c-ocaml-1-setup.sh"
printf "%s\n" " -c OCAMLC_OPT_EXE: If a possibly older 'ocamlc.opt' is specified, it speeds up compilation of the new OCaml compiler"
printf "%s\n" " -e DKMLHOSTABI: Uses the Diskuv OCaml compiler detector find a host ABI compiler"
printf "%s\n" " -f HOSTSRC_SUBDIR: Use HOSTSRC_SUBDIR subdirectory of -t DIR to place the source code of the host ABI"
printf "%s\n" " -p HOST_SUBDIR: Optional. Use HOST_SUBDIR subdirectory of -t DIR to place the host ABI"
Expand Down Expand Up @@ -72,9 +73,10 @@ RUNTIMEONLY=OFF
HOSTSRC_SUBDIR=
HOST_SUBDIR=
HOST_ONLY=OFF
OCAMLC_OPT_EXE=
FLEXLINKFLAGS=
export MSVS_PREFERENCE=
while getopts ":s:d:t:b:e:m:i:j:k:l:rf:p:o:h" opt; do
while getopts ":s:d:t:b:c:e:m:i:j:k:l:rf:p:o:h" opt; do
case ${opt} in
h )
usage
Expand All @@ -99,6 +101,7 @@ while getopts ":s:d:t:b:e:m:i:j:k:l:rf:p:o:h" opt; do
e )
DKMLHOSTABI="$OPTARG"
;;
c ) OCAMLC_OPT_EXE="$OPTARG" ;;
f ) HOSTSRC_SUBDIR=$OPTARG ;;
p ) HOST_SUBDIR=$OPTARG ;;
m )
Expand Down Expand Up @@ -186,6 +189,16 @@ if [ -n "$HOSTABISCRIPT" ]; then
esac
fi

if [ -n "$OCAMLC_OPT_EXE" ]; then
case "$OCAMLC_OPT_EXE" in
/* | ?:*) # /a/b/c or C:\Windows
;;
*) # relative path; need absolute path since we will soon change dir to $OCAMLSRC_UNIX
OCAMLC_OPT_EXE="$DKMLDIR/$OCAMLC_OPT_EXE"
;;
esac
fi

cd "$OCAMLSRC_UNIX"

# Dump environment variables
Expand Down Expand Up @@ -217,6 +230,14 @@ else
fi
log_trace ocaml_configure "$OCAMLHOST_UNIX" "$DKMLHOSTABI" "$HOSTABISCRIPT" "$CONFIGUREARGS"

# Skip bootstrapping if ocamlc.opt is present
if [ -n "$OCAMLC_OPT_EXE" ]; then
case "$DKMLHOSTABI" in
windows_*) log_trace install "$OCAMLC_OPT_EXE" boot/ocamlc.opt.exe ;;
*) log_trace install "$OCAMLC_OPT_EXE" boot/ocamlc.opt
esac
fi

# Capture SAK_ variables for use in cross-compiler.
# We need $(1) and $(2) parameter placeholders to get passed as well, so
# we encode them.
Expand Down

0 comments on commit f7d8d59

Please sign in to comment.