diff --git a/.ci/dkml-compilers/pc/setup-dkml-windows_x86.ps1 b/.ci/dkml-compilers/pc/setup-dkml-windows_x86.ps1 new file mode 100644 index 00000000..15973621 --- /dev/null +++ b/.ci/dkml-compilers/pc/setup-dkml-windows_x86.ps1 @@ -0,0 +1,2782 @@ +# setup-dkml +# Short form: sd4 + +<# +.SYNOPSIS + +Setup Diskuv OCaml (DKML) compiler on a desktop PC. + +.DESCRIPTION + +Setup Diskuv OCaml (DKML) compiler on a desktop PC. + +.PARAMETER PC_PROJECT_DIR +Context variable for the project directory. Defaults to the current directory. + +.PARAMETER FDOPEN_OPAMEXE_BOOTSTRAP +Input variable. + +.PARAMETER CACHE_PREFIX +Input variable. + +.PARAMETER OCAML_COMPILER +Input variable. -DKML_COMPILER takes priority. If -DKML_COMPILER is not set and -OCAML_COMPILER is set, then the specified OCaml version tag of dkml-compiler (ex. 4.12.1) is used. + +.PARAMETER DKML_COMPILER +Input variable. Unspecified or blank is the latest from the default branch (main) of dkml-compiler. @repository@ is the latest from Opam. + +.PARAMETER SKIP_OPAM_MODIFICATIONS +Input variable. If true (the default is false) then the opam root and switches will not be created or modified. + +.PARAMETER SECONDARY_SWITCH +Input variable. If true then the secondary switch named 'two' is created. + +.PARAMETER PRIMARY_SWITCH_SKIP_INSTALL +Input variable. If true no dkml-base-compiler will be installed in the 'dkml' switch. + +.PARAMETER CONF_DKML_CROSS_TOOLCHAIN +Input variable. Unspecified or blank is the latest from the default branch (main) of conf-dkml-cross-toolchain. @repository@ is the latest from Opam. + +.PARAMETER DISKUV_OPAM_REPOSITORY +Input variable. Defaults to the value of -DEFAULT_DISKUV_OPAM_REPOSITORY_TAG (see below) + +.PARAMETER DKML_HOME +Input variables. If specified then DiskuvOCamlHome, DiskuvOCamlBinaryPaths and DiskuvOCamlDeploymentId will be set, in addition to the always-present DiskuvOCamlVarsVersion, DiskuvOCamlVersion +and DiskuvOCamlMSYS2Dir. + +# autogen from global_env_vars. +.PARAMETER DKML_VERSION +Environment variable. + +.PARAMETER DEFAULT_DISKUV_OPAM_REPOSITORY_TAG +Environment variable. + +.PARAMETER DEFAULT_DKML_COMPILER +Environment variable. + +.PARAMETER PIN_ASTRING +Environment variable. + +.PARAMETER PIN_BASE +Environment variable. + +.PARAMETER PIN_BASE64 +Environment variable. + +.PARAMETER PIN_BIGARRAY_COMPAT +Environment variable. + +.PARAMETER PIN_BOS +Environment variable. + +.PARAMETER PIN_CAMLP_STREAMS +Environment variable. + +.PARAMETER PIN_CHROME_TRACE +Environment variable. + +.PARAMETER PIN_CMDLINER +Environment variable. + +.PARAMETER PIN_CONF_DKML_SYS_OPAM +Environment variable. + +.PARAMETER PIN_CONF_PKG_CONFIG +Environment variable. + +.PARAMETER PIN_CONF_SQLITE3 +Environment variable. + +.PARAMETER PIN_CPPO +Environment variable. + +.PARAMETER PIN_CRUNCH +Environment variable. + +.PARAMETER PIN_CSEXP +Environment variable. + +.PARAMETER PIN_CSTRUCT +Environment variable. + +.PARAMETER PIN_CTYPES_FOREIGN +Environment variable. + +.PARAMETER PIN_CTYPES +Environment variable. + +.PARAMETER PIN_CUDF +Environment variable. + +.PARAMETER PIN_DIGESTIF +Environment variable. + +.PARAMETER PIN_DISKUVBOX +Environment variable. + +.PARAMETER PIN_DKML_APPS +Environment variable. + +.PARAMETER PIN_DKML_BASE_COMPILER +Environment variable. + +.PARAMETER PIN_DKML_BUILD_DESKTOP +Environment variable. + +.PARAMETER PIN_DKML_C_PROBE +Environment variable. + +.PARAMETER PIN_DKML_COMPILER_ENV +Environment variable. + +.PARAMETER PIN_DKML_COMPILER_SRC +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_COMMON_DESKTOP +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_COMMON_OPAM +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_COMMON_UNIXUTILS +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_OCAMLRUN +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_OPAM32 +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_OPAM64 +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_UNIXUTILS +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_WITHDKML +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_XX_CONSOLE +Environment variable. + +.PARAMETER PIN_DKML_EXE_LIB +Environment variable. + +.PARAMETER PIN_DKML_EXE +Environment variable. + +.PARAMETER PIN_DKML_INSTALL_INSTALLER +Environment variable. + +.PARAMETER PIN_DKML_INSTALL_RUNNER +Environment variable. + +.PARAMETER PIN_DKML_INSTALL +Environment variable. + +.PARAMETER PIN_DKML_INSTALLER_OCAML_COMMON +Environment variable. + +.PARAMETER PIN_DKML_INSTALLER_OCAML_OFFLINE +Environment variable. + +.PARAMETER PIN_DKML_PACKAGE_CONSOLE +Environment variable. + +.PARAMETER PIN_DKML_RUNTIME_COMMON_NATIVE +Environment variable. + +.PARAMETER PIN_DKML_RUNTIME_COMMON +Environment variable. + +.PARAMETER PIN_DKML_RUNTIME_DISTRIBUTION +Environment variable. + +.PARAMETER PIN_DKML_RUNTIMELIB +Environment variable. + +.PARAMETER PIN_DKML_RUNTIMESCRIPTS +Environment variable. + +.PARAMETER PIN_DKML_WORKFLOWS +Environment variable. + +.PARAMETER PIN_DUNE_ACTION_PLUGIN +Environment variable. + +.PARAMETER PIN_DUNE_BUILD_INFO +Environment variable. + +.PARAMETER PIN_DUNE_CONFIGURATOR +Environment variable. + +.PARAMETER PIN_DUNE_GLOB +Environment variable. + +.PARAMETER PIN_DUNE_PRIVATE_LIBS +Environment variable. + +.PARAMETER PIN_DUNE_RPC_LWT +Environment variable. + +.PARAMETER PIN_DUNE_RPC +Environment variable. + +.PARAMETER PIN_DUNE_SITE +Environment variable. + +.PARAMETER PIN_DUNE +Environment variable. + +.PARAMETER PIN_DYN +Environment variable. + +.PARAMETER PIN_EITHER +Environment variable. + +.PARAMETER PIN_EQAF +Environment variable. + +.PARAMETER PIN_EXTLIB +Environment variable. + +.PARAMETER PIN_EZJSONM +Environment variable. + +.PARAMETER PIN_FEATHER +Environment variable. + +.PARAMETER PIN_FIBER +Environment variable. + +.PARAMETER PIN_FIX +Environment variable. + +.PARAMETER PIN_FMT +Environment variable. + +.PARAMETER PIN_FPATH +Environment variable. + +.PARAMETER PIN_GRAPHICS +Environment variable. + +.PARAMETER PIN_HEX +Environment variable. + +.PARAMETER PIN_INTEGERS +Environment variable. + +.PARAMETER PIN_JANE_STREET_HEADERS +Environment variable. + +.PARAMETER PIN_JINGOO +Environment variable. + +.PARAMETER PIN_JSONM +Environment variable. + +.PARAMETER PIN_JSONRPC +Environment variable. + +.PARAMETER PIN_JST_CONFIG +Environment variable. + +.PARAMETER PIN_LAMBDA_TERM +Environment variable. + +.PARAMETER PIN_LOGS +Environment variable. + +.PARAMETER PIN_LSP +Environment variable. + +.PARAMETER PIN_LWT +Environment variable. + +.PARAMETER PIN_LWT_REACT +Environment variable. + +.PARAMETER PIN_MCCS +Environment variable. + +.PARAMETER PIN_MDX +Environment variable. + +.PARAMETER PIN_MENHIR +Environment variable. + +.PARAMETER PIN_MENHIRLIB +Environment variable. + +.PARAMETER PIN_MENHIRSDK +Environment variable. + +.PARAMETER PIN_MERLIN_LIB +Environment variable. + +.PARAMETER PIN_METAPP +Environment variable. + +.PARAMETER PIN_METAQUOT +Environment variable. + +.PARAMETER PIN_MEW +Environment variable. + +.PARAMETER PIN_MEW_VI +Environment variable. + +.PARAMETER PIN_NUM +Environment variable. + +.PARAMETER PIN_OCAML_COMPILER_LIBS +Environment variable. + +.PARAMETER PIN_OCAML_LSP_SERVER +Environment variable. + +.PARAMETER PIN_OCAML_VERSION +Environment variable. + +.PARAMETER PIN_OCAML +Environment variable. + +.PARAMETER PIN_OCAMLBUILD +Environment variable. + +.PARAMETER PIN_OCAMLC_LOC +Environment variable. + +.PARAMETER PIN_OCAMLFIND +Environment variable. + +.PARAMETER PIN_OCAMLFORMAT_LIB +Environment variable. + +.PARAMETER PIN_OCAMLFORMAT_RPC_LIB +Environment variable. + +.PARAMETER PIN_OCAMLFORMAT +Environment variable. + +.PARAMETER PIN_OCP_INDENT +Environment variable. + +.PARAMETER PIN_OCPLIB_ENDIAN +Environment variable. + +.PARAMETER PIN_ODOC_PARSER +Environment variable. + +.PARAMETER PIN_ODOC +Environment variable. + +.PARAMETER PIN_ORDERING +Environment variable. + +.PARAMETER PIN_PARSEXP +Environment variable. + +.PARAMETER PIN_PP +Environment variable. + +.PARAMETER PIN_PPX_ASSERT +Environment variable. + +.PARAMETER PIN_PPX_BASE +Environment variable. + +.PARAMETER PIN_PPX_COLD +Environment variable. + +.PARAMETER PIN_PPX_COMPARE +Environment variable. + +.PARAMETER PIN_PPX_DERIVERS +Environment variable. + +.PARAMETER PIN_PPX_DERIVING +Environment variable. + +.PARAMETER PIN_PPX_ENUMERATE +Environment variable. + +.PARAMETER PIN_PPX_EXPECT +Environment variable. + +.PARAMETER PIN_PPX_GLOBALIZE +Environment variable. + +.PARAMETER PIN_PPX_HASH +Environment variable. + +.PARAMETER PIN_PPX_HERE +Environment variable. + +.PARAMETER PIN_PPX_IGNORE_INSTRUMENTATION +Environment variable. + +.PARAMETER PIN_PPX_INLINE_TEST +Environment variable. + +.PARAMETER PIN_PPX_OPTCOMP +Environment variable. + +.PARAMETER PIN_PPX_PIPEBANG +Environment variable. + +.PARAMETER PIN_PPX_SEXP_CONV +Environment variable. + +.PARAMETER PIN_PPX_YOJSON_CONV_LIB +Environment variable. + +.PARAMETER PIN_PPXLIB +Environment variable. + +.PARAMETER PIN_PTIME +Environment variable. + +.PARAMETER PIN_QRC +Environment variable. + +.PARAMETER PIN_RE +Environment variable. + +.PARAMETER PIN_REACT +Environment variable. + +.PARAMETER PIN_REFL +Environment variable. + +.PARAMETER PIN_RESULT +Environment variable. + +.PARAMETER PIN_RRESULT +Environment variable. + +.PARAMETER PIN_SEQ +Environment variable. + +.PARAMETER PIN_SEXPLIB +Environment variable. + +.PARAMETER PIN_SEXPLIB0 +Environment variable. + +.PARAMETER PIN_SHA +Environment variable. + +.PARAMETER PIN_SPAWN +Environment variable. + +.PARAMETER PIN_SQLITE3 +Environment variable. + +.PARAMETER PIN_STDCOMPAT +Environment variable. + +.PARAMETER PIN_STDIO +Environment variable. + +.PARAMETER PIN_STDLIB_SHIMS +Environment variable. + +.PARAMETER PIN_STDUNE +Environment variable. + +.PARAMETER PIN_TIME_NOW +Environment variable. + +.PARAMETER PIN_TOPKG +Environment variable. + +.PARAMETER PIN_TRAVERSE +Environment variable. + +.PARAMETER PIN_TRIE +Environment variable. + +.PARAMETER PIN_TSORT +Environment variable. + +.PARAMETER PIN_TYXML +Environment variable. + +.PARAMETER PIN_UCHAR +Environment variable. + +.PARAMETER PIN_UTOP +Environment variable. + +.PARAMETER PIN_UUCP +Environment variable. + +.PARAMETER PIN_UUIDM +Environment variable. + +.PARAMETER PIN_UUSEG +Environment variable. + +.PARAMETER PIN_UUTF +Environment variable. + +.PARAMETER PIN_WITH_DKML +Environment variable. + +.PARAMETER PIN_XDG +Environment variable. + +.PARAMETER PIN_YOJSON +Environment variable. + +.PARAMETER PIN_ZED +Environment variable. + +#> +[CmdletBinding()] +param ( + # Context variables + [Parameter(HelpMessage='Defaults to the current directory')] + [string] + $PC_PROJECT_DIR = $PWD, + + # Input variables + [string] + $FDOPEN_OPAMEXE_BOOTSTRAP = "false", + [string] + $CACHE_PREFIX = "v1", + [string] + $OCAML_COMPILER = "", + [string] + $DKML_COMPILER = "", + [string] + $SKIP_OPAM_MODIFICATIONS = "false", + [string] + $SECONDARY_SWITCH = "false", + [string] + $PRIMARY_SWITCH_SKIP_INSTALL = "false", + [string] + $CONF_DKML_CROSS_TOOLCHAIN = "@repository@", + [string] + $DISKUV_OPAM_REPOSITORY = "", + [string] + $DKML_HOME = "" + + # Conflicts with automatic variable $Verbose + # [Parameter()] + # [string] + # $VERBOSE = "false" + + # Environment variables (can be overridden on command line) + # autogen from global_env_vars. + ,[Parameter()] [string] $DKML_VERSION = "2.0.3" + ,[Parameter()] [string] $DEFAULT_DISKUV_OPAM_REPOSITORY_TAG = "2.0.3" + ,[Parameter()] [string] $DEFAULT_DKML_COMPILER = "2.0.3" + ,[Parameter()] [string] $PIN_ASTRING = "0.8.5" + ,[Parameter()] [string] $PIN_BASE = "v0.16.1" + ,[Parameter()] [string] $PIN_BASE64 = "3.5.1" + ,[Parameter()] [string] $PIN_BIGARRAY_COMPAT = "1.1.0" + ,[Parameter()] [string] $PIN_BOS = "0.2.1" + ,[Parameter()] [string] $PIN_CAMLP_STREAMS = "5.0.1" + ,[Parameter()] [string] $PIN_CHROME_TRACE = "3.10.0" + ,[Parameter()] [string] $PIN_CMDLINER = "1.2.0" + ,[Parameter()] [string] $PIN_CONF_DKML_SYS_OPAM = "1" + ,[Parameter()] [string] $PIN_CONF_PKG_CONFIG = "2+cpkgs" + ,[Parameter()] [string] $PIN_CONF_SQLITE3 = "3.1+cpkgs" + ,[Parameter()] [string] $PIN_CPPO = "1.6.9" + ,[Parameter()] [string] $PIN_CRUNCH = "3.3.1" + ,[Parameter()] [string] $PIN_CSEXP = "1.5.2" + ,[Parameter()] [string] $PIN_CSTRUCT = "6.2.0" + ,[Parameter()] [string] $PIN_CTYPES_FOREIGN = "0.19.2-windowssupport-r7" + ,[Parameter()] [string] $PIN_CTYPES = "0.19.2-windowssupport-r7" + ,[Parameter()] [string] $PIN_CUDF = "0.10" + ,[Parameter()] [string] $PIN_DIGESTIF = "1.1.4" + ,[Parameter()] [string] $PIN_DISKUVBOX = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_APPS = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_BASE_COMPILER = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_BUILD_DESKTOP = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_C_PROBE = "3.0.0" + ,[Parameter()] [string] $PIN_DKML_COMPILER_ENV = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPILER_SRC = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_COMMON_DESKTOP = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_COMMON_OPAM = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_COMMON_UNIXUTILS = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_OCAMLRUN = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_OPAM32 = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_OPAM64 = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_UNIXUTILS = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_WITHDKML = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_XX_CONSOLE = "0.1.1" + ,[Parameter()] [string] $PIN_DKML_EXE_LIB = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_EXE = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_INSTALL_INSTALLER = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_INSTALL_RUNNER = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_INSTALL = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_INSTALLER_OCAML_COMMON = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_INSTALLER_OCAML_OFFLINE = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_PACKAGE_CONSOLE = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_RUNTIME_COMMON_NATIVE = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIME_COMMON = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIME_DISTRIBUTION = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIMELIB = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIMESCRIPTS = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_WORKFLOWS = "2.0.3" + ,[Parameter()] [string] $PIN_DUNE_ACTION_PLUGIN = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_BUILD_INFO = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_CONFIGURATOR = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_GLOB = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_PRIVATE_LIBS = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_RPC_LWT = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_RPC = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_SITE = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE = "3.8.3" + ,[Parameter()] [string] $PIN_DYN = "3.8.3" + ,[Parameter()] [string] $PIN_EITHER = "1.0.0" + ,[Parameter()] [string] $PIN_EQAF = "0.9" + ,[Parameter()] [string] $PIN_EXTLIB = "1.7.9" + ,[Parameter()] [string] $PIN_EZJSONM = "1.3.0" + ,[Parameter()] [string] $PIN_FEATHER = "0.3.0" + ,[Parameter()] [string] $PIN_FIBER = "3.7.0" + ,[Parameter()] [string] $PIN_FIX = "20230505" + ,[Parameter()] [string] $PIN_FMT = "0.9.0" + ,[Parameter()] [string] $PIN_FPATH = "0.7.3" + ,[Parameter()] [string] $PIN_GRAPHICS = "5.1.2" + ,[Parameter()] [string] $PIN_HEX = "1.5.0" + ,[Parameter()] [string] $PIN_INTEGERS = "0.7.0" + ,[Parameter()] [string] $PIN_JANE_STREET_HEADERS = "v0.16.0" + ,[Parameter()] [string] $PIN_JINGOO = "1.4.4" + ,[Parameter()] [string] $PIN_JSONM = "1.0.2" + ,[Parameter()] [string] $PIN_JSONRPC = "1.16.2" + ,[Parameter()] [string] $PIN_JST_CONFIG = "v0.16.0" + ,[Parameter()] [string] $PIN_LAMBDA_TERM = "3.3.1" + ,[Parameter()] [string] $PIN_LOGS = "0.7.0" + ,[Parameter()] [string] $PIN_LSP = "1.16.2" + ,[Parameter()] [string] $PIN_LWT = "5.6.1" + ,[Parameter()] [string] $PIN_LWT_REACT = "1.2.0" + ,[Parameter()] [string] $PIN_MCCS = "1.1+13" + ,[Parameter()] [string] $PIN_MDX = "2.3.0" + ,[Parameter()] [string] $PIN_MENHIR = "20230608" + ,[Parameter()] [string] $PIN_MENHIRLIB = "20230608" + ,[Parameter()] [string] $PIN_MENHIRSDK = "20230608" + ,[Parameter()] [string] $PIN_MERLIN_LIB = "4.9-414" + ,[Parameter()] [string] $PIN_METAPP = "0.4.4+win" + ,[Parameter()] [string] $PIN_METAQUOT = "0.5.2" + ,[Parameter()] [string] $PIN_MEW = "0.1.0" + ,[Parameter()] [string] $PIN_MEW_VI = "0.5.0" + ,[Parameter()] [string] $PIN_NUM = "1.4" + ,[Parameter()] [string] $PIN_OCAML_COMPILER_LIBS = "v0.12.4" + ,[Parameter()] [string] $PIN_OCAML_LSP_SERVER = "1.16.2" + ,[Parameter()] [string] $PIN_OCAML_VERSION = "3.6.1" + ,[Parameter()] [string] $PIN_OCAML = "4.14.0" + ,[Parameter()] [string] $PIN_OCAMLBUILD = "0.14.2+win+unix" + ,[Parameter()] [string] $PIN_OCAMLC_LOC = "3.8.3" + ,[Parameter()] [string] $PIN_OCAMLFIND = "1.9.5" + ,[Parameter()] [string] $PIN_OCAMLFORMAT_LIB = "0.25.1" + ,[Parameter()] [string] $PIN_OCAMLFORMAT_RPC_LIB = "0.25.1" + ,[Parameter()] [string] $PIN_OCAMLFORMAT = "0.25.1" + ,[Parameter()] [string] $PIN_OCP_INDENT = "1.8.2-windowssupport" + ,[Parameter()] [string] $PIN_OCPLIB_ENDIAN = "1.2" + ,[Parameter()] [string] $PIN_ODOC_PARSER = "2.0.0" + ,[Parameter()] [string] $PIN_ODOC = "2.2.0" + ,[Parameter()] [string] $PIN_ORDERING = "3.8.3" + ,[Parameter()] [string] $PIN_PARSEXP = "v0.16.0" + ,[Parameter()] [string] $PIN_PP = "1.1.2" + ,[Parameter()] [string] $PIN_PPX_ASSERT = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_BASE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_COLD = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_COMPARE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_DERIVERS = "1.2.1" + ,[Parameter()] [string] $PIN_PPX_DERIVING = "5.2.1" + ,[Parameter()] [string] $PIN_PPX_ENUMERATE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_EXPECT = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_GLOBALIZE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_HASH = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_HERE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_IGNORE_INSTRUMENTATION = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_INLINE_TEST = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_OPTCOMP = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_PIPEBANG = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_SEXP_CONV = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_YOJSON_CONV_LIB = "v0.16.0" + ,[Parameter()] [string] $PIN_PPXLIB = "0.30.0" + ,[Parameter()] [string] $PIN_PTIME = "1.1.0" + ,[Parameter()] [string] $PIN_QRC = "0.1.1~dune" + ,[Parameter()] [string] $PIN_RE = "1.11.0" + ,[Parameter()] [string] $PIN_REACT = "1.2.2" + ,[Parameter()] [string] $PIN_REFL = "0.4.1" + ,[Parameter()] [string] $PIN_RESULT = "1.5" + ,[Parameter()] [string] $PIN_RRESULT = "0.7.0" + ,[Parameter()] [string] $PIN_SEQ = "base" + ,[Parameter()] [string] $PIN_SEXPLIB = "v0.16.0" + ,[Parameter()] [string] $PIN_SEXPLIB0 = "v0.16.0" + ,[Parameter()] [string] $PIN_SHA = "1.15.4" + ,[Parameter()] [string] $PIN_SPAWN = "v0.15.1" + ,[Parameter()] [string] $PIN_SQLITE3 = "5.1.0+msvc" + ,[Parameter()] [string] $PIN_STDCOMPAT = "19+optautoconf" + ,[Parameter()] [string] $PIN_STDIO = "v0.16.0" + ,[Parameter()] [string] $PIN_STDLIB_SHIMS = "0.3.0" + ,[Parameter()] [string] $PIN_STDUNE = "3.8.3" + ,[Parameter()] [string] $PIN_TIME_NOW = "v0.16.0" + ,[Parameter()] [string] $PIN_TOPKG = "1.0.7" + ,[Parameter()] [string] $PIN_TRAVERSE = "0.3.0" + ,[Parameter()] [string] $PIN_TRIE = "1.0.0" + ,[Parameter()] [string] $PIN_TSORT = "2.1.0" + ,[Parameter()] [string] $PIN_TYXML = "4.5.0" + ,[Parameter()] [string] $PIN_UCHAR = "0.0.2" + ,[Parameter()] [string] $PIN_UTOP = "2.13.1" + ,[Parameter()] [string] $PIN_UUCP = "15.0.0" + ,[Parameter()] [string] $PIN_UUIDM = "0.9.8" + ,[Parameter()] [string] $PIN_UUSEG = "15.0.0" + ,[Parameter()] [string] $PIN_UUTF = "1.0.3" + ,[Parameter()] [string] $PIN_WITH_DKML = "2.0.3" + ,[Parameter()] [string] $PIN_XDG = "3.9.0" + ,[Parameter()] [string] $PIN_YOJSON = "2.1.0" + ,[Parameter()] [string] $PIN_ZED = "3.2.2" +) + +$ErrorActionPreference = "Stop" + +# Reset environment so no conflicts with a parent Opam or OCaml system +if (Test-Path Env:OPAMROOT) { Remove-Item Env:OPAMROOT } +if (Test-Path Env:OPAMSWITCH) { Remove-Item Env:OPAMSWITCH } +if (Test-Path Env:OPAM_SWITCH_PREFIX) { Remove-Item Env:OPAM_SWITCH_PREFIX } +if (Test-Path Env:CAML_LD_LIBRARY_PATH) { Remove-Item Env:CAML_LD_LIBRARY_PATH } +if (Test-Path Env:OCAMLLIB) { Remove-Item Env:OCAMLLIB } +if (Test-Path Env:OCAML_TOPLEVEL_PATH) { Remove-Item Env:OCAML_TOPLEVEL_PATH } + +# Pushdown context variables +$env:PC_CI = 'true' +$env:PC_PROJECT_DIR = $PC_PROJECT_DIR + +# Pushdown input variables +$env:FDOPEN_OPAMEXE_BOOTSTRAP = $FDOPEN_OPAMEXE_BOOTSTRAP +$env:CACHE_PREFIX = $CACHE_PREFIX +$env:OCAML_COMPILER = $OCAML_COMPILER +$env:DKML_COMPILER = $DKML_COMPILER +$env:SKIP_OPAM_MODIFICATIONS = $SKIP_OPAM_MODIFICATIONS +$env:SECONDARY_SWITCH = $SECONDARY_SWITCH +$env:PRIMARY_SWITCH_SKIP_INSTALL = $PRIMARY_SWITCH_SKIP_INSTALL +$env:CONF_DKML_CROSS_TOOLCHAIN = $CONF_DKML_CROSS_TOOLCHAIN +$env:DISKUV_OPAM_REPOSITORY = $DISKUV_OPAM_REPOSITORY +$env:DKML_HOME = $DKML_HOME + +# Set matrix variables +# autogen from pc_vars. only windows_x86 +$env:dkml_host_os = "windows" +$env:opam_root_cacheable = "${env:PC_PROJECT_DIR}/.ci/o" +$env:abi_pattern = "win32-windows_x86" +$env:msys2_system = "MINGW32" +$env:msys2_packages = "mingw-w64-i686-pkg-config" +$env:exe_ext = ".exe" +$env:bootstrap_opam_version = "2.2.0-alpha-20221228" +$env:opam_abi = "windows_x86" +$env:dkml_host_abi = "windows_x86" +$env:opam_root = "${env:PC_PROJECT_DIR}/.ci/o" +$env:vsstudio_hostarch = "x64" +$env:vsstudio_arch = "x86" +$env:ocaml_options = "ocaml-option-32bit" + + +# Set environment variables +# autogen from global_env_vars. +$env:DKML_VERSION = $DKML_VERSION +$env:DEFAULT_DISKUV_OPAM_REPOSITORY_TAG = $DEFAULT_DISKUV_OPAM_REPOSITORY_TAG +$env:DEFAULT_DKML_COMPILER = $DEFAULT_DKML_COMPILER +$env:PIN_ASTRING = $PIN_ASTRING +$env:PIN_BASE = $PIN_BASE +$env:PIN_BASE64 = $PIN_BASE64 +$env:PIN_BIGARRAY_COMPAT = $PIN_BIGARRAY_COMPAT +$env:PIN_BOS = $PIN_BOS +$env:PIN_CAMLP_STREAMS = $PIN_CAMLP_STREAMS +$env:PIN_CHROME_TRACE = $PIN_CHROME_TRACE +$env:PIN_CMDLINER = $PIN_CMDLINER +$env:PIN_CONF_DKML_SYS_OPAM = $PIN_CONF_DKML_SYS_OPAM +$env:PIN_CONF_PKG_CONFIG = $PIN_CONF_PKG_CONFIG +$env:PIN_CONF_SQLITE3 = $PIN_CONF_SQLITE3 +$env:PIN_CPPO = $PIN_CPPO +$env:PIN_CRUNCH = $PIN_CRUNCH +$env:PIN_CSEXP = $PIN_CSEXP +$env:PIN_CSTRUCT = $PIN_CSTRUCT +$env:PIN_CTYPES_FOREIGN = $PIN_CTYPES_FOREIGN +$env:PIN_CTYPES = $PIN_CTYPES +$env:PIN_CUDF = $PIN_CUDF +$env:PIN_DIGESTIF = $PIN_DIGESTIF +$env:PIN_DISKUVBOX = $PIN_DISKUVBOX +$env:PIN_DKML_APPS = $PIN_DKML_APPS +$env:PIN_DKML_BASE_COMPILER = $PIN_DKML_BASE_COMPILER +$env:PIN_DKML_BUILD_DESKTOP = $PIN_DKML_BUILD_DESKTOP +$env:PIN_DKML_C_PROBE = $PIN_DKML_C_PROBE +$env:PIN_DKML_COMPILER_ENV = $PIN_DKML_COMPILER_ENV +$env:PIN_DKML_COMPILER_SRC = $PIN_DKML_COMPILER_SRC +$env:PIN_DKML_COMPONENT_COMMON_DESKTOP = $PIN_DKML_COMPONENT_COMMON_DESKTOP +$env:PIN_DKML_COMPONENT_COMMON_OPAM = $PIN_DKML_COMPONENT_COMMON_OPAM +$env:PIN_DKML_COMPONENT_COMMON_UNIXUTILS = $PIN_DKML_COMPONENT_COMMON_UNIXUTILS +$env:PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON = $PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON +$env:PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK = $PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK +$env:PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE = $PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE +$env:PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL = $PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL +$env:PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM = $PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM +$env:PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS = $PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS +$env:PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL = $PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL +$env:PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR = $PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR +$env:PIN_DKML_COMPONENT_STAGING_OCAMLRUN = $PIN_DKML_COMPONENT_STAGING_OCAMLRUN +$env:PIN_DKML_COMPONENT_STAGING_OPAM32 = $PIN_DKML_COMPONENT_STAGING_OPAM32 +$env:PIN_DKML_COMPONENT_STAGING_OPAM64 = $PIN_DKML_COMPONENT_STAGING_OPAM64 +$env:PIN_DKML_COMPONENT_STAGING_UNIXUTILS = $PIN_DKML_COMPONENT_STAGING_UNIXUTILS +$env:PIN_DKML_COMPONENT_STAGING_WITHDKML = $PIN_DKML_COMPONENT_STAGING_WITHDKML +$env:PIN_DKML_COMPONENT_XX_CONSOLE = $PIN_DKML_COMPONENT_XX_CONSOLE +$env:PIN_DKML_EXE_LIB = $PIN_DKML_EXE_LIB +$env:PIN_DKML_EXE = $PIN_DKML_EXE +$env:PIN_DKML_INSTALL_INSTALLER = $PIN_DKML_INSTALL_INSTALLER +$env:PIN_DKML_INSTALL_RUNNER = $PIN_DKML_INSTALL_RUNNER +$env:PIN_DKML_INSTALL = $PIN_DKML_INSTALL +$env:PIN_DKML_INSTALLER_OCAML_COMMON = $PIN_DKML_INSTALLER_OCAML_COMMON +$env:PIN_DKML_INSTALLER_OCAML_OFFLINE = $PIN_DKML_INSTALLER_OCAML_OFFLINE +$env:PIN_DKML_PACKAGE_CONSOLE = $PIN_DKML_PACKAGE_CONSOLE +$env:PIN_DKML_RUNTIME_COMMON_NATIVE = $PIN_DKML_RUNTIME_COMMON_NATIVE +$env:PIN_DKML_RUNTIME_COMMON = $PIN_DKML_RUNTIME_COMMON +$env:PIN_DKML_RUNTIME_DISTRIBUTION = $PIN_DKML_RUNTIME_DISTRIBUTION +$env:PIN_DKML_RUNTIMELIB = $PIN_DKML_RUNTIMELIB +$env:PIN_DKML_RUNTIMESCRIPTS = $PIN_DKML_RUNTIMESCRIPTS +$env:PIN_DKML_WORKFLOWS = $PIN_DKML_WORKFLOWS +$env:PIN_DUNE_ACTION_PLUGIN = $PIN_DUNE_ACTION_PLUGIN +$env:PIN_DUNE_BUILD_INFO = $PIN_DUNE_BUILD_INFO +$env:PIN_DUNE_CONFIGURATOR = $PIN_DUNE_CONFIGURATOR +$env:PIN_DUNE_GLOB = $PIN_DUNE_GLOB +$env:PIN_DUNE_PRIVATE_LIBS = $PIN_DUNE_PRIVATE_LIBS +$env:PIN_DUNE_RPC_LWT = $PIN_DUNE_RPC_LWT +$env:PIN_DUNE_RPC = $PIN_DUNE_RPC +$env:PIN_DUNE_SITE = $PIN_DUNE_SITE +$env:PIN_DUNE = $PIN_DUNE +$env:PIN_DYN = $PIN_DYN +$env:PIN_EITHER = $PIN_EITHER +$env:PIN_EQAF = $PIN_EQAF +$env:PIN_EXTLIB = $PIN_EXTLIB +$env:PIN_EZJSONM = $PIN_EZJSONM +$env:PIN_FEATHER = $PIN_FEATHER +$env:PIN_FIBER = $PIN_FIBER +$env:PIN_FIX = $PIN_FIX +$env:PIN_FMT = $PIN_FMT +$env:PIN_FPATH = $PIN_FPATH +$env:PIN_GRAPHICS = $PIN_GRAPHICS +$env:PIN_HEX = $PIN_HEX +$env:PIN_INTEGERS = $PIN_INTEGERS +$env:PIN_JANE_STREET_HEADERS = $PIN_JANE_STREET_HEADERS +$env:PIN_JINGOO = $PIN_JINGOO +$env:PIN_JSONM = $PIN_JSONM +$env:PIN_JSONRPC = $PIN_JSONRPC +$env:PIN_JST_CONFIG = $PIN_JST_CONFIG +$env:PIN_LAMBDA_TERM = $PIN_LAMBDA_TERM +$env:PIN_LOGS = $PIN_LOGS +$env:PIN_LSP = $PIN_LSP +$env:PIN_LWT = $PIN_LWT +$env:PIN_LWT_REACT = $PIN_LWT_REACT +$env:PIN_MCCS = $PIN_MCCS +$env:PIN_MDX = $PIN_MDX +$env:PIN_MENHIR = $PIN_MENHIR +$env:PIN_MENHIRLIB = $PIN_MENHIRLIB +$env:PIN_MENHIRSDK = $PIN_MENHIRSDK +$env:PIN_MERLIN_LIB = $PIN_MERLIN_LIB +$env:PIN_METAPP = $PIN_METAPP +$env:PIN_METAQUOT = $PIN_METAQUOT +$env:PIN_MEW = $PIN_MEW +$env:PIN_MEW_VI = $PIN_MEW_VI +$env:PIN_NUM = $PIN_NUM +$env:PIN_OCAML_COMPILER_LIBS = $PIN_OCAML_COMPILER_LIBS +$env:PIN_OCAML_LSP_SERVER = $PIN_OCAML_LSP_SERVER +$env:PIN_OCAML_VERSION = $PIN_OCAML_VERSION +$env:PIN_OCAML = $PIN_OCAML +$env:PIN_OCAMLBUILD = $PIN_OCAMLBUILD +$env:PIN_OCAMLC_LOC = $PIN_OCAMLC_LOC +$env:PIN_OCAMLFIND = $PIN_OCAMLFIND +$env:PIN_OCAMLFORMAT_LIB = $PIN_OCAMLFORMAT_LIB +$env:PIN_OCAMLFORMAT_RPC_LIB = $PIN_OCAMLFORMAT_RPC_LIB +$env:PIN_OCAMLFORMAT = $PIN_OCAMLFORMAT +$env:PIN_OCP_INDENT = $PIN_OCP_INDENT +$env:PIN_OCPLIB_ENDIAN = $PIN_OCPLIB_ENDIAN +$env:PIN_ODOC_PARSER = $PIN_ODOC_PARSER +$env:PIN_ODOC = $PIN_ODOC +$env:PIN_ORDERING = $PIN_ORDERING +$env:PIN_PARSEXP = $PIN_PARSEXP +$env:PIN_PP = $PIN_PP +$env:PIN_PPX_ASSERT = $PIN_PPX_ASSERT +$env:PIN_PPX_BASE = $PIN_PPX_BASE +$env:PIN_PPX_COLD = $PIN_PPX_COLD +$env:PIN_PPX_COMPARE = $PIN_PPX_COMPARE +$env:PIN_PPX_DERIVERS = $PIN_PPX_DERIVERS +$env:PIN_PPX_DERIVING = $PIN_PPX_DERIVING +$env:PIN_PPX_ENUMERATE = $PIN_PPX_ENUMERATE +$env:PIN_PPX_EXPECT = $PIN_PPX_EXPECT +$env:PIN_PPX_GLOBALIZE = $PIN_PPX_GLOBALIZE +$env:PIN_PPX_HASH = $PIN_PPX_HASH +$env:PIN_PPX_HERE = $PIN_PPX_HERE +$env:PIN_PPX_IGNORE_INSTRUMENTATION = $PIN_PPX_IGNORE_INSTRUMENTATION +$env:PIN_PPX_INLINE_TEST = $PIN_PPX_INLINE_TEST +$env:PIN_PPX_OPTCOMP = $PIN_PPX_OPTCOMP +$env:PIN_PPX_PIPEBANG = $PIN_PPX_PIPEBANG +$env:PIN_PPX_SEXP_CONV = $PIN_PPX_SEXP_CONV +$env:PIN_PPX_YOJSON_CONV_LIB = $PIN_PPX_YOJSON_CONV_LIB +$env:PIN_PPXLIB = $PIN_PPXLIB +$env:PIN_PTIME = $PIN_PTIME +$env:PIN_QRC = $PIN_QRC +$env:PIN_RE = $PIN_RE +$env:PIN_REACT = $PIN_REACT +$env:PIN_REFL = $PIN_REFL +$env:PIN_RESULT = $PIN_RESULT +$env:PIN_RRESULT = $PIN_RRESULT +$env:PIN_SEQ = $PIN_SEQ +$env:PIN_SEXPLIB = $PIN_SEXPLIB +$env:PIN_SEXPLIB0 = $PIN_SEXPLIB0 +$env:PIN_SHA = $PIN_SHA +$env:PIN_SPAWN = $PIN_SPAWN +$env:PIN_SQLITE3 = $PIN_SQLITE3 +$env:PIN_STDCOMPAT = $PIN_STDCOMPAT +$env:PIN_STDIO = $PIN_STDIO +$env:PIN_STDLIB_SHIMS = $PIN_STDLIB_SHIMS +$env:PIN_STDUNE = $PIN_STDUNE +$env:PIN_TIME_NOW = $PIN_TIME_NOW +$env:PIN_TOPKG = $PIN_TOPKG +$env:PIN_TRAVERSE = $PIN_TRAVERSE +$env:PIN_TRIE = $PIN_TRIE +$env:PIN_TSORT = $PIN_TSORT +$env:PIN_TYXML = $PIN_TYXML +$env:PIN_UCHAR = $PIN_UCHAR +$env:PIN_UTOP = $PIN_UTOP +$env:PIN_UUCP = $PIN_UUCP +$env:PIN_UUIDM = $PIN_UUIDM +$env:PIN_UUSEG = $PIN_UUSEG +$env:PIN_UUTF = $PIN_UUTF +$env:PIN_WITH_DKML = $PIN_WITH_DKML +$env:PIN_XDG = $PIN_XDG +$env:PIN_YOJSON = $PIN_YOJSON +$env:PIN_ZED = $PIN_ZED + +# https://patchwork.kernel.org/project/qemu-devel/patch/20211215073402.144286-17-thuth@redhat.com/ +$env:CHERE_INVOKING = "yes" # Preserve the current working directory +$env:MSYSTEM = $env:msys2_system # Start a 64 bit environment if CLANG64, etc. + +########################### before_script ############################### + +# Troubleshooting +If ( "${env:VERBOSE}" -eq "true" ) { Get-ChildItem 'env:' } + +# ----- +# MSYS2 +# ----- +# +# https://www.msys2.org/docs/ci/ +# https://patchwork.kernel.org/project/qemu-devel/patch/20211215073402.144286-17-thuth@redhat.com/ + +if ( Test-Path -Path msys64\usr\bin\pacman.exe ) { + Write-Host "Re-using MSYS2 from cache." +} +else { + Write-Host "Download the archive ..." + If ( !(Test-Path -Path msys64\var\cache ) ) { New-Item msys64\var\cache -ItemType Directory | Out-Null } + If ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) { Invoke-WebRequest "https://github.com/msys2/msys2-installer/releases/download/2022-09-04/msys2-base-x86_64-20220904.sfx.exe" -outfile "msys64\var\cache\msys2.exe" } + + Write-Host "Extract the archive ..." + msys64\var\cache\msys2.exe -y # Extract to msys64 + Remove-Item msys64\var\cache\msys2.exe # Delete the archive again + ((Get-Content -path msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path msys64\etc\post-install\07-pacman-key.post + msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf" + + Write-Host "Run for the first time ..." + msys64\usr\bin\bash -lc ' ' +} +Write-Host "Update MSYS2 ..." +msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update (in case any core packages are outdated) +msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update +if ("${env:CI}" -eq "true") { taskkill /F /FI "MODULES eq msys-2.0.dll" } # Only safe to kill MSYS2 in CI + +Write-Host "Install matrix, required and CI packages ..." +# Packages for GitLab CI: +# dos2unix (used to translate PowerShell written files below in this CI .yml into MSYS2 scripts) +msys64\usr\bin\bash -lc 'set -x; pacman -Sy --noconfirm --needed ${msys2_packages} wget make rsync diffutils patch unzip git tar xz dos2unix' + +Write-Host "Uninstall MSYS2 conflicting executables ..." +msys64\usr\bin\bash -lc 'rm -vf /usr/bin/link.exe' # link.exe interferes with MSVC's link.exe + +Write-Host "Installing VSSetup for the Get-VSSetupInstance function ..." +Install-Module VSSetup -Scope CurrentUser -Force + +Write-Host "Writing scripts ..." + +# POSIX and AWK scripts + +If ( !(Test-Path -Path.ci\sd4 ) ) { New-Item .ci\sd4 -ItemType Directory | Out-Null } + +$Content = @' +#!/bin/sh + +# ------------------------ Log Formatting ------------------------ + +TXT_SECTION="\e[94m" # bright blue +TXT_CLEAR="\e[0m" + +if [ "${GITLAB_CI:-}" = "true" ]; then + # https://docs.gitlab.com/ee/ci/jobs/#expand-and-collapse-job-log-sections + print_section_start() { + print_section_start_NAME=$1 + shift + printf "\e[0Ksection_start:%s:%s[collapsed=true]\r\e[0K" \ + "$(date +%s)" \ + "$print_section_start_NAME" + } + print_section_end() { + print_section_end_NAME=$1 + shift + printf "\e[0Ksection_end:%s:%s\r\e[0K\n" \ + "$(date +%s)" \ + "$print_section_end_NAME" + } +elif [ -n "${GITHUB_ENV:-}" ]; then + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines + print_section_start() { + print_section_start_NAME=$1 + shift + printf "::group::" + } + print_section_end() { + print_section_end_NAME=$1 + shift + printf "::endgroup::\n" + } +else + print_section_start() { + print_section_start_NAME=$1 + shift + } + print_section_end() { + print_section_end_NAME=$1 + shift + } +fi + +section_begin() { + # https://docs.gitlab.com/ee/ci/yaml/script.html#add-color-codes-to-script-output + section_NAME=$1 + shift + section_HEADER=$1 + shift + print_section_start "$section_NAME" + printf "${TXT_SECTION}%s${TXT_CLEAR}\n" "$section_HEADER" +} + +section_end() { + section_NAME=$1 + shift + print_section_end "$section_NAME" +} + +# ------------------- Other Functions ----------------- + +transfer_dir() { + transfer_dir_SRC=$1 + shift + transfer_dir_DST=$1 + shift + # Remove the destination directory completely, but make sure the parent of the + # destination directory exists so `mv` will work + install -d "$transfer_dir_DST" + rm -rf "$transfer_dir_DST" + # Move + mv "$transfer_dir_SRC" "$transfer_dir_DST" +} + +# Set TEMP variable which is used, among other things, for OCaml's +# [Filename.temp_dir_name] on Win32, and by with-dkml.exe on Windows +export_temp_for_windows() { + if [ -x /usr/bin/cygpath ]; then + if [ -n "${RUNNER_TEMP:-}" ]; then + # GitHub Actions + TEMP=$(cygpath -am "$RUNNER_TEMP") + else + # GitLab CI/CD or desktop + install -d .ci/tmp + TEMP=$(cygpath -am ".ci/tmp") + fi + export TEMP + fi +} + +# Fixup opam_root on Windows to be mixed case. +# On input the following variables must be present: +# - opam_root +# - opam_root_cacheable +# On output the input variables will be modified _and_ the +# following variables will be available: +# - original_opam_root +# - original_opam_root_cacheable +# - unix_opam_root +# - unix_opam_root_cacheable +fixup_opam_root() { + # shellcheck disable=SC2034 + original_opam_root=$opam_root + # shellcheck disable=SC2034 + original_opam_root_cacheable=$opam_root_cacheable + if [ -x /usr/bin/cygpath ]; then + opam_root=$(/usr/bin/cygpath -m "$opam_root") + opam_root_cacheable=$(/usr/bin/cygpath -m "$opam_root_cacheable") + unix_opam_root=$(/usr/bin/cygpath -u "$opam_root") + unix_opam_root_cacheable=$(/usr/bin/cygpath -u "$opam_root_cacheable") + else + # shellcheck disable=SC2034 + unix_opam_root=$opam_root + # shellcheck disable=SC2034 + unix_opam_root_cacheable=$opam_root_cacheable + fi +} +'@ +Set-Content -Path ".ci\sd4\common-values.sh" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/common-values.sh' + + +$Content = @' +#!/bin/sh + +# ================ +# checkout-code.sh +# ================ +# +# Checkouts all of the git source code. +# +# This should be done outside of +# dockcross (used by Linux) since a Docker-in-Docker container can have +# difficulties doing a git checkout (the Git credentials for any private +# repositories are likely not present). We don't care about any private +# repositories for DKML but any code that extends this (ex. DKSDK) may +# need to use private repositories. + +set -euf + +setup_WORKSPACE_VARNAME=$1 +shift +setup_WORKSPACE=$1 +shift + +if [ -x /usr/bin/cygpath ]; then + setup_WORKSPACE=$(/usr/bin/cygpath -au "$setup_WORKSPACE") +fi + +# ------------------------ Functions ------------------------ + +# shellcheck source=./common-values.sh +. .ci/sd4/common-values.sh + +# Disable automatic garbage collection +git_disable_gc() { + git_disable_gc_NAME=$1 + shift + git -C ".ci/sd4/g/$git_disable_gc_NAME" config --local gc.auto 0 +} + +# Mimic the behavior of GitHub's actions/checkout@v3 +# - the plus symbol in 'git fetch ... origin +REF:refs/tags/v0.0' overrides any existing REF +git_checkout() { + git_checkout_NAME=$1 + shift + git_checkout_URL=$1 + shift + git_checkout_REF=$1 + shift + + if [ -e ".ci/sd4/g/$git_checkout_NAME" ]; then + git_disable_gc "$git_checkout_NAME" + git -C ".ci/sd4/g/$git_checkout_NAME" remote set-url origin "$git_checkout_URL" + git -C ".ci/sd4/g/$git_checkout_NAME" fetch --no-tags --progress --no-recurse-submodules --depth=1 origin "+${git_checkout_REF}:refs/tags/v0.0" + else + install -d ".ci/sd4/g/$git_checkout_NAME" + git -C ".ci/sd4/g/$git_checkout_NAME" -c init.defaultBranch=main init + git_disable_gc "$git_checkout_NAME" + git -C ".ci/sd4/g/$git_checkout_NAME" remote add origin "$git_checkout_URL" + git -C ".ci/sd4/g/$git_checkout_NAME" fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin "+${git_checkout_REF}:refs/tags/v0.0" + fi + git -C ".ci/sd4/g/$git_checkout_NAME" -c advice.detachedHead=false checkout --progress --force refs/tags/v0.0 + git -C ".ci/sd4/g/$git_checkout_NAME" log -1 --format='%H' +} + +# --------------------------------------------------------------------- + +section_begin checkout-info "Summary: code checkout" + +# shellcheck disable=SC2154 +echo " +================ +checkout-code.sh +================ +. +--------- +Arguments +--------- +WORKSPACE_VARNAME=$setup_WORKSPACE_VARNAME +WORKSPACE=$setup_WORKSPACE +. +------ +Inputs +------ +VERBOSE=${VERBOSE:-} +. +------ +Matrix +------ +dkml_host_abi=$dkml_host_abi +. +" + +section_end checkout-info + +install -d .ci/sd4/g + +# dkml-runtime-distribution + +# For 'Diagnose Visual Studio environment variables (Windows)' we need dkml-runtime-distribution +# so that 'Import-Module Machine' and 'Get-VSSetupInstance' can be run. +# The version doesn't matter too much, as long as it has a functioning Get-VSSetupInstance +# that supports the Visual Studio versions of the latest GitLab CI and GitHub Actions machines. +# commit 4d6f1bfc3510c55ba4273cb240e43727854b5718 = WinSDK 19041 and VS 14.29 +case "$dkml_host_abi" in +windows_*) + section_begin checkout-dkml-runtime-distribution 'Checkout dkml-runtime-distribution' + git_checkout dkml-runtime-distribution https://github.com/diskuv/dkml-runtime-distribution.git "4d6f1bfc3510c55ba4273cb240e43727854b5718" + section_end checkout-dkml-runtime-distribution + ;; +esac + +'@ +Set-Content -Path ".ci\sd4\run-checkout-code.sh" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/run-checkout-code.sh' + + +$Content = @' +#!/bin/sh +set -euf + +# Constants +SHA512_DEVNULL='cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' + +setup_WORKSPACE_VARNAME=$1 +shift +setup_WORKSPACE=$1 +shift + +if [ -x /usr/bin/cygpath ]; then + setup_WORKSPACE=$(/usr/bin/cygpath -au "$setup_WORKSPACE") +fi + +# ------------------ Variables and functions ------------------------ + +# shellcheck source=./common-values.sh +. .ci/sd4/common-values.sh + +if [ "${VERBOSE:-}" = "true" ]; then + do_tar_rf() { + tar rvf "$@" + } +else + do_tar_rf() { + tar rf "$@" + } +fi + +# Make the standard input work as an OCaml string. +# This currently only escapes backslashes and double quotes. +escape_arg_as_ocaml_string() { + escape_arg_as_ocaml_string_ARG=$1 + shift + printf "%s" "$escape_arg_as_ocaml_string_ARG" | sed 's#\\#\\\\#g; s#"#\\"#g;' +} + +# Fixup opam_root on Windows to be mixed case. Set original_* and unix_* as well. +fixup_opam_root + +# Set TEMP variable for Windows +export_temp_for_windows + +# Load VS studio environment +if [ -e .ci/sd4/vsenv.sh ]; then + # shellcheck disable=SC1091 + . .ci/sd4/vsenv.sh +fi + +# ------------------------------------------------------------------- + +section_begin setup-info "Summary: setup-dkml" + +SKIP_OPAM_MODIFICATIONS=${SKIP_OPAM_MODIFICATIONS:-false} # default is false + +# shellcheck disable=SC2154 +echo " +============= +setup-dkml.sh +============= +. +--------- +Arguments +--------- +WORKSPACE_VARNAME=$setup_WORKSPACE_VARNAME +WORKSPACE=$setup_WORKSPACE +. +------ +Inputs +------ +FDOPEN_OPAMEXE_BOOTSTRAP=${FDOPEN_OPAMEXE_BOOTSTRAP:-} +DISKUV_OPAM_REPOSITORY=${DISKUV_OPAM_REPOSITORY:-} +DKML_COMPILER=${DKML_COMPILER:-} +OCAML_COMPILER=${OCAML_COMPILER:-} +CONF_DKML_CROSS_TOOLCHAIN=${CONF_DKML_CROSS_TOOLCHAIN:-} +SKIP_OPAM_MODIFICATIONS=${SKIP_OPAM_MODIFICATIONS:-} +SECONDARY_SWITCH=${SECONDARY_SWITCH:-} +PRIMARY_SWITCH_SKIP_INSTALL=${PRIMARY_SWITCH_SKIP_INSTALL:-} +MANYLINUX=${MANYLINUX:-} +DKML_HOME=${DKML_HOME:-} +VERBOSE=${VERBOSE:-} +. +------------------- +Generated Constants +------------------- +DKML_VERSION=$DKML_VERSION +DEFAULT_DISKUV_OPAM_REPOSITORY_TAG=$DEFAULT_DISKUV_OPAM_REPOSITORY_TAG +DEFAULT_DKML_COMPILER=$DEFAULT_DKML_COMPILER +. +------ +Matrix +------ +dkml_host_abi=$dkml_host_abi +bootstrap_opam_version=$bootstrap_opam_version +abi_pattern=$abi_pattern +opam_root=${opam_root} +opam_root_cacheable=${opam_root_cacheable} +original_opam_root=${original_opam_root} +original_opam_root_cacheable=${original_opam_root_cacheable} +unix_opam_root=${unix_opam_root} +unix_opam_root_cacheable=${unix_opam_root_cacheable} +dockcross_image=${dockcross_image:-} +dockcross_image_custom_prefix=${dockcross_image_custom_prefix:-} +dockcross_run_extra_args=${dockcross_run_extra_args:-} +docker_runner=${docker_runner:-} +in_docker=${in_docker:-} +ocaml_options=${ocaml_options:-} +. +---- +Pins +---- +" +set | grep ^PIN_ +echo ". +" +case "$dkml_host_abi" in +windows_*) + # shellcheck disable=SC2153 + echo " +------------- +Visual Studio +------------- +VS_DIR=$VS_DIR +VS_VCVARSVER=$VS_VCVARSVER +VS_WINSDKVER=$VS_WINSDKVER +VS_MSVSPREFERENCE=$VS_MSVSPREFERENCE +VS_CMAKEGENERATOR=$VS_CMAKEGENERATOR +. +" + ;; +esac +section_end setup-info + +do_bootstrap() { + # Bootstrap from historical release + runit_BOOTSTRAPPED=0 + + # Bootstrap opam from fdopen (Windows) + if [ "$runit_BOOTSTRAPPED" = 0 ] && [ "${FDOPEN_OPAMEXE_BOOTSTRAP:-}" = "true" ]; then + if [ -e .ci/sd4/opam64/bin/opam.exe ] && [ -e .ci/sd4/opam64/bin/opam-installer.exe ]; then + runit_BOOTSTRAPPED=1 + else + case "$dkml_host_abi" in + windows_*) + echo 'Bootstrap opam from fdopen (Windows) ...' + install -d .ci/sd4/bs/bin + wget -O "$setup_WORKSPACE"/.ci/sd4/opam64.tar.xz https://github.com/fdopen/opam-repository-mingw/releases/download/0.0.0.2/opam64.tar.xz + + # this stalls: tar xvCfJ "$setup_WORKSPACE"/.ci/sd4 "$setup_WORKSPACE"/.ci/sd4/opam64.tar.xz + xz -v -d "$setup_WORKSPACE"/.ci/sd4/opam64.tar.xz + tar xvCf .ci/sd4 .ci/sd4/opam64.tar + + rm -rf "$setup_WORKSPACE"/.ci/sd4/bs/bin/Opam.Runtime.amd64 + mv -v "$setup_WORKSPACE"/.ci/sd4/opam64/bin/Opam.Runtime.amd64/ "$setup_WORKSPACE"/.ci/sd4/bs/bin/ + mv -v "$setup_WORKSPACE"/.ci/sd4/opam64/bin/opam.exe "$setup_WORKSPACE"/.ci/sd4/bs/bin/ + mv -v "$setup_WORKSPACE"/.ci/sd4/opam64/bin/opam-installer.exe "$setup_WORKSPACE"/.ci/sd4/bs/bin/ + + # diagnostics + ldd "$setup_WORKSPACE"/.ci/sd4/bs/bin/opam.exe + ldd "$setup_WORKSPACE"/.ci/sd4/bs/bin/opam-installer.exe + + runit_BOOTSTRAPPED=1 + ;; + esac + fi + fi + + # Bootstrap from historical release + if [ "$runit_BOOTSTRAPPED" = 0 ] && [ "$bootstrap_opam_version" != "os" ]; then + install -d .ci/sd4/bs + cd .ci/sd4/bs + + if [ ! -e version ] || [ "$(cat version)" != "$bootstrap_opam_version" ]; then + echo 'Bootstrap opam from historical release (non-Windows; Windows non-fdopen) ...' + if command -v curl > /dev/null 2> /dev/null; then + curl -L -o opam.tar.gz "https://github.com/diskuv/dkml-component-opam/releases/download/v${bootstrap_opam_version}/dkml-component-staging-opam.tar.gz" + else + wget -O opam.tar.gz "https://github.com/diskuv/dkml-component-opam/releases/download/v${bootstrap_opam_version}/dkml-component-staging-opam.tar.gz" + fi + tar tvfz opam.tar.gz + tar xfz opam.tar.gz "./staging-files/${dkml_host_abi}/" + rm -rf bin/ + mv "staging-files/${dkml_host_abi}/bin" . + rm -rf "${abi_pattern}" + printf "%s" "${bootstrap_opam_version}" >version + fi + + rm -f opam.tar.gz + cd ../../.. + + runit_BOOTSTRAPPED=1 + fi + + # Bootstrap from package manager or GitHub ocaml/opam release + case "$runit_BOOTSTRAPPED,$bootstrap_opam_version,$dkml_host_abi" in + 0,os,darwin_*) + if ! command -v opam; then + echo 'Bootstrap opam from package manager (macOS) ...' + brew install gpatch + brew install opam + fi + runit_BOOTSTRAPPED=1 + ;; + 0,os,linux_x86) + if [ ! -x .ci/sd4/bs/bin/opam ]; then + echo 'Bootstrap opam from GitHub ocaml/opam release (Linux x86) ...' + install -d .ci/sd4/bs/bin + if command -v curl > /dev/null 2> /dev/null; then + curl -L -o .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-i686-linux + else + wget -O .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-i686-linux + fi + sha512_check=$(openssl sha512 2>&1 /dev/null | cut -f 2 -d ' ') + check="85a480d60e09a7d37fa0d0434ed97a3187434772ceb4e7e8faa5b06bc18423d004af3ad5849c7d35e72dca155103257fd6b1178872df8291583929eb8f884b6a" + test "$sha512" = "$check" + chmod +x .ci/sd4/bs/bin/opam.tmp + mv .ci/sd4/bs/bin/opam.tmp .ci/sd4/bs/bin/opam + else + echo "openssl 512 option unsupported." + exit 61 + fi + fi + runit_BOOTSTRAPPED=1 + ;; + 0,os,linux_x86_64) + if [ ! -x .ci/sd4/bs/bin/opam ]; then + echo 'Bootstrap opam from GitHub ocaml/opam release (Linux x86_64) ...' + install -d .ci/sd4/bs/bin + if command -v curl > /dev/null 2> /dev/null; then + curl -L -o .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-x86_64-linux + else + wget -O .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-x86_64-linux + fi + sha512_check=$(openssl sha512 2>&1 /dev/null | cut -f 2 -d ' ') + check="c0657ecbd4dc212587a4da70c5ff0402df95d148867be0e1eb1be8863a2851015f191437c3c99b7c2b153fcaa56cac99169c76ec94c5787750d7a59cd1fbb68b" + test "$sha512" = "$check" + chmod +x .ci/sd4/bs/bin/opam.tmp + mv .ci/sd4/bs/bin/opam.tmp .ci/sd4/bs/bin/opam + else + echo "openssl 512 option unsupported." + exit 61 + fi + fi + runit_BOOTSTRAPPED=1 + ;; + esac +} +section_begin bootstrap-opam 'Bootstrap opam' +do_bootstrap +section_end bootstrap-opam + +# Start environment distribution tarball +# We use .tar rather than .tar.gz/.tar.bz2 because we can repeatedly add to an uncompressed .tar. But we need to +# start with an empty tarball since some tar programs will only add ('tar rf xyz.tar') to an existing .tar. +install -d .ci/sd4/dist +tar cf .ci/sd4/dist/run-with-env.tar -T /dev/null + +do_get_dockcross() { + if [ -n "${dockcross_image:-}" ]; then + # The dockcross script is super-slow + section_begin get-dockcross 'Get dockcross binary (ManyLinux)' + install -d .ci/sd4 + # shellcheck disable=SC2086 + docker run ${dockcross_run_extra_args:-} --rm "${dockcross_image_custom_prefix:-}${dockcross_image:-}" >.ci/sd4/dockcross.gen + + # PROBLEM 1 + # --------- + # Super-annoying stderr output from dockcross at line: + # tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti + # When there is no tty, get: + # tty: ignoring all arguments + # not a tty + # So replace 'tty -s &&' with 'false &&' + sed 's/tty -s &&/false \&\&/' .ci/sd4/dockcross.gen >.ci/sd4/dockcross-real + rm -f .ci/sd4/dockcross.gen + chmod +x .ci/sd4/dockcross-real + + # PROBLEM 2 + # --------- + # By default dockcross for ManyLinux will chown -R all python packages; super-slow (~10 seconds)! + # Confer: https://github.com/dockcross/dockcross/blob/master/manylinux-common/pre_exec.sh + # That kills speed for any repetitive dockcross invocation. + # + # BUT it is unnecessary to chown -R when the current user is root, because inside the Docker container + # the files are already root! + # + # The chown -R (within pre_exec.sh) is not run when the user ids are not passed in. + # Confer: https://github.com/dockcross/dockcross/blob/96d87416f639af0204bdd42553e4b99315ca8476/imagefiles/entrypoint.sh#L21-L53 + # + # So explicitly call the entrypoint if root! + if echo "${dockcross_run_extra_args:-}" | grep -q linux/386; then + # https://github.com/dockcross/dockcross/blob/master/linux-x86/linux32-entrypoint.sh + # But only when `--platform linux/386` because the container image may be overridden. + dockcross_entrypoint=/dockcross/linux32-entrypoint.sh + else + dockcross_entrypoint=/dockcross/entrypoint.sh + fi + cat > .ci/sd4/dockcross <&2 "Missing functionality (\${f}) (in cygwin)." ; exit 1 ; } ; + done ; + HOST_PWD="\$( cygpath -w "\$( readlink -f "\$( pwd ;)" ; )" ; )" ; + else + HOST_PWD=\$PWD + [ -L \$HOST_PWD ] && HOST_PWD=\$(readlink \$HOST_PWD) + fi + + # ---------- End of dockcross script snippet ------- + + # Handle: dockcross --args "-v X:Y --platform P" + ARGS= + if [ "\$#" -ge 1 ] && [ "\$1" = "--args" ]; then + shift + ARGS=\$1 + shift + fi + + # Directly invoke entrypoint + exec docker run --entrypoint /bin/bash \ + --rm \ + \${ARGS:-} \ + -v "\$HOST_PWD":/work \ + ${dockcross_image_custom_prefix:-}${dockcross_image:-} ${dockcross_entrypoint} "\$@" +else + HERE=\$(dirname "\$0") + HERE=\$(cd "\$HERE" && pwd) + exec "\$HERE/dockcross-real" "\$@" +fi +EOF + chmod +x .ci/sd4/dockcross + + # Bundle for consumers of setup-dkml.yml + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/dockcross .ci/sd4/dockcross-real + + section_end get-dockcross + fi +} +do_get_dockcross + +if [ -n "${dockcross_image:-}" ]; then + # rsync needs to be available, even after Docker container disappears + if [ ! -e .ci/sd4/bs/bin/rsync ]; then + section_begin get-opam-prereqs-in-dockcross 'Get Opam prerequisites (ManyLinux)' + install -d .ci/sd4/bs/bin + # Install rsync with 'yum' (ManyLinux) or 'apt' (dockcross/linux-x64, etc.) + # if not present. + # shellcheck disable=SC2016 + .ci/sd4/dockcross --args "${dockcross_run_extra_args:-}" sh -c 'if ! command -v rsync; then if command -v yum; then sudo yum install -y rsync; else sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y rsync; fi; fi && install $(command -v rsync) .ci/sd4/bs/bin' + section_end get-opam-prereqs-in-dockcross + fi +fi + +# Opam prerequisites for using opam (not for installing opam) + +{ + if [ -n "${docker_runner:-}" ]; then + # rsync needs to be available, even after Docker container disappears + if [ ! -e .ci/sd4/bs/bin/rsync.deps ]; then + section_begin get-opam-prereqs-in-docker 'Get Opam prerequisites (Linux Docker)' + install -d .ci/sd4/bs/bin + ${docker_runner} sh -c ' + apt-get update -qq -o=Dpkg::Use-Pty=0 && + apt-get install -qq -o=Dpkg::Use-Pty=0 -y rsync && + ldd /usr/bin/rsync && + ls -l /lib/i386-linux-gnu/libpopt.so.0 /lib/i386-linux-gnu/libacl.so.1 /lib/i386-linux-gnu/libattr.so.1 && + tar cCfhz / /work/.ci/sd4/bs/bin/deps.tar.gz /usr/bin/rsync /lib/i386-linux-gnu/libpopt.so.0 + ' + touch .ci/sd4/bs/bin/rsync.deps + section_end get-opam-prereqs-in-docker + fi + fi + + # Bundle Opam prerequisites (ManyLinux or Linux Docker) + if [ -n "${docker_runner:-}" ] || [ -n "${dockcross_image:-}" ]; then + # Bundle for consumers of setup-dkml.yml + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/bs/bin/rsync + fi +} + +# Get Opam Cache +do_get_opam_cache() { + if [ "$unix_opam_root_cacheable" = "$unix_opam_root" ]; then return; fi + if [ ! -e "$unix_opam_root_cacheable" ]; then return; fi + section_begin get-opam-cache "Transferring Opam cache to $original_opam_root_cacheable" + echo Starting transfer # need some output or GitLab CI will not display the section duration + transfer_dir "$unix_opam_root_cacheable" "$unix_opam_root" + echo Finished transfer + section_end get-opam-cache +} +do_get_opam_cache + +# Setup Opam + +do_write_opam_scripts() { + case "${FDOPEN_OPAMEXE_BOOTSTRAP:-},$dkml_host_abi" in + true,windows_*) + # With fdopen's opam.exe, 'os-distribution = "cygwinports"'. But native Windows opam.exe has 'os-distribution = "win32"'. + # But on Windows we always want MSYS2 or native Windows libraries, not Cygwin. If cygwinports then + # code like https://github.com/ocaml/opam-repository/blob/08cbb8258bd4bf30cd6f307c958911a29d537b54/packages/conf-pkg-config/conf-pkg-config.2/opam#L36 + # will fail. So always set 'os-distribution = "win32"' on Windows. + PATCH_OS_DISTRIBUTION_WIN32=true + # With fdopen's opam.exe, no 'exe = ".exe"' is set because Cygwin does not need file extensions. + # Native Windows requires a .exe extension. + PATCH_EXE_WIN32=true + ;; + *) + PATCH_OS_DISTRIBUTION_WIN32=false + PATCH_EXE_WIN32=false + ;; + esac + + # --------------------- + # Empty opam repository + # --------------------- + + install -d .ci/sd4/eor + cat >.ci/sd4/eor/repo <.ci/sd4/troubleshoot-opam.sh </dev/null >/dev/null; then + FINDARGS="-mmin -240" # is -mmin supported? BSD (incl. macOS), MSYS2, GNU +else + FINDARGS="-mtime -1" # use 1 day instead. Solaris +fi +printf "\n\n========= [START OF TROUBLESHOOTING] ===========\n\n" >&2 +find "\$OPAMROOT"/log -mindepth 1 -maxdepth 1 \$FINDARGS -name "*.out" ! -name "log-*.out" ! -name "ocaml-variants-*.out" | while read -r dump_on_error_LOG; do + dump_on_error_BLOG=\$(basename "\$dump_on_error_LOG") + printf "\n\n========= [TROUBLESHOOTING] %s ===========\n\n" "\$dump_on_error_BLOG" >&2 + awk -v BLOG="\$dump_on_error_BLOG" '{print "[" BLOG "]", \$0}' "\$dump_on_error_LOG" >&2 +done +printf "\nScroll up to see the [TROUBLESHOOTING] logs that begin at the [START OF TROUBLESHOOTING] line\n" >&2 +EOF + + chmod +x .ci/sd4/troubleshoot-opam.sh + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/troubleshoot-opam.sh + + # --------------- + # Create Opam support scripts (not needed for all platforms) + # The PATH to find opam must work internally in setup-dkml.yml (sd4/bs/bin) and + # by consumers of setup-dkml.yml (sd4/opamexe) + # --------------- + + USER_ID=$(id -u) + GROUP_ID=$(id -g) + USER_NAME=$(id -un) + GROUP_NAME=$(id -gn) + + case "${opam_root}" in + /* | ?:*) # /a/b/c or C:\Windows + validate_supports_docker() { + echo "Docker only supported with relative paths for the opam root, not: ${opam_root}" >&2 + exit 3 + } + ;; + *) # relative path + validate_supports_docker() { + true + } + cat >.ci/sd4/run-in-docker <&2 +set +e +"\$prog" "\$@" +exitcode=\$? +if [ \$troubleshooting = 1 ] && [ \$prog = opam ]; then + [ \$exitcode = 0 ] || "/work/.ci/sd4/troubleshoot-opam.sh" \$OPAMROOT +fi +exit \$exitcode +EOF + chmod +x .ci/sd4/run-in-docker + ;; + esac + + cat >.ci/sd4/deescalate <.ci/sd4/run-with-env <&2 + cat .ci/sd4/run-in-docker >&2 + echo '___________________' >&2 + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/run-with-env .ci/sd4/run-in-docker .ci/sd4/edr + + elif [ -n "${docker_runner:-}" ]; then + + cat >.ci/sd4/run-with-env <&2 + cat .ci/sd4/run-in-docker >&2 + echo '________________________' >&2 + echo '__ deescalate __' >&2 + cat .ci/sd4/deescalate >&2 + echo '________________' >&2 + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/run-with-env .ci/sd4/run-in-docker .ci/sd4/deescalate + + else + + cat >.ci/sd4/run-with-env <&2 +set +e +"\$prog" "\$@" +exitcode=\$? +if [ \$troubleshooting = 1 ] && [ \$prog = opam ]; then + [ \$exitcode = 0 ] || "\${PROJECT_DIR}/.ci/sd4/troubleshoot-opam.sh" \$OPAMROOT +fi +exit \$exitcode +EOF + chmod +x .ci/sd4/run-with-env + + # Bundle for consumers of setup-dkml.yml + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/run-with-env + + fi + echo '__ run-with-env __' >&2 + cat .ci/sd4/run-with-env >&2 + echo '__________________' >&2 + + # ------ + # cmdrun + # ------ + + install -d .ci/sd4/opamrun + cat >.ci/sd4/opamrun/cmdrun <.ci/sd4/opamrun/opamrun <>"$GITHUB_PATH" + # Special case: GITHUB_PATH does not influence msys2.CMD of msys2/setup-msys2@v2, so place in real MSYS2 PATH + if [ -n "${MSYSTEM:-}" ]; then + install -d /usr/local/bin + install .ci/sd4/opamrun/opamrun /usr/local/bin/opamrun + fi +fi + +# Place opamrun in the immediate PATH +PATH="$setup_WORKSPACE/.ci/sd4/opamrun:$PATH" + +# Complicated Opam sequence is because: +# 1. Opam's default curl does not work on Windows, +# and `opam init` does not provide a way to change it (TODO: need +# a PR!). +# 2. We have to separate the Opam download cache from the other Opam +# caches +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ] && [ ! -s "$opam_root/.ci.root-init" ]; then # non-empty init file so can be cached irrespective of existence + section_begin opam-init 'Initialize opam root' + + # Clear any partial previous attempt + rm -rf "$opam_root" + + case "$dkml_host_abi,${in_docker:-}" in + windows_*,*) + eor=$(cygpath -am "$setup_WORKSPACE"/.ci/sd4/eor) + opamrun init --disable-sandboxing --no-setup --kind local --bare "$eor" + case "$(opamrun --version)" in + 2.0.*) echo 'download-command: wget' >>"$opam_root/config" ;; + *) opamrun option --yes --global download-command=wget ;; + esac + ;; + *,true) + opamrun init --disable-sandboxing --no-setup --kind local --bare "/work/.ci/sd4/eor" + ;; + *) + opamrun init --disable-sandboxing --no-setup --kind local --bare "$setup_WORKSPACE/.ci/sd4/eor" + ;; + esac + echo yes > "$opam_root/.ci.root-init" + + section_end opam-init +fi + +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + section_begin opam-vars "Summary: opam global variables" + opamrun --no-troubleshooting var --global || true + section_end opam-vars +fi + +# Build OCaml + +do_switch_create() { + do_switch_create_NAME=$1 + shift + + section_begin "switch-create-$do_switch_create_NAME" "Create opam switch '$do_switch_create_NAME'" + # Create, or recreate, the Opam switch. The Opam switch should not be + # cached except for the compiler (confer docs for setup-ocaml GitHub + # Action) which is the 'dkml' switch (or the 'two' switch). + # Check if the switch name is present in the Opam root (which may come from cache) + NOMINALLY_PRESENT=false + if opamrun switch list --short | grep "^${do_switch_create_NAME}\$"; then NOMINALLY_PRESENT=true; fi + + # Check if the switch is actually present in case of cache incoherence + # or corrupt Opam state that could result in: + # Error: No config file found for switch dkml. Switch broken? + if [ $NOMINALLY_PRESENT = true ] && [ ! -e "$opam_root/$do_switch_create_NAME/.opam-switch/switch-config" ]; then + # Remove the switch name from Opam root, and any partial switch state. + # Ignore inevitable warnings/failure about missing switch. + opamrun --no-troubleshooting switch remove "$do_switch_create_NAME" --yes || true + rm -rf "${opam_root:?}/$do_switch_create_NAME" + NOMINALLY_PRESENT=false + fi + + if [ $NOMINALLY_PRESENT = false ]; then + opamrun switch create "$do_switch_create_NAME" --empty --yes + fi + section_end "switch-create-$do_switch_create_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_switch_create dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_switch_create two + else + section_begin "switch-create-two" "Create empty opam switch 'two'" + # Always create a secondary switch ... just empty. Avoid problems with cache content missing + # and idempotency. + opamrun --no-troubleshooting switch remove two --yes || true + rm -rf "$opam_root/two" + opamrun switch create two --empty --yes + section_end "switch-create-two" + fi +fi + +do_switch_active() { + section_begin "switch-active" "Set dkml as active switch" + opamrun switch set dkml --yes + section_end "switch-active" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_switch_active +fi + +do_opam_repositories_add() { + section_begin "opam-repo-add" "Add 'diskuv' opam repository" + if ! opamrun --no-troubleshooting repository list -s | grep '^diskuv'; then + opamrun repository add diskuv "git+https://github.com/diskuv/diskuv-opam-repository.git#${DISKUV_OPAM_REPOSITORY:-$DEFAULT_DISKUV_OPAM_REPOSITORY_TAG}" --yes --dont-select + fi + section_end "opam-repo-add" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_opam_repositories_add +fi + +do_opam_repositories_config() { + do_opam_repositories_config_NAME=$1 + shift + + section_begin "opam-repo-$do_opam_repositories_config_NAME" "Attach repositories to $do_opam_repositories_config_NAME" + + if [ ! -s "$opam_root/.ci.$do_opam_repositories_config_NAME.repo-init" ]; then # non-empty init file so can be cached irrespective of existence + opamrun --no-troubleshooting repository remove default --switch "$do_opam_repositories_config_NAME" --yes || true + opamrun --no-troubleshooting repository remove diskuv --switch "$do_opam_repositories_config_NAME" --yes || true + opamrun repository add default --switch "$do_opam_repositories_config_NAME" --yes + opamrun repository add diskuv --switch "$do_opam_repositories_config_NAME" --yes + echo yes > "$opam_root/.ci.$do_opam_repositories_config_NAME.repo-init" + fi + + section_end "opam-repo-$do_opam_repositories_config_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_opam_repositories_config dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_opam_repositories_config two + fi +fi + +do_opam_repositories_update() { + section_begin "opam-repo-update" "Update opam repositories" + # The default repository may be the initial 'eor' (empty) repository + opamrun repository set-url default https://opam.ocaml.org --yes + # Always set the `diskuv` repository url since it can change + opamrun repository set-url diskuv "git+https://github.com/diskuv/diskuv-opam-repository.git#${DISKUV_OPAM_REPOSITORY:-$DEFAULT_DISKUV_OPAM_REPOSITORY_TAG}" --yes --dont-select + # Update both `default` and `diskuv` Opam repositories + opamrun update default diskuv + section_end "opam-repo-update" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_opam_repositories_update +fi + +do_pins() { + do_pins_NAME=$1 + shift + + section_begin "opam-pins-$do_pins_NAME" "Opam pins for $do_pins_NAME switch" + ### BEGIN pin-adds. DO NOT EDIT THE LINES IN THIS SECTION + # Managed by bump-packages.cmake + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version astring "${PIN_ASTRING}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version base "${PIN_BASE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version base64 "${PIN_BASE64}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version bigarray-compat "${PIN_BIGARRAY_COMPAT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version bos "${PIN_BOS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version camlp-streams "${PIN_CAMLP_STREAMS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version chrome-trace "${PIN_CHROME_TRACE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cmdliner "${PIN_CMDLINER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version conf-dkml-sys-opam "${PIN_CONF_DKML_SYS_OPAM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version conf-pkg-config "${PIN_CONF_PKG_CONFIG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version conf-sqlite3 "${PIN_CONF_SQLITE3}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cppo "${PIN_CPPO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version crunch "${PIN_CRUNCH}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version csexp "${PIN_CSEXP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cstruct "${PIN_CSTRUCT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ctypes "${PIN_CTYPES}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ctypes-foreign "${PIN_CTYPES_FOREIGN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cudf "${PIN_CUDF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version digestif "${PIN_DIGESTIF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version diskuvbox "${PIN_DISKUVBOX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-apps "${PIN_DKML_APPS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-base-compiler "${PIN_DKML_BASE_COMPILER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-build-desktop "${PIN_DKML_BUILD_DESKTOP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-c-probe "${PIN_DKML_C_PROBE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-compiler-env "${PIN_DKML_COMPILER_ENV}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-compiler-src "${PIN_DKML_COMPILER_SRC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-common-desktop "${PIN_DKML_COMPONENT_COMMON_DESKTOP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-common-opam "${PIN_DKML_COMPONENT_COMMON_OPAM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-common-unixutils "${PIN_DKML_COMPONENT_COMMON_UNIXUTILS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-ocamlcompiler-common "${PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-ocamlcompiler-network "${PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-ocamlcompiler-offline "${PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-offline-desktop-full "${PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-offline-opamshim "${PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-offline-unixutils "${PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-desktop-full "${PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-dkmlconfdir "${PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-ocamlrun "${PIN_DKML_COMPONENT_STAGING_OCAMLRUN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-opam32 "${PIN_DKML_COMPONENT_STAGING_OPAM32}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-opam64 "${PIN_DKML_COMPONENT_STAGING_OPAM64}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-unixutils "${PIN_DKML_COMPONENT_STAGING_UNIXUTILS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-withdkml "${PIN_DKML_COMPONENT_STAGING_WITHDKML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-xx-console "${PIN_DKML_COMPONENT_XX_CONSOLE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-exe "${PIN_DKML_EXE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-exe-lib "${PIN_DKML_EXE_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-install "${PIN_DKML_INSTALL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-install-installer "${PIN_DKML_INSTALL_INSTALLER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-install-runner "${PIN_DKML_INSTALL_RUNNER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-installer-ocaml-common "${PIN_DKML_INSTALLER_OCAML_COMMON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-installer-ocaml-offline "${PIN_DKML_INSTALLER_OCAML_OFFLINE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-package-console "${PIN_DKML_PACKAGE_CONSOLE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtime-common "${PIN_DKML_RUNTIME_COMMON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtime-common-native "${PIN_DKML_RUNTIME_COMMON_NATIVE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtime-distribution "${PIN_DKML_RUNTIME_DISTRIBUTION}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtimelib "${PIN_DKML_RUNTIMELIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtimescripts "${PIN_DKML_RUNTIMESCRIPTS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-workflows "${PIN_DKML_WORKFLOWS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune "${PIN_DUNE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-action-plugin "${PIN_DUNE_ACTION_PLUGIN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-build-info "${PIN_DUNE_BUILD_INFO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-configurator "${PIN_DUNE_CONFIGURATOR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-glob "${PIN_DUNE_GLOB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-private-libs "${PIN_DUNE_PRIVATE_LIBS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-rpc "${PIN_DUNE_RPC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-rpc-lwt "${PIN_DUNE_RPC_LWT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-site "${PIN_DUNE_SITE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dyn "${PIN_DYN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version either "${PIN_EITHER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version eqaf "${PIN_EQAF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version extlib "${PIN_EXTLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ezjsonm "${PIN_EZJSONM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version feather "${PIN_FEATHER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fiber "${PIN_FIBER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fix "${PIN_FIX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fmt "${PIN_FMT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fpath "${PIN_FPATH}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version graphics "${PIN_GRAPHICS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version hex "${PIN_HEX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version integers "${PIN_INTEGERS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jane-street-headers "${PIN_JANE_STREET_HEADERS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jingoo "${PIN_JINGOO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jsonm "${PIN_JSONM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jsonrpc "${PIN_JSONRPC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jst-config "${PIN_JST_CONFIG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lambda-term "${PIN_LAMBDA_TERM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version logs "${PIN_LOGS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lsp "${PIN_LSP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lwt "${PIN_LWT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lwt_react "${PIN_LWT_REACT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mccs "${PIN_MCCS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mdx "${PIN_MDX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version menhir "${PIN_MENHIR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version menhirLib "${PIN_MENHIRLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version menhirSdk "${PIN_MENHIRSDK}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version merlin-lib "${PIN_MERLIN_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version metapp "${PIN_METAPP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version metaquot "${PIN_METAQUOT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mew "${PIN_MEW}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mew_vi "${PIN_MEW_VI}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version num "${PIN_NUM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml "${PIN_OCAML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml-compiler-libs "${PIN_OCAML_COMPILER_LIBS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml-lsp-server "${PIN_OCAML_LSP_SERVER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml-version "${PIN_OCAML_VERSION}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlbuild "${PIN_OCAMLBUILD}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlc-loc "${PIN_OCAMLC_LOC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlfind "${PIN_OCAMLFIND}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlformat "${PIN_OCAMLFORMAT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlformat-lib "${PIN_OCAMLFORMAT_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlformat-rpc-lib "${PIN_OCAMLFORMAT_RPC_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocp-indent "${PIN_OCP_INDENT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocplib-endian "${PIN_OCPLIB_ENDIAN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version odoc "${PIN_ODOC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version odoc-parser "${PIN_ODOC_PARSER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ordering "${PIN_ORDERING}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version parsexp "${PIN_PARSEXP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version pp "${PIN_PP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_assert "${PIN_PPX_ASSERT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_base "${PIN_PPX_BASE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_cold "${PIN_PPX_COLD}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_compare "${PIN_PPX_COMPARE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_derivers "${PIN_PPX_DERIVERS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_deriving "${PIN_PPX_DERIVING}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_enumerate "${PIN_PPX_ENUMERATE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_expect "${PIN_PPX_EXPECT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_globalize "${PIN_PPX_GLOBALIZE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_hash "${PIN_PPX_HASH}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_here "${PIN_PPX_HERE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_ignore_instrumentation "${PIN_PPX_IGNORE_INSTRUMENTATION}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_inline_test "${PIN_PPX_INLINE_TEST}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_optcomp "${PIN_PPX_OPTCOMP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_pipebang "${PIN_PPX_PIPEBANG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_sexp_conv "${PIN_PPX_SEXP_CONV}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_yojson_conv_lib "${PIN_PPX_YOJSON_CONV_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppxlib "${PIN_PPXLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ptime "${PIN_PTIME}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version qrc "${PIN_QRC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version re "${PIN_RE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version react "${PIN_REACT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version refl "${PIN_REFL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version result "${PIN_RESULT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version rresult "${PIN_RRESULT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version seq "${PIN_SEQ}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sexplib "${PIN_SEXPLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sexplib0 "${PIN_SEXPLIB0}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sha "${PIN_SHA}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version spawn "${PIN_SPAWN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sqlite3 "${PIN_SQLITE3}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdcompat "${PIN_STDCOMPAT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdio "${PIN_STDIO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdlib-shims "${PIN_STDLIB_SHIMS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdune "${PIN_STDUNE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version time_now "${PIN_TIME_NOW}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version topkg "${PIN_TOPKG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version traverse "${PIN_TRAVERSE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version trie "${PIN_TRIE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version tsort "${PIN_TSORT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version tyxml "${PIN_TYXML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uchar "${PIN_UCHAR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version utop "${PIN_UTOP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uucp "${PIN_UUCP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uuidm "${PIN_UUIDM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uuseg "${PIN_UUSEG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uutf "${PIN_UUTF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version with-dkml "${PIN_WITH_DKML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version xdg "${PIN_XDG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version yojson "${PIN_YOJSON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version zed "${PIN_ZED}" + ### END pin-adds. DO NOT EDIT THE LINES ABOVE + section_end "opam-pins-$do_pins_NAME" + + # -------------- + # REMAINING PINS + # -------------- + + # These come after [pin-adds] section since [pin-adds] may need to be overridden by + # users' choice. + + # dkml-base-compiler + + if [ "${DKML_COMPILER:-}" != '@repository@' ] && [ -z "${DKML_COMPILER:-}" ] && [ -z "${OCAML_COMPILER:-}" ]; then + section_begin checkout-dkml-base-compiler "Pin dkml-base-compiler to default ${DEFAULT_DKML_COMPILER} (neither dkml-base-compiler nor OCAML_COMPILER specified) for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action dkml-base-compiler "https://github.com/diskuv/dkml-compiler.git#${DEFAULT_DKML_COMPILER}" + section_end checkout-dkml-base-compiler + elif [ "${DKML_COMPILER:-}" != '@repository@' ] && [ -n "${DKML_COMPILER:-}" ] && [ -z "${OCAML_COMPILER:-}" ]; then + section_begin checkout-dkml-base-compiler "Pin dkml-base-compiler to $DKML_COMPILER (dkml-base-compiler specified; no OCAML_COMPILER specified) for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action dkml-base-compiler "https://github.com/diskuv/dkml-compiler.git#${DKML_COMPILER}" + section_end checkout-dkml-base-compiler + elif [ -n "${OCAML_COMPILER:-}" ]; then + # Validate OCAML_COMPILER (OCAML_COMPILER specified) + case "${OCAML_COMPILER:-}" in + 4.12.1) true ;; + 4.14.0) true ;; + *) + echo "OCAML_COMPILER version ${OCAML_COMPILER:-} is not supported" >&2 + exit 109 + ;; + esac + + section_begin checkout-dkml-base-compiler "Pin dkml-base-compiler (OCAML_COMPILER specified) for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action dkml-base-compiler "https://github.com/diskuv/dkml-compiler.git#${OCAML_COMPILER}-v${DKML_VERSION}" + section_end checkout-dkml-base-compiler + fi + + # conf-dkml-cross-toolchain + + if [ "${CONF_DKML_CROSS_TOOLCHAIN:-}" != '@repository@' ]; then + section_begin checkout-conf-dkml-cross-toolchain "Pin conf-dkml-cross-toolchain for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action conf-dkml-cross-toolchain "https://github.com/diskuv/conf-dkml-cross-toolchain.git#$CONF_DKML_CROSS_TOOLCHAIN" + section_end checkout-conf-dkml-cross-toolchain + fi +} + +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_pins dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_pins two + fi +fi + +do_use_vsstudio() { + do_use_vsstudio_NAME=$1 + shift + case "$dkml_host_abi" in + windows_*) + section_begin "use-vsstudio-$do_use_vsstudio_NAME" "Use Visual Studio in dkml-* Opam packages (Windows) for $do_use_vsstudio_NAME switch" + + # shellcheck disable=SC2153 + E_VS_DIR=$(escape_arg_as_ocaml_string "$VS_DIR") + # shellcheck disable=SC2153 + E_VS_VCVARSVER=$(escape_arg_as_ocaml_string "$VS_VCVARSVER") + # shellcheck disable=SC2153 + E_VS_WINSDKVER=$(escape_arg_as_ocaml_string "$VS_WINSDKVER") + # shellcheck disable=SC2153 + E_VS_MSVSPREFERENCE=$(escape_arg_as_ocaml_string "$VS_MSVSPREFERENCE") + # shellcheck disable=SC2153 + E_VS_CMAKEGENERATOR=$(escape_arg_as_ocaml_string "$VS_CMAKEGENERATOR") + + case "$(opamrun --version)" in + 2.0.*) + if [ "${in_docker}" = "true" ]; then + echo Opam 2.0 support in dockcross to use a portable opam var prefix not yet implemented + exit 67 + fi + OP=$(opamrun var prefix --switch "$do_use_vsstudio_NAME") + OPSC=$OP/.opam-switch/switch-config + if grep setenv: "$OPSC"; then + echo "INFO: Updating switch-config. Old was:" + awk '{print ">> " $0}' "$OPSC" + + awk '$1=="setenv:"{x=1} x==0{print} x==1 && $0=="]"{x=0}' "$OPSC" >"$OPSC".trimmed + mv "$OPSC".trimmed "$OPSC" + fi + echo 'setenv: [' >>"$OPSC" + echo ' [DKML_COMPILE_SPEC = "1"]' >>"$OPSC" + echo ' [DKML_COMPILE_TYPE = "VS"]' >>"$OPSC" + echo " [DKML_COMPILE_VS_DIR = \"$E_VS_DIR\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_VCVARSVER = \"$E_VS_VCVARSVER\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_WINSDKVER = \"$E_VS_WINSDKVER\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_MSVSPREFERENCE = \"$E_VS_MSVSPREFERENCE\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_CMAKEGENERATOR = \"$E_VS_CMAKEGENERATOR\"]" >>"$OPSC" + echo " [DKML_HOST_ABI = \"${dkml_host_abi}\"]" >>"$OPSC" + echo ']' >>"$OPSC" + cat "$OPSC" >&2 # print + ;; + *) + opamrun option --switch "$do_use_vsstudio_NAME" setenv= # reset + opamrun option --switch "$do_use_vsstudio_NAME" setenv+='DKML_COMPILE_SPEC = "1"' + opamrun option --switch "$do_use_vsstudio_NAME" setenv+='DKML_COMPILE_TYPE = "VS"' + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_DIR = \"$E_VS_DIR\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_VCVARSVER = \"$E_VS_VCVARSVER\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_WINSDKVER = \"$E_VS_WINSDKVER\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_MSVSPREFERENCE = \"$E_VS_MSVSPREFERENCE\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_CMAKEGENERATOR = \"$E_VS_CMAKEGENERATOR\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_HOST_ABI = \"${dkml_host_abi}\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv # print + ;; + esac + + # shellcheck disable=SC2016 + opamrun exec --switch "$do_use_vsstudio_NAME" -- sh -c 'echo $VCToolsRedistDir' + + section_end "use-vsstudio-$do_use_vsstudio_NAME" + ;; + esac +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_use_vsstudio dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_use_vsstudio two + fi +fi + +# Because dune.X.Y.Z+shim (and any user DKML packages) requires DKML installed (after all, it is just +# a with-dkml.exe shim), we need either dkmlvars-v2.sexp or DKML environment +# variables. Confer: Dkml_runtimelib.Dkml_context.get_dkmlversion +# +# grep matches either: +# [... [DiskuvOCamlVersion = "1.0.1"] ...] +# DiskuvOCamlVersion = "1.0.1" +do_setenv() { + do_setenv_SWITCH=$1 + shift + section_begin "setenv-$do_setenv_SWITCH" "Set opam option for $do_setenv_SWITCH switch" + opamrun option --switch "$do_setenv_SWITCH" setenv > ".ci/sd4/setenv.$do_setenv_SWITCH.txt" + if ! grep -q '\(^|\[\)DiskuvOCamlVarsVersion ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+='DiskuvOCamlVarsVersion = "2"' + fi + if ! grep -q '\(^|\[\)DiskuvOCamlVersion ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlVersion = \"$DKML_VERSION\"" + fi + if [ "$do_setenv_SWITCH" = dkml ] && [ -n "${DKML_HOME:-}" ]; then + do_setenv_DKMLHOME_ESCAPED="$DKML_HOME" + do_setenv_USRBIN_ESCAPED="$DKML_HOME/usr/bin" + do_setenv_BIN_ESCAPED="$DKML_HOME/bin" + if [ -x /usr/bin/cygpath ]; then + do_setenv_DKMLHOME_ESCAPED=$(/usr/bin/cygpath -aw "$do_setenv_DKMLHOME_ESCAPED" | sed 's/\\/\\\\/g') + do_setenv_USRBIN_ESCAPED=$(/usr/bin/cygpath -aw "$do_setenv_USRBIN_ESCAPED" | sed 's/\\/\\\\/g') + do_setenv_BIN_ESCAPED=$(/usr/bin/cygpath -aw "$do_setenv_BIN_ESCAPED" | sed 's/\\/\\\\/g') + fi + if ! grep -q '\(^|\[\)DiskuvOCamlHome ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlHome = \"$do_setenv_DKMLHOME_ESCAPED\"" + fi + if ! grep -q '\(^|\[\)DiskuvOCamlBinaryPaths ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlBinaryPaths = \"$do_setenv_USRBIN_ESCAPED;$do_setenv_BIN_ESCAPED\"" + fi + if ! grep -q '\(^|\[\)DiskuvOCamlDeploymentId ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlDeploymentId = \"setup-dkml-switch-$do_setenv_SWITCH\"" + fi + fi + case "${dkml_host_abi}" in + windows_*) + if ! grep -q '\(^|\[\)DiskuvOCamlMSYS2Dir ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + if [ -x /usr/bin/cygpath ]; then + MSYS2_DIR_NATIVE=$(/usr/bin/cygpath -aw /) + else + # If we are already inside MSYS2 then MSYSTEM_PREFIX should be set. But cygpath should be there as well!! + echo "FATAL: Could not locate MSYS2: there was no cygpath" >&2 + exit 3 + fi + MSYS2_DIR_NATIVE_ESCAPED=$(printf "%s" "$MSYS2_DIR_NATIVE" | sed 's/\\/\\\\/g') + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlMSYS2Dir = \"$MSYS2_DIR_NATIVE_ESCAPED\"" + fi + esac + section_end "setenv-$do_setenv_SWITCH" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_setenv dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_setenv two + fi +fi + +do_install_compiler() { + do_install_compiler_NAME=$1 + shift + section_begin "install-compiler-$do_install_compiler_NAME" "Install OCaml compiler for $do_install_compiler_NAME switch" + opamrun pin list --switch "$do_install_compiler_NAME" + # shellcheck disable=SC2086 + opamrun upgrade --switch "$do_install_compiler_NAME" --yes dkml-base-compiler conf-dkml-cross-toolchain ${ocaml_options:-} + section_end "install-compiler-$do_install_compiler_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + if ! [ "${PRIMARY_SWITCH_SKIP_INSTALL:-}" = "true" ]; then + do_install_compiler dkml + fi + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_install_compiler two + fi +fi + +do_summary() { + do_summary_NAME=$1 + shift + section_begin "summary-$do_summary_NAME" "Summary: $do_summary_NAME switch" + opamrun var --switch "$do_summary_NAME" + opamrun exec --switch "$do_summary_NAME" -- ocamlc -config + section_end "summary-$do_summary_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_summary dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_summary two + fi +fi + +'@ +Set-Content -Path ".ci\sd4\run-setup-dkml.sh" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/run-setup-dkml.sh' + +$Content = @' +# MSVC environment variables: +# 1. https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170 +# 2. https://docs.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-170#link-environment-variables (except TMP) +# 3. VCToolsRedistDir: https://docs.microsoft.com/en-us/cpp/windows/redistributing-visual-cpp-files?view=msvc-170#locate-the-redistributable-files +BEGIN{FS="="} +$1=="CL"||$1=="_CL_"||$1=="INCLUDE"||$1=="LIBPATH" {print "export " $0} +$1=="LINK"||$1=="_LINK_"||$1=="LIB"||$1=="PATH" {print "export " $0} +$1=="VCToolsRedistDir" {print "export " $0} + +'@ +Set-Content -Path ".ci\sd4\msvcenv.awk" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/msvcenv.awk' + + +$Content = @' +{ + # trim leading and trailing space + sub(/^ */, ""); + sub(/ *$/, ""); + + print "export PATH='" $0 "'"; +} +'@ +Set-Content -Path ".ci\sd4\msvcpath.awk" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/msvcpath.awk' + +# PowerShell (UTF-16) and Batch (ANSI) scripts + + +$Content = @' +# Diagnose Visual Studio environment variables (Windows) +# This wastes time and has lots of rows! Only run if "VERBOSE" GitHub input key. +if ( "${env:VERBOSE}" -eq "true" ) { + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\include") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\include" + } + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop" + } + + $env:PSModulePath += "$([System.IO.Path]::PathSeparator).ci\sd4\g\dkml-runtime-distribution\src\windows" + Import-Module Machine + + $allinstances = Get-VSSetupInstance + $allinstances | ConvertTo-Json -Depth 5 +} + +# Make export expression [SN]NAME=[SV]VALUE[EV] +# where [SN] is start name and [SV] and [EV] are start and end value +if (("${env:GITLAB_CI}" -eq "true") -or ("${env:PC_CI}" -eq "true")) { + # Executed immediately in POSIX shell, so must be a real POSIX shell variable declaration + $ExportSN = "export " + $ExportSV = "'" + $ExportEV = "'" + $ExportExt = ".sh" +} else { + # Goes into $env:GITHUB_ENV, so must be plain NAME=VALUE + $ExportSN = "" + $ExportSV = "" + $ExportEV = "" + $ExportExt = ".github" +} + +# Locate Visual Studio (Windows) +if ("${env:vsstudio_dir}" -eq "" -and (!(Test-Path -Path .ci/sd4/vsenv${ExportExt}) -or !(Test-Path -Path .ci/sd4/vsenv.ps1))) { + $env:PSModulePath += "$([System.IO.Path]::PathSeparator).ci\sd4\g\dkml-runtime-distribution\src\windows" + Import-Module Machine + + $CompatibleVisualStudios = Get-CompatibleVisualStudios -ErrorIfNotFound + $CompatibleVisualStudios + $ChosenVisualStudio = ($CompatibleVisualStudios | Select-Object -First 1) + $VisualStudioProps = Get-VisualStudioProperties -VisualStudioInstallation $ChosenVisualStudio + $VisualStudioProps + + Write-Output "${ExportSN}VS_DIR=${ExportSV}$($VisualStudioProps.InstallPath)${ExportEV}" > .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_VCVARSVER=${ExportSV}$($VisualStudioProps.VcVarsVer)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_WINSDKVER=${ExportSV}$($VisualStudioProps.WinSdkVer)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_MSVSPREFERENCE=${ExportSV}$($VisualStudioProps.MsvsPreference)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_CMAKEGENERATOR=${ExportSV}$($VisualStudioProps.CMakeGenerator)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + + Write-Output "`$env:VS_DIR='$($VisualStudioProps.InstallPath)'" > .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_VCVARSVER='$($VisualStudioProps.VcVarsVer)'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_WINSDKVER='$($VisualStudioProps.WinSdkVer)'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_MSVSPREFERENCE='$($VisualStudioProps.MsvsPreference)'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_CMAKEGENERATOR='$($VisualStudioProps.CMakeGenerator)'" >> .ci/sd4/vsenv.ps1 +} + +# Link to hardcoded Visual Studio (Windows) +if ("${env:vsstudio_dir}" -ne "") { + Write-Output "${ExportSN}VS_DIR=${ExportSV}${env:vsstudio_dir}${ExportEV}" > .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_VCVARSVER=${ExportSV}${env:vsstudio_vcvarsver}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_WINSDKVER=${ExportSV}${env:vsstudio_winsdkver}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_MSVSPREFERENCE=${ExportSV}${env:vsstudio_msvspreference}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_CMAKEGENERATOR=${ExportSV}${env:vsstudio_cmakegenerator}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + + Write-Output "`$env:VS_DIR='${env:vsstudio_dir}'" > .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_VCVARSVER='${env:vsstudio_vcvarsver}'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_WINSDKVER='${env:vsstudio_winsdkver}'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_MSVSPREFERENCE='${env:vsstudio_msvspreference}'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_CMAKEGENERATOR='${env:vsstudio_cmakegenerator}'" >> .ci/sd4/vsenv.ps1 +} + +'@ +Set-Content -Path ".ci\sd4\config-vsstudio.ps1" -Encoding Unicode -Value $Content + + +$Content = @' +@ECHO OFF + +REM The OCaml dkml-base-compiler will compile fine but any other +REM packages (ocamlbuild, etc.) which +REM need a native compiler will fail without the MSVC compiler in the +REM PATH. There isn't a `with-dkml.exe` alternative available at +REM this stage of the GitHub workflow. +SET VSCMD_DEBUG=2 +SET VSCMD_SKIP_SENDTELEMETRY=1 +call "%VS_DIR%\Common7\Tools\VsDevCmd.bat" -no_logo -host_arch=%vsstudio_hostarch% -arch=%vsstudio_arch% -vcvars_ver=%VS_VCVARSVER% -winsdk=%VS_WINSDKVER% +if %ERRORLEVEL% neq 0 ( + echo. + echo.The "%VS_DIR%\Common7\Tools\VsDevCmd.bat" command failed + echo.with exit code %ERRORLEVEL%. + echo. + exit /b %ERRORLEVEL% +) + +REM VsDevCmd.bat turns off echo; be explicit if we want it on or off +@echo OFF + +REM MSVC environment variables in Unix format. +echo %PATH% > .ci\sd4\msvcpath + + +REM * We can't use `bash -lc` directly to query for all MSVC environment variables +REM because it stomps over the PATH. So we are inside a Batch script to do the query. +msys64\usr\bin\bash -lc "set | grep -v '^PATH=' | awk -f .ci/sd4/msvcenv.awk > .ci/sd4/msvcenv" +'@ +Set-Content -Path ".ci\sd4\get-msvcpath-into-msys2.bat" -Encoding Default -Value $Content + +msys64\usr\bin\bash -lc "sh .ci/sd4/run-checkout-code.sh PC_PROJECT_DIR '${env:PC_PROJECT_DIR}'" +if ($LASTEXITCODE -ne 0) { + throw "run-checkout-code.sh failed" +} + +# Diagnose Visual Studio environment variables (Windows) +# This wastes time and has lots of rows! Only run if "VERBOSE" GitHub input key. + +If ( "${env:VERBOSE}" -eq "true" ) { + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\include") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\include" + } + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop" + } + + $env:PSModulePath += "$([System.IO.Path]::PathSeparator).ci\sd4\g\dkml-runtime-distribution\src\windows" + Import-Module Machine + + $allinstances = Get-VSSetupInstance + $allinstances | ConvertTo-Json -Depth 5 +} +.ci\sd4\config-vsstudio.ps1 +msys64\usr\bin\bash -lc "dos2unix .ci/sd4/vsenv.sh" +Get-Content .ci/sd4/vsenv.sh +Get-Content .ci/sd4/vsenv.ps1 + +# Capture Visual Studio compiler environment +& .ci\sd4\vsenv.ps1 +& .ci\sd4\get-msvcpath-into-msys2.bat +msys64\usr\bin\bash -lc "cat .ci/sd4/msvcpath | tr -d '\r' | cygpath --path -f - | awk -f .ci/sd4/msvcpath.awk >> .ci/sd4/msvcenv" +msys64\usr\bin\bash -lc "tail -n100 .ci/sd4/msvcpath .ci/sd4/msvcenv" + +msys64\usr\bin\bash -lc "sh .ci/sd4/run-setup-dkml.sh PC_PROJECT_DIR '${env:PC_PROJECT_DIR}'" +if ($LASTEXITCODE -ne 0) { + throw "run-setup-dkml.sh failed" +} + +########################### script ############################### + +Write-Host @" +Finished setup. + +To continue your testing, run in PowerShell: + `$env:CHERE_INVOKING = "yes" + `$env:MSYSTEM = "$env:msys2_system" + `$env:dkml_host_abi = "$env:dkml_host_abi" + `$env:abi_pattern = "$env:abi_pattern" + `$env:opam_root = "$env:opam_root" + `$env:exe_ext = "$env:exe_ext" + +Now you can use 'opamrun' to do opam commands like: + + msys64\usr\bin\bash -lc 'PATH="`$PWD/.ci/sd4/opamrun:`$PATH"; opamrun install XYZ.opam' + msys64\usr\bin\bash -lc 'PATH="`$PWD/.ci/sd4/opamrun:`$PATH"; opamrun exec -- bash' + msys64\usr\bin\bash -lc 'sh ci/build-test.sh' +"@ diff --git a/.ci/dkml-compilers/pc/setup-dkml-windows_x86_64.ps1 b/.ci/dkml-compilers/pc/setup-dkml-windows_x86_64.ps1 new file mode 100644 index 00000000..bbbb463b --- /dev/null +++ b/.ci/dkml-compilers/pc/setup-dkml-windows_x86_64.ps1 @@ -0,0 +1,2781 @@ +# setup-dkml +# Short form: sd4 + +<# +.SYNOPSIS + +Setup Diskuv OCaml (DKML) compiler on a desktop PC. + +.DESCRIPTION + +Setup Diskuv OCaml (DKML) compiler on a desktop PC. + +.PARAMETER PC_PROJECT_DIR +Context variable for the project directory. Defaults to the current directory. + +.PARAMETER FDOPEN_OPAMEXE_BOOTSTRAP +Input variable. + +.PARAMETER CACHE_PREFIX +Input variable. + +.PARAMETER OCAML_COMPILER +Input variable. -DKML_COMPILER takes priority. If -DKML_COMPILER is not set and -OCAML_COMPILER is set, then the specified OCaml version tag of dkml-compiler (ex. 4.12.1) is used. + +.PARAMETER DKML_COMPILER +Input variable. Unspecified or blank is the latest from the default branch (main) of dkml-compiler. @repository@ is the latest from Opam. + +.PARAMETER SKIP_OPAM_MODIFICATIONS +Input variable. If true (the default is false) then the opam root and switches will not be created or modified. + +.PARAMETER SECONDARY_SWITCH +Input variable. If true then the secondary switch named 'two' is created. + +.PARAMETER PRIMARY_SWITCH_SKIP_INSTALL +Input variable. If true no dkml-base-compiler will be installed in the 'dkml' switch. + +.PARAMETER CONF_DKML_CROSS_TOOLCHAIN +Input variable. Unspecified or blank is the latest from the default branch (main) of conf-dkml-cross-toolchain. @repository@ is the latest from Opam. + +.PARAMETER DISKUV_OPAM_REPOSITORY +Input variable. Defaults to the value of -DEFAULT_DISKUV_OPAM_REPOSITORY_TAG (see below) + +.PARAMETER DKML_HOME +Input variables. If specified then DiskuvOCamlHome, DiskuvOCamlBinaryPaths and DiskuvOCamlDeploymentId will be set, in addition to the always-present DiskuvOCamlVarsVersion, DiskuvOCamlVersion +and DiskuvOCamlMSYS2Dir. + +# autogen from global_env_vars. +.PARAMETER DKML_VERSION +Environment variable. + +.PARAMETER DEFAULT_DISKUV_OPAM_REPOSITORY_TAG +Environment variable. + +.PARAMETER DEFAULT_DKML_COMPILER +Environment variable. + +.PARAMETER PIN_ASTRING +Environment variable. + +.PARAMETER PIN_BASE +Environment variable. + +.PARAMETER PIN_BASE64 +Environment variable. + +.PARAMETER PIN_BIGARRAY_COMPAT +Environment variable. + +.PARAMETER PIN_BOS +Environment variable. + +.PARAMETER PIN_CAMLP_STREAMS +Environment variable. + +.PARAMETER PIN_CHROME_TRACE +Environment variable. + +.PARAMETER PIN_CMDLINER +Environment variable. + +.PARAMETER PIN_CONF_DKML_SYS_OPAM +Environment variable. + +.PARAMETER PIN_CONF_PKG_CONFIG +Environment variable. + +.PARAMETER PIN_CONF_SQLITE3 +Environment variable. + +.PARAMETER PIN_CPPO +Environment variable. + +.PARAMETER PIN_CRUNCH +Environment variable. + +.PARAMETER PIN_CSEXP +Environment variable. + +.PARAMETER PIN_CSTRUCT +Environment variable. + +.PARAMETER PIN_CTYPES_FOREIGN +Environment variable. + +.PARAMETER PIN_CTYPES +Environment variable. + +.PARAMETER PIN_CUDF +Environment variable. + +.PARAMETER PIN_DIGESTIF +Environment variable. + +.PARAMETER PIN_DISKUVBOX +Environment variable. + +.PARAMETER PIN_DKML_APPS +Environment variable. + +.PARAMETER PIN_DKML_BASE_COMPILER +Environment variable. + +.PARAMETER PIN_DKML_BUILD_DESKTOP +Environment variable. + +.PARAMETER PIN_DKML_C_PROBE +Environment variable. + +.PARAMETER PIN_DKML_COMPILER_ENV +Environment variable. + +.PARAMETER PIN_DKML_COMPILER_SRC +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_COMMON_DESKTOP +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_COMMON_OPAM +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_COMMON_UNIXUTILS +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_OCAMLRUN +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_OPAM32 +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_OPAM64 +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_UNIXUTILS +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_STAGING_WITHDKML +Environment variable. + +.PARAMETER PIN_DKML_COMPONENT_XX_CONSOLE +Environment variable. + +.PARAMETER PIN_DKML_EXE_LIB +Environment variable. + +.PARAMETER PIN_DKML_EXE +Environment variable. + +.PARAMETER PIN_DKML_INSTALL_INSTALLER +Environment variable. + +.PARAMETER PIN_DKML_INSTALL_RUNNER +Environment variable. + +.PARAMETER PIN_DKML_INSTALL +Environment variable. + +.PARAMETER PIN_DKML_INSTALLER_OCAML_COMMON +Environment variable. + +.PARAMETER PIN_DKML_INSTALLER_OCAML_OFFLINE +Environment variable. + +.PARAMETER PIN_DKML_PACKAGE_CONSOLE +Environment variable. + +.PARAMETER PIN_DKML_RUNTIME_COMMON_NATIVE +Environment variable. + +.PARAMETER PIN_DKML_RUNTIME_COMMON +Environment variable. + +.PARAMETER PIN_DKML_RUNTIME_DISTRIBUTION +Environment variable. + +.PARAMETER PIN_DKML_RUNTIMELIB +Environment variable. + +.PARAMETER PIN_DKML_RUNTIMESCRIPTS +Environment variable. + +.PARAMETER PIN_DKML_WORKFLOWS +Environment variable. + +.PARAMETER PIN_DUNE_ACTION_PLUGIN +Environment variable. + +.PARAMETER PIN_DUNE_BUILD_INFO +Environment variable. + +.PARAMETER PIN_DUNE_CONFIGURATOR +Environment variable. + +.PARAMETER PIN_DUNE_GLOB +Environment variable. + +.PARAMETER PIN_DUNE_PRIVATE_LIBS +Environment variable. + +.PARAMETER PIN_DUNE_RPC_LWT +Environment variable. + +.PARAMETER PIN_DUNE_RPC +Environment variable. + +.PARAMETER PIN_DUNE_SITE +Environment variable. + +.PARAMETER PIN_DUNE +Environment variable. + +.PARAMETER PIN_DYN +Environment variable. + +.PARAMETER PIN_EITHER +Environment variable. + +.PARAMETER PIN_EQAF +Environment variable. + +.PARAMETER PIN_EXTLIB +Environment variable. + +.PARAMETER PIN_EZJSONM +Environment variable. + +.PARAMETER PIN_FEATHER +Environment variable. + +.PARAMETER PIN_FIBER +Environment variable. + +.PARAMETER PIN_FIX +Environment variable. + +.PARAMETER PIN_FMT +Environment variable. + +.PARAMETER PIN_FPATH +Environment variable. + +.PARAMETER PIN_GRAPHICS +Environment variable. + +.PARAMETER PIN_HEX +Environment variable. + +.PARAMETER PIN_INTEGERS +Environment variable. + +.PARAMETER PIN_JANE_STREET_HEADERS +Environment variable. + +.PARAMETER PIN_JINGOO +Environment variable. + +.PARAMETER PIN_JSONM +Environment variable. + +.PARAMETER PIN_JSONRPC +Environment variable. + +.PARAMETER PIN_JST_CONFIG +Environment variable. + +.PARAMETER PIN_LAMBDA_TERM +Environment variable. + +.PARAMETER PIN_LOGS +Environment variable. + +.PARAMETER PIN_LSP +Environment variable. + +.PARAMETER PIN_LWT +Environment variable. + +.PARAMETER PIN_LWT_REACT +Environment variable. + +.PARAMETER PIN_MCCS +Environment variable. + +.PARAMETER PIN_MDX +Environment variable. + +.PARAMETER PIN_MENHIR +Environment variable. + +.PARAMETER PIN_MENHIRLIB +Environment variable. + +.PARAMETER PIN_MENHIRSDK +Environment variable. + +.PARAMETER PIN_MERLIN_LIB +Environment variable. + +.PARAMETER PIN_METAPP +Environment variable. + +.PARAMETER PIN_METAQUOT +Environment variable. + +.PARAMETER PIN_MEW +Environment variable. + +.PARAMETER PIN_MEW_VI +Environment variable. + +.PARAMETER PIN_NUM +Environment variable. + +.PARAMETER PIN_OCAML_COMPILER_LIBS +Environment variable. + +.PARAMETER PIN_OCAML_LSP_SERVER +Environment variable. + +.PARAMETER PIN_OCAML_VERSION +Environment variable. + +.PARAMETER PIN_OCAML +Environment variable. + +.PARAMETER PIN_OCAMLBUILD +Environment variable. + +.PARAMETER PIN_OCAMLC_LOC +Environment variable. + +.PARAMETER PIN_OCAMLFIND +Environment variable. + +.PARAMETER PIN_OCAMLFORMAT_LIB +Environment variable. + +.PARAMETER PIN_OCAMLFORMAT_RPC_LIB +Environment variable. + +.PARAMETER PIN_OCAMLFORMAT +Environment variable. + +.PARAMETER PIN_OCP_INDENT +Environment variable. + +.PARAMETER PIN_OCPLIB_ENDIAN +Environment variable. + +.PARAMETER PIN_ODOC_PARSER +Environment variable. + +.PARAMETER PIN_ODOC +Environment variable. + +.PARAMETER PIN_ORDERING +Environment variable. + +.PARAMETER PIN_PARSEXP +Environment variable. + +.PARAMETER PIN_PP +Environment variable. + +.PARAMETER PIN_PPX_ASSERT +Environment variable. + +.PARAMETER PIN_PPX_BASE +Environment variable. + +.PARAMETER PIN_PPX_COLD +Environment variable. + +.PARAMETER PIN_PPX_COMPARE +Environment variable. + +.PARAMETER PIN_PPX_DERIVERS +Environment variable. + +.PARAMETER PIN_PPX_DERIVING +Environment variable. + +.PARAMETER PIN_PPX_ENUMERATE +Environment variable. + +.PARAMETER PIN_PPX_EXPECT +Environment variable. + +.PARAMETER PIN_PPX_GLOBALIZE +Environment variable. + +.PARAMETER PIN_PPX_HASH +Environment variable. + +.PARAMETER PIN_PPX_HERE +Environment variable. + +.PARAMETER PIN_PPX_IGNORE_INSTRUMENTATION +Environment variable. + +.PARAMETER PIN_PPX_INLINE_TEST +Environment variable. + +.PARAMETER PIN_PPX_OPTCOMP +Environment variable. + +.PARAMETER PIN_PPX_PIPEBANG +Environment variable. + +.PARAMETER PIN_PPX_SEXP_CONV +Environment variable. + +.PARAMETER PIN_PPX_YOJSON_CONV_LIB +Environment variable. + +.PARAMETER PIN_PPXLIB +Environment variable. + +.PARAMETER PIN_PTIME +Environment variable. + +.PARAMETER PIN_QRC +Environment variable. + +.PARAMETER PIN_RE +Environment variable. + +.PARAMETER PIN_REACT +Environment variable. + +.PARAMETER PIN_REFL +Environment variable. + +.PARAMETER PIN_RESULT +Environment variable. + +.PARAMETER PIN_RRESULT +Environment variable. + +.PARAMETER PIN_SEQ +Environment variable. + +.PARAMETER PIN_SEXPLIB +Environment variable. + +.PARAMETER PIN_SEXPLIB0 +Environment variable. + +.PARAMETER PIN_SHA +Environment variable. + +.PARAMETER PIN_SPAWN +Environment variable. + +.PARAMETER PIN_SQLITE3 +Environment variable. + +.PARAMETER PIN_STDCOMPAT +Environment variable. + +.PARAMETER PIN_STDIO +Environment variable. + +.PARAMETER PIN_STDLIB_SHIMS +Environment variable. + +.PARAMETER PIN_STDUNE +Environment variable. + +.PARAMETER PIN_TIME_NOW +Environment variable. + +.PARAMETER PIN_TOPKG +Environment variable. + +.PARAMETER PIN_TRAVERSE +Environment variable. + +.PARAMETER PIN_TRIE +Environment variable. + +.PARAMETER PIN_TSORT +Environment variable. + +.PARAMETER PIN_TYXML +Environment variable. + +.PARAMETER PIN_UCHAR +Environment variable. + +.PARAMETER PIN_UTOP +Environment variable. + +.PARAMETER PIN_UUCP +Environment variable. + +.PARAMETER PIN_UUIDM +Environment variable. + +.PARAMETER PIN_UUSEG +Environment variable. + +.PARAMETER PIN_UUTF +Environment variable. + +.PARAMETER PIN_WITH_DKML +Environment variable. + +.PARAMETER PIN_XDG +Environment variable. + +.PARAMETER PIN_YOJSON +Environment variable. + +.PARAMETER PIN_ZED +Environment variable. + +#> +[CmdletBinding()] +param ( + # Context variables + [Parameter(HelpMessage='Defaults to the current directory')] + [string] + $PC_PROJECT_DIR = $PWD, + + # Input variables + [string] + $FDOPEN_OPAMEXE_BOOTSTRAP = "false", + [string] + $CACHE_PREFIX = "v1", + [string] + $OCAML_COMPILER = "", + [string] + $DKML_COMPILER = "", + [string] + $SKIP_OPAM_MODIFICATIONS = "false", + [string] + $SECONDARY_SWITCH = "false", + [string] + $PRIMARY_SWITCH_SKIP_INSTALL = "false", + [string] + $CONF_DKML_CROSS_TOOLCHAIN = "@repository@", + [string] + $DISKUV_OPAM_REPOSITORY = "", + [string] + $DKML_HOME = "" + + # Conflicts with automatic variable $Verbose + # [Parameter()] + # [string] + # $VERBOSE = "false" + + # Environment variables (can be overridden on command line) + # autogen from global_env_vars. + ,[Parameter()] [string] $DKML_VERSION = "2.0.3" + ,[Parameter()] [string] $DEFAULT_DISKUV_OPAM_REPOSITORY_TAG = "2.0.3" + ,[Parameter()] [string] $DEFAULT_DKML_COMPILER = "2.0.3" + ,[Parameter()] [string] $PIN_ASTRING = "0.8.5" + ,[Parameter()] [string] $PIN_BASE = "v0.16.1" + ,[Parameter()] [string] $PIN_BASE64 = "3.5.1" + ,[Parameter()] [string] $PIN_BIGARRAY_COMPAT = "1.1.0" + ,[Parameter()] [string] $PIN_BOS = "0.2.1" + ,[Parameter()] [string] $PIN_CAMLP_STREAMS = "5.0.1" + ,[Parameter()] [string] $PIN_CHROME_TRACE = "3.10.0" + ,[Parameter()] [string] $PIN_CMDLINER = "1.2.0" + ,[Parameter()] [string] $PIN_CONF_DKML_SYS_OPAM = "1" + ,[Parameter()] [string] $PIN_CONF_PKG_CONFIG = "2+cpkgs" + ,[Parameter()] [string] $PIN_CONF_SQLITE3 = "3.1+cpkgs" + ,[Parameter()] [string] $PIN_CPPO = "1.6.9" + ,[Parameter()] [string] $PIN_CRUNCH = "3.3.1" + ,[Parameter()] [string] $PIN_CSEXP = "1.5.2" + ,[Parameter()] [string] $PIN_CSTRUCT = "6.2.0" + ,[Parameter()] [string] $PIN_CTYPES_FOREIGN = "0.19.2-windowssupport-r7" + ,[Parameter()] [string] $PIN_CTYPES = "0.19.2-windowssupport-r7" + ,[Parameter()] [string] $PIN_CUDF = "0.10" + ,[Parameter()] [string] $PIN_DIGESTIF = "1.1.4" + ,[Parameter()] [string] $PIN_DISKUVBOX = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_APPS = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_BASE_COMPILER = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_BUILD_DESKTOP = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_C_PROBE = "3.0.0" + ,[Parameter()] [string] $PIN_DKML_COMPILER_ENV = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPILER_SRC = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_COMMON_DESKTOP = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_COMMON_OPAM = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_COMMON_UNIXUTILS = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_OCAMLRUN = "4.14.0~v2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_OPAM32 = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_OPAM64 = "2.2.0~alpha0~20221228" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_UNIXUTILS = "0.2.0" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_STAGING_WITHDKML = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_COMPONENT_XX_CONSOLE = "0.1.1" + ,[Parameter()] [string] $PIN_DKML_EXE_LIB = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_EXE = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_INSTALL_INSTALLER = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_INSTALL_RUNNER = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_INSTALL = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_INSTALLER_OCAML_COMMON = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_INSTALLER_OCAML_OFFLINE = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_PACKAGE_CONSOLE = "0.5.1" + ,[Parameter()] [string] $PIN_DKML_RUNTIME_COMMON_NATIVE = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIME_COMMON = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIME_DISTRIBUTION = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIMELIB = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_RUNTIMESCRIPTS = "2.0.3" + ,[Parameter()] [string] $PIN_DKML_WORKFLOWS = "2.0.3" + ,[Parameter()] [string] $PIN_DUNE_ACTION_PLUGIN = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_BUILD_INFO = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_CONFIGURATOR = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_GLOB = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_PRIVATE_LIBS = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_RPC_LWT = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_RPC = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE_SITE = "3.8.3" + ,[Parameter()] [string] $PIN_DUNE = "3.8.3" + ,[Parameter()] [string] $PIN_DYN = "3.8.3" + ,[Parameter()] [string] $PIN_EITHER = "1.0.0" + ,[Parameter()] [string] $PIN_EQAF = "0.9" + ,[Parameter()] [string] $PIN_EXTLIB = "1.7.9" + ,[Parameter()] [string] $PIN_EZJSONM = "1.3.0" + ,[Parameter()] [string] $PIN_FEATHER = "0.3.0" + ,[Parameter()] [string] $PIN_FIBER = "3.7.0" + ,[Parameter()] [string] $PIN_FIX = "20230505" + ,[Parameter()] [string] $PIN_FMT = "0.9.0" + ,[Parameter()] [string] $PIN_FPATH = "0.7.3" + ,[Parameter()] [string] $PIN_GRAPHICS = "5.1.2" + ,[Parameter()] [string] $PIN_HEX = "1.5.0" + ,[Parameter()] [string] $PIN_INTEGERS = "0.7.0" + ,[Parameter()] [string] $PIN_JANE_STREET_HEADERS = "v0.16.0" + ,[Parameter()] [string] $PIN_JINGOO = "1.4.4" + ,[Parameter()] [string] $PIN_JSONM = "1.0.2" + ,[Parameter()] [string] $PIN_JSONRPC = "1.16.2" + ,[Parameter()] [string] $PIN_JST_CONFIG = "v0.16.0" + ,[Parameter()] [string] $PIN_LAMBDA_TERM = "3.3.1" + ,[Parameter()] [string] $PIN_LOGS = "0.7.0" + ,[Parameter()] [string] $PIN_LSP = "1.16.2" + ,[Parameter()] [string] $PIN_LWT = "5.6.1" + ,[Parameter()] [string] $PIN_LWT_REACT = "1.2.0" + ,[Parameter()] [string] $PIN_MCCS = "1.1+13" + ,[Parameter()] [string] $PIN_MDX = "2.3.0" + ,[Parameter()] [string] $PIN_MENHIR = "20230608" + ,[Parameter()] [string] $PIN_MENHIRLIB = "20230608" + ,[Parameter()] [string] $PIN_MENHIRSDK = "20230608" + ,[Parameter()] [string] $PIN_MERLIN_LIB = "4.9-414" + ,[Parameter()] [string] $PIN_METAPP = "0.4.4+win" + ,[Parameter()] [string] $PIN_METAQUOT = "0.5.2" + ,[Parameter()] [string] $PIN_MEW = "0.1.0" + ,[Parameter()] [string] $PIN_MEW_VI = "0.5.0" + ,[Parameter()] [string] $PIN_NUM = "1.4" + ,[Parameter()] [string] $PIN_OCAML_COMPILER_LIBS = "v0.12.4" + ,[Parameter()] [string] $PIN_OCAML_LSP_SERVER = "1.16.2" + ,[Parameter()] [string] $PIN_OCAML_VERSION = "3.6.1" + ,[Parameter()] [string] $PIN_OCAML = "4.14.0" + ,[Parameter()] [string] $PIN_OCAMLBUILD = "0.14.2+win+unix" + ,[Parameter()] [string] $PIN_OCAMLC_LOC = "3.8.3" + ,[Parameter()] [string] $PIN_OCAMLFIND = "1.9.5" + ,[Parameter()] [string] $PIN_OCAMLFORMAT_LIB = "0.25.1" + ,[Parameter()] [string] $PIN_OCAMLFORMAT_RPC_LIB = "0.25.1" + ,[Parameter()] [string] $PIN_OCAMLFORMAT = "0.25.1" + ,[Parameter()] [string] $PIN_OCP_INDENT = "1.8.2-windowssupport" + ,[Parameter()] [string] $PIN_OCPLIB_ENDIAN = "1.2" + ,[Parameter()] [string] $PIN_ODOC_PARSER = "2.0.0" + ,[Parameter()] [string] $PIN_ODOC = "2.2.0" + ,[Parameter()] [string] $PIN_ORDERING = "3.8.3" + ,[Parameter()] [string] $PIN_PARSEXP = "v0.16.0" + ,[Parameter()] [string] $PIN_PP = "1.1.2" + ,[Parameter()] [string] $PIN_PPX_ASSERT = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_BASE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_COLD = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_COMPARE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_DERIVERS = "1.2.1" + ,[Parameter()] [string] $PIN_PPX_DERIVING = "5.2.1" + ,[Parameter()] [string] $PIN_PPX_ENUMERATE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_EXPECT = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_GLOBALIZE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_HASH = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_HERE = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_IGNORE_INSTRUMENTATION = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_INLINE_TEST = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_OPTCOMP = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_PIPEBANG = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_SEXP_CONV = "v0.16.0" + ,[Parameter()] [string] $PIN_PPX_YOJSON_CONV_LIB = "v0.16.0" + ,[Parameter()] [string] $PIN_PPXLIB = "0.30.0" + ,[Parameter()] [string] $PIN_PTIME = "1.1.0" + ,[Parameter()] [string] $PIN_QRC = "0.1.1~dune" + ,[Parameter()] [string] $PIN_RE = "1.11.0" + ,[Parameter()] [string] $PIN_REACT = "1.2.2" + ,[Parameter()] [string] $PIN_REFL = "0.4.1" + ,[Parameter()] [string] $PIN_RESULT = "1.5" + ,[Parameter()] [string] $PIN_RRESULT = "0.7.0" + ,[Parameter()] [string] $PIN_SEQ = "base" + ,[Parameter()] [string] $PIN_SEXPLIB = "v0.16.0" + ,[Parameter()] [string] $PIN_SEXPLIB0 = "v0.16.0" + ,[Parameter()] [string] $PIN_SHA = "1.15.4" + ,[Parameter()] [string] $PIN_SPAWN = "v0.15.1" + ,[Parameter()] [string] $PIN_SQLITE3 = "5.1.0+msvc" + ,[Parameter()] [string] $PIN_STDCOMPAT = "19+optautoconf" + ,[Parameter()] [string] $PIN_STDIO = "v0.16.0" + ,[Parameter()] [string] $PIN_STDLIB_SHIMS = "0.3.0" + ,[Parameter()] [string] $PIN_STDUNE = "3.8.3" + ,[Parameter()] [string] $PIN_TIME_NOW = "v0.16.0" + ,[Parameter()] [string] $PIN_TOPKG = "1.0.7" + ,[Parameter()] [string] $PIN_TRAVERSE = "0.3.0" + ,[Parameter()] [string] $PIN_TRIE = "1.0.0" + ,[Parameter()] [string] $PIN_TSORT = "2.1.0" + ,[Parameter()] [string] $PIN_TYXML = "4.5.0" + ,[Parameter()] [string] $PIN_UCHAR = "0.0.2" + ,[Parameter()] [string] $PIN_UTOP = "2.13.1" + ,[Parameter()] [string] $PIN_UUCP = "15.0.0" + ,[Parameter()] [string] $PIN_UUIDM = "0.9.8" + ,[Parameter()] [string] $PIN_UUSEG = "15.0.0" + ,[Parameter()] [string] $PIN_UUTF = "1.0.3" + ,[Parameter()] [string] $PIN_WITH_DKML = "2.0.3" + ,[Parameter()] [string] $PIN_XDG = "3.9.0" + ,[Parameter()] [string] $PIN_YOJSON = "2.1.0" + ,[Parameter()] [string] $PIN_ZED = "3.2.2" +) + +$ErrorActionPreference = "Stop" + +# Reset environment so no conflicts with a parent Opam or OCaml system +if (Test-Path Env:OPAMROOT) { Remove-Item Env:OPAMROOT } +if (Test-Path Env:OPAMSWITCH) { Remove-Item Env:OPAMSWITCH } +if (Test-Path Env:OPAM_SWITCH_PREFIX) { Remove-Item Env:OPAM_SWITCH_PREFIX } +if (Test-Path Env:CAML_LD_LIBRARY_PATH) { Remove-Item Env:CAML_LD_LIBRARY_PATH } +if (Test-Path Env:OCAMLLIB) { Remove-Item Env:OCAMLLIB } +if (Test-Path Env:OCAML_TOPLEVEL_PATH) { Remove-Item Env:OCAML_TOPLEVEL_PATH } + +# Pushdown context variables +$env:PC_CI = 'true' +$env:PC_PROJECT_DIR = $PC_PROJECT_DIR + +# Pushdown input variables +$env:FDOPEN_OPAMEXE_BOOTSTRAP = $FDOPEN_OPAMEXE_BOOTSTRAP +$env:CACHE_PREFIX = $CACHE_PREFIX +$env:OCAML_COMPILER = $OCAML_COMPILER +$env:DKML_COMPILER = $DKML_COMPILER +$env:SKIP_OPAM_MODIFICATIONS = $SKIP_OPAM_MODIFICATIONS +$env:SECONDARY_SWITCH = $SECONDARY_SWITCH +$env:PRIMARY_SWITCH_SKIP_INSTALL = $PRIMARY_SWITCH_SKIP_INSTALL +$env:CONF_DKML_CROSS_TOOLCHAIN = $CONF_DKML_CROSS_TOOLCHAIN +$env:DISKUV_OPAM_REPOSITORY = $DISKUV_OPAM_REPOSITORY +$env:DKML_HOME = $DKML_HOME + +# Set matrix variables +# autogen from pc_vars. only windows_x86_64 +$env:dkml_host_os = "windows" +$env:opam_root_cacheable = "${env:PC_PROJECT_DIR}/.ci/o" +$env:abi_pattern = "win32-windows_x86_64" +$env:msys2_system = "CLANG64" +$env:msys2_packages = "mingw-w64-clang-x86_64-pkg-config" +$env:exe_ext = ".exe" +$env:bootstrap_opam_version = "2.2.0-alpha-20221228" +$env:opam_abi = "windows_x86_64" +$env:dkml_host_abi = "windows_x86_64" +$env:opam_root = "${env:PC_PROJECT_DIR}/.ci/o" +$env:vsstudio_hostarch = "x64" +$env:vsstudio_arch = "x64" + + +# Set environment variables +# autogen from global_env_vars. +$env:DKML_VERSION = $DKML_VERSION +$env:DEFAULT_DISKUV_OPAM_REPOSITORY_TAG = $DEFAULT_DISKUV_OPAM_REPOSITORY_TAG +$env:DEFAULT_DKML_COMPILER = $DEFAULT_DKML_COMPILER +$env:PIN_ASTRING = $PIN_ASTRING +$env:PIN_BASE = $PIN_BASE +$env:PIN_BASE64 = $PIN_BASE64 +$env:PIN_BIGARRAY_COMPAT = $PIN_BIGARRAY_COMPAT +$env:PIN_BOS = $PIN_BOS +$env:PIN_CAMLP_STREAMS = $PIN_CAMLP_STREAMS +$env:PIN_CHROME_TRACE = $PIN_CHROME_TRACE +$env:PIN_CMDLINER = $PIN_CMDLINER +$env:PIN_CONF_DKML_SYS_OPAM = $PIN_CONF_DKML_SYS_OPAM +$env:PIN_CONF_PKG_CONFIG = $PIN_CONF_PKG_CONFIG +$env:PIN_CONF_SQLITE3 = $PIN_CONF_SQLITE3 +$env:PIN_CPPO = $PIN_CPPO +$env:PIN_CRUNCH = $PIN_CRUNCH +$env:PIN_CSEXP = $PIN_CSEXP +$env:PIN_CSTRUCT = $PIN_CSTRUCT +$env:PIN_CTYPES_FOREIGN = $PIN_CTYPES_FOREIGN +$env:PIN_CTYPES = $PIN_CTYPES +$env:PIN_CUDF = $PIN_CUDF +$env:PIN_DIGESTIF = $PIN_DIGESTIF +$env:PIN_DISKUVBOX = $PIN_DISKUVBOX +$env:PIN_DKML_APPS = $PIN_DKML_APPS +$env:PIN_DKML_BASE_COMPILER = $PIN_DKML_BASE_COMPILER +$env:PIN_DKML_BUILD_DESKTOP = $PIN_DKML_BUILD_DESKTOP +$env:PIN_DKML_C_PROBE = $PIN_DKML_C_PROBE +$env:PIN_DKML_COMPILER_ENV = $PIN_DKML_COMPILER_ENV +$env:PIN_DKML_COMPILER_SRC = $PIN_DKML_COMPILER_SRC +$env:PIN_DKML_COMPONENT_COMMON_DESKTOP = $PIN_DKML_COMPONENT_COMMON_DESKTOP +$env:PIN_DKML_COMPONENT_COMMON_OPAM = $PIN_DKML_COMPONENT_COMMON_OPAM +$env:PIN_DKML_COMPONENT_COMMON_UNIXUTILS = $PIN_DKML_COMPONENT_COMMON_UNIXUTILS +$env:PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON = $PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON +$env:PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK = $PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK +$env:PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE = $PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE +$env:PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL = $PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL +$env:PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM = $PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM +$env:PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS = $PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS +$env:PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL = $PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL +$env:PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR = $PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR +$env:PIN_DKML_COMPONENT_STAGING_OCAMLRUN = $PIN_DKML_COMPONENT_STAGING_OCAMLRUN +$env:PIN_DKML_COMPONENT_STAGING_OPAM32 = $PIN_DKML_COMPONENT_STAGING_OPAM32 +$env:PIN_DKML_COMPONENT_STAGING_OPAM64 = $PIN_DKML_COMPONENT_STAGING_OPAM64 +$env:PIN_DKML_COMPONENT_STAGING_UNIXUTILS = $PIN_DKML_COMPONENT_STAGING_UNIXUTILS +$env:PIN_DKML_COMPONENT_STAGING_WITHDKML = $PIN_DKML_COMPONENT_STAGING_WITHDKML +$env:PIN_DKML_COMPONENT_XX_CONSOLE = $PIN_DKML_COMPONENT_XX_CONSOLE +$env:PIN_DKML_EXE_LIB = $PIN_DKML_EXE_LIB +$env:PIN_DKML_EXE = $PIN_DKML_EXE +$env:PIN_DKML_INSTALL_INSTALLER = $PIN_DKML_INSTALL_INSTALLER +$env:PIN_DKML_INSTALL_RUNNER = $PIN_DKML_INSTALL_RUNNER +$env:PIN_DKML_INSTALL = $PIN_DKML_INSTALL +$env:PIN_DKML_INSTALLER_OCAML_COMMON = $PIN_DKML_INSTALLER_OCAML_COMMON +$env:PIN_DKML_INSTALLER_OCAML_OFFLINE = $PIN_DKML_INSTALLER_OCAML_OFFLINE +$env:PIN_DKML_PACKAGE_CONSOLE = $PIN_DKML_PACKAGE_CONSOLE +$env:PIN_DKML_RUNTIME_COMMON_NATIVE = $PIN_DKML_RUNTIME_COMMON_NATIVE +$env:PIN_DKML_RUNTIME_COMMON = $PIN_DKML_RUNTIME_COMMON +$env:PIN_DKML_RUNTIME_DISTRIBUTION = $PIN_DKML_RUNTIME_DISTRIBUTION +$env:PIN_DKML_RUNTIMELIB = $PIN_DKML_RUNTIMELIB +$env:PIN_DKML_RUNTIMESCRIPTS = $PIN_DKML_RUNTIMESCRIPTS +$env:PIN_DKML_WORKFLOWS = $PIN_DKML_WORKFLOWS +$env:PIN_DUNE_ACTION_PLUGIN = $PIN_DUNE_ACTION_PLUGIN +$env:PIN_DUNE_BUILD_INFO = $PIN_DUNE_BUILD_INFO +$env:PIN_DUNE_CONFIGURATOR = $PIN_DUNE_CONFIGURATOR +$env:PIN_DUNE_GLOB = $PIN_DUNE_GLOB +$env:PIN_DUNE_PRIVATE_LIBS = $PIN_DUNE_PRIVATE_LIBS +$env:PIN_DUNE_RPC_LWT = $PIN_DUNE_RPC_LWT +$env:PIN_DUNE_RPC = $PIN_DUNE_RPC +$env:PIN_DUNE_SITE = $PIN_DUNE_SITE +$env:PIN_DUNE = $PIN_DUNE +$env:PIN_DYN = $PIN_DYN +$env:PIN_EITHER = $PIN_EITHER +$env:PIN_EQAF = $PIN_EQAF +$env:PIN_EXTLIB = $PIN_EXTLIB +$env:PIN_EZJSONM = $PIN_EZJSONM +$env:PIN_FEATHER = $PIN_FEATHER +$env:PIN_FIBER = $PIN_FIBER +$env:PIN_FIX = $PIN_FIX +$env:PIN_FMT = $PIN_FMT +$env:PIN_FPATH = $PIN_FPATH +$env:PIN_GRAPHICS = $PIN_GRAPHICS +$env:PIN_HEX = $PIN_HEX +$env:PIN_INTEGERS = $PIN_INTEGERS +$env:PIN_JANE_STREET_HEADERS = $PIN_JANE_STREET_HEADERS +$env:PIN_JINGOO = $PIN_JINGOO +$env:PIN_JSONM = $PIN_JSONM +$env:PIN_JSONRPC = $PIN_JSONRPC +$env:PIN_JST_CONFIG = $PIN_JST_CONFIG +$env:PIN_LAMBDA_TERM = $PIN_LAMBDA_TERM +$env:PIN_LOGS = $PIN_LOGS +$env:PIN_LSP = $PIN_LSP +$env:PIN_LWT = $PIN_LWT +$env:PIN_LWT_REACT = $PIN_LWT_REACT +$env:PIN_MCCS = $PIN_MCCS +$env:PIN_MDX = $PIN_MDX +$env:PIN_MENHIR = $PIN_MENHIR +$env:PIN_MENHIRLIB = $PIN_MENHIRLIB +$env:PIN_MENHIRSDK = $PIN_MENHIRSDK +$env:PIN_MERLIN_LIB = $PIN_MERLIN_LIB +$env:PIN_METAPP = $PIN_METAPP +$env:PIN_METAQUOT = $PIN_METAQUOT +$env:PIN_MEW = $PIN_MEW +$env:PIN_MEW_VI = $PIN_MEW_VI +$env:PIN_NUM = $PIN_NUM +$env:PIN_OCAML_COMPILER_LIBS = $PIN_OCAML_COMPILER_LIBS +$env:PIN_OCAML_LSP_SERVER = $PIN_OCAML_LSP_SERVER +$env:PIN_OCAML_VERSION = $PIN_OCAML_VERSION +$env:PIN_OCAML = $PIN_OCAML +$env:PIN_OCAMLBUILD = $PIN_OCAMLBUILD +$env:PIN_OCAMLC_LOC = $PIN_OCAMLC_LOC +$env:PIN_OCAMLFIND = $PIN_OCAMLFIND +$env:PIN_OCAMLFORMAT_LIB = $PIN_OCAMLFORMAT_LIB +$env:PIN_OCAMLFORMAT_RPC_LIB = $PIN_OCAMLFORMAT_RPC_LIB +$env:PIN_OCAMLFORMAT = $PIN_OCAMLFORMAT +$env:PIN_OCP_INDENT = $PIN_OCP_INDENT +$env:PIN_OCPLIB_ENDIAN = $PIN_OCPLIB_ENDIAN +$env:PIN_ODOC_PARSER = $PIN_ODOC_PARSER +$env:PIN_ODOC = $PIN_ODOC +$env:PIN_ORDERING = $PIN_ORDERING +$env:PIN_PARSEXP = $PIN_PARSEXP +$env:PIN_PP = $PIN_PP +$env:PIN_PPX_ASSERT = $PIN_PPX_ASSERT +$env:PIN_PPX_BASE = $PIN_PPX_BASE +$env:PIN_PPX_COLD = $PIN_PPX_COLD +$env:PIN_PPX_COMPARE = $PIN_PPX_COMPARE +$env:PIN_PPX_DERIVERS = $PIN_PPX_DERIVERS +$env:PIN_PPX_DERIVING = $PIN_PPX_DERIVING +$env:PIN_PPX_ENUMERATE = $PIN_PPX_ENUMERATE +$env:PIN_PPX_EXPECT = $PIN_PPX_EXPECT +$env:PIN_PPX_GLOBALIZE = $PIN_PPX_GLOBALIZE +$env:PIN_PPX_HASH = $PIN_PPX_HASH +$env:PIN_PPX_HERE = $PIN_PPX_HERE +$env:PIN_PPX_IGNORE_INSTRUMENTATION = $PIN_PPX_IGNORE_INSTRUMENTATION +$env:PIN_PPX_INLINE_TEST = $PIN_PPX_INLINE_TEST +$env:PIN_PPX_OPTCOMP = $PIN_PPX_OPTCOMP +$env:PIN_PPX_PIPEBANG = $PIN_PPX_PIPEBANG +$env:PIN_PPX_SEXP_CONV = $PIN_PPX_SEXP_CONV +$env:PIN_PPX_YOJSON_CONV_LIB = $PIN_PPX_YOJSON_CONV_LIB +$env:PIN_PPXLIB = $PIN_PPXLIB +$env:PIN_PTIME = $PIN_PTIME +$env:PIN_QRC = $PIN_QRC +$env:PIN_RE = $PIN_RE +$env:PIN_REACT = $PIN_REACT +$env:PIN_REFL = $PIN_REFL +$env:PIN_RESULT = $PIN_RESULT +$env:PIN_RRESULT = $PIN_RRESULT +$env:PIN_SEQ = $PIN_SEQ +$env:PIN_SEXPLIB = $PIN_SEXPLIB +$env:PIN_SEXPLIB0 = $PIN_SEXPLIB0 +$env:PIN_SHA = $PIN_SHA +$env:PIN_SPAWN = $PIN_SPAWN +$env:PIN_SQLITE3 = $PIN_SQLITE3 +$env:PIN_STDCOMPAT = $PIN_STDCOMPAT +$env:PIN_STDIO = $PIN_STDIO +$env:PIN_STDLIB_SHIMS = $PIN_STDLIB_SHIMS +$env:PIN_STDUNE = $PIN_STDUNE +$env:PIN_TIME_NOW = $PIN_TIME_NOW +$env:PIN_TOPKG = $PIN_TOPKG +$env:PIN_TRAVERSE = $PIN_TRAVERSE +$env:PIN_TRIE = $PIN_TRIE +$env:PIN_TSORT = $PIN_TSORT +$env:PIN_TYXML = $PIN_TYXML +$env:PIN_UCHAR = $PIN_UCHAR +$env:PIN_UTOP = $PIN_UTOP +$env:PIN_UUCP = $PIN_UUCP +$env:PIN_UUIDM = $PIN_UUIDM +$env:PIN_UUSEG = $PIN_UUSEG +$env:PIN_UUTF = $PIN_UUTF +$env:PIN_WITH_DKML = $PIN_WITH_DKML +$env:PIN_XDG = $PIN_XDG +$env:PIN_YOJSON = $PIN_YOJSON +$env:PIN_ZED = $PIN_ZED + +# https://patchwork.kernel.org/project/qemu-devel/patch/20211215073402.144286-17-thuth@redhat.com/ +$env:CHERE_INVOKING = "yes" # Preserve the current working directory +$env:MSYSTEM = $env:msys2_system # Start a 64 bit environment if CLANG64, etc. + +########################### before_script ############################### + +# Troubleshooting +If ( "${env:VERBOSE}" -eq "true" ) { Get-ChildItem 'env:' } + +# ----- +# MSYS2 +# ----- +# +# https://www.msys2.org/docs/ci/ +# https://patchwork.kernel.org/project/qemu-devel/patch/20211215073402.144286-17-thuth@redhat.com/ + +if ( Test-Path -Path msys64\usr\bin\pacman.exe ) { + Write-Host "Re-using MSYS2 from cache." +} +else { + Write-Host "Download the archive ..." + If ( !(Test-Path -Path msys64\var\cache ) ) { New-Item msys64\var\cache -ItemType Directory | Out-Null } + If ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) { Invoke-WebRequest "https://github.com/msys2/msys2-installer/releases/download/2022-09-04/msys2-base-x86_64-20220904.sfx.exe" -outfile "msys64\var\cache\msys2.exe" } + + Write-Host "Extract the archive ..." + msys64\var\cache\msys2.exe -y # Extract to .\msys64 + Remove-Item msys64\var\cache\msys2.exe # Delete the archive again + ((Get-Content -path msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path msys64\etc\post-install\07-pacman-key.post + msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf" + + Write-Host "Run for the first time ..." + msys64\usr\bin\bash -lc ' ' +} +Write-Host "Update MSYS2 ..." +msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update (in case any core packages are outdated) +msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update +if ("${env:CI}" -eq "true") { taskkill /F /FI "MODULES eq msys-2.0.dll" } # Only safe to kill MSYS2 in CI + +Write-Host "Install matrix, required and CI packages ..." +# Packages for GitLab CI: +# dos2unix (used to translate PowerShell written files below in this CI .yml into MSYS2 scripts) +msys64\usr\bin\bash -lc 'set -x; pacman -Sy --noconfirm --needed ${msys2_packages} wget make rsync diffutils patch unzip git tar xz dos2unix' + +Write-Host "Uninstall MSYS2 conflicting executables ..." +msys64\usr\bin\bash -lc 'rm -vf /usr/bin/link.exe' # link.exe interferes with MSVC's link.exe + +Write-Host "Installing VSSetup for the Get-VSSetupInstance function ..." +Install-Module VSSetup -Scope CurrentUser -Force + +Write-Host "Writing scripts ..." + +# POSIX and AWK scripts + +If ( !(Test-Path -Path.ci\sd4 ) ) { New-Item .ci\sd4 -ItemType Directory | Out-Null } + +$Content = @' +#!/bin/sh + +# ------------------------ Log Formatting ------------------------ + +TXT_SECTION="\e[94m" # bright blue +TXT_CLEAR="\e[0m" + +if [ "${GITLAB_CI:-}" = "true" ]; then + # https://docs.gitlab.com/ee/ci/jobs/#expand-and-collapse-job-log-sections + print_section_start() { + print_section_start_NAME=$1 + shift + printf "\e[0Ksection_start:%s:%s[collapsed=true]\r\e[0K" \ + "$(date +%s)" \ + "$print_section_start_NAME" + } + print_section_end() { + print_section_end_NAME=$1 + shift + printf "\e[0Ksection_end:%s:%s\r\e[0K\n" \ + "$(date +%s)" \ + "$print_section_end_NAME" + } +elif [ -n "${GITHUB_ENV:-}" ]; then + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines + print_section_start() { + print_section_start_NAME=$1 + shift + printf "::group::" + } + print_section_end() { + print_section_end_NAME=$1 + shift + printf "::endgroup::\n" + } +else + print_section_start() { + print_section_start_NAME=$1 + shift + } + print_section_end() { + print_section_end_NAME=$1 + shift + } +fi + +section_begin() { + # https://docs.gitlab.com/ee/ci/yaml/script.html#add-color-codes-to-script-output + section_NAME=$1 + shift + section_HEADER=$1 + shift + print_section_start "$section_NAME" + printf "${TXT_SECTION}%s${TXT_CLEAR}\n" "$section_HEADER" +} + +section_end() { + section_NAME=$1 + shift + print_section_end "$section_NAME" +} + +# ------------------- Other Functions ----------------- + +transfer_dir() { + transfer_dir_SRC=$1 + shift + transfer_dir_DST=$1 + shift + # Remove the destination directory completely, but make sure the parent of the + # destination directory exists so `mv` will work + install -d "$transfer_dir_DST" + rm -rf "$transfer_dir_DST" + # Move + mv "$transfer_dir_SRC" "$transfer_dir_DST" +} + +# Set TEMP variable which is used, among other things, for OCaml's +# [Filename.temp_dir_name] on Win32, and by with-dkml.exe on Windows +export_temp_for_windows() { + if [ -x /usr/bin/cygpath ]; then + if [ -n "${RUNNER_TEMP:-}" ]; then + # GitHub Actions + TEMP=$(cygpath -am "$RUNNER_TEMP") + else + # GitLab CI/CD or desktop + install -d .ci/tmp + TEMP=$(cygpath -am ".ci/tmp") + fi + export TEMP + fi +} + +# Fixup opam_root on Windows to be mixed case. +# On input the following variables must be present: +# - opam_root +# - opam_root_cacheable +# On output the input variables will be modified _and_ the +# following variables will be available: +# - original_opam_root +# - original_opam_root_cacheable +# - unix_opam_root +# - unix_opam_root_cacheable +fixup_opam_root() { + # shellcheck disable=SC2034 + original_opam_root=$opam_root + # shellcheck disable=SC2034 + original_opam_root_cacheable=$opam_root_cacheable + if [ -x /usr/bin/cygpath ]; then + opam_root=$(/usr/bin/cygpath -m "$opam_root") + opam_root_cacheable=$(/usr/bin/cygpath -m "$opam_root_cacheable") + unix_opam_root=$(/usr/bin/cygpath -u "$opam_root") + unix_opam_root_cacheable=$(/usr/bin/cygpath -u "$opam_root_cacheable") + else + # shellcheck disable=SC2034 + unix_opam_root=$opam_root + # shellcheck disable=SC2034 + unix_opam_root_cacheable=$opam_root_cacheable + fi +} +'@ +Set-Content -Path ".ci\sd4\common-values.sh" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/common-values.sh' + + +$Content = @' +#!/bin/sh + +# ================ +# checkout-code.sh +# ================ +# +# Checkouts all of the git source code. +# +# This should be done outside of +# dockcross (used by Linux) since a Docker-in-Docker container can have +# difficulties doing a git checkout (the Git credentials for any private +# repositories are likely not present). We don't care about any private +# repositories for DKML but any code that extends this (ex. DKSDK) may +# need to use private repositories. + +set -euf + +setup_WORKSPACE_VARNAME=$1 +shift +setup_WORKSPACE=$1 +shift + +if [ -x /usr/bin/cygpath ]; then + setup_WORKSPACE=$(/usr/bin/cygpath -au "$setup_WORKSPACE") +fi + +# ------------------------ Functions ------------------------ + +# shellcheck source=./common-values.sh +. .ci/sd4/common-values.sh + +# Disable automatic garbage collection +git_disable_gc() { + git_disable_gc_NAME=$1 + shift + git -C ".ci/sd4/g/$git_disable_gc_NAME" config --local gc.auto 0 +} + +# Mimic the behavior of GitHub's actions/checkout@v3 +# - the plus symbol in 'git fetch ... origin +REF:refs/tags/v0.0' overrides any existing REF +git_checkout() { + git_checkout_NAME=$1 + shift + git_checkout_URL=$1 + shift + git_checkout_REF=$1 + shift + + if [ -e ".ci/sd4/g/$git_checkout_NAME" ]; then + git_disable_gc "$git_checkout_NAME" + git -C ".ci/sd4/g/$git_checkout_NAME" remote set-url origin "$git_checkout_URL" + git -C ".ci/sd4/g/$git_checkout_NAME" fetch --no-tags --progress --no-recurse-submodules --depth=1 origin "+${git_checkout_REF}:refs/tags/v0.0" + else + install -d ".ci/sd4/g/$git_checkout_NAME" + git -C ".ci/sd4/g/$git_checkout_NAME" -c init.defaultBranch=main init + git_disable_gc "$git_checkout_NAME" + git -C ".ci/sd4/g/$git_checkout_NAME" remote add origin "$git_checkout_URL" + git -C ".ci/sd4/g/$git_checkout_NAME" fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin "+${git_checkout_REF}:refs/tags/v0.0" + fi + git -C ".ci/sd4/g/$git_checkout_NAME" -c advice.detachedHead=false checkout --progress --force refs/tags/v0.0 + git -C ".ci/sd4/g/$git_checkout_NAME" log -1 --format='%H' +} + +# --------------------------------------------------------------------- + +section_begin checkout-info "Summary: code checkout" + +# shellcheck disable=SC2154 +echo " +================ +checkout-code.sh +================ +. +--------- +Arguments +--------- +WORKSPACE_VARNAME=$setup_WORKSPACE_VARNAME +WORKSPACE=$setup_WORKSPACE +. +------ +Inputs +------ +VERBOSE=${VERBOSE:-} +. +------ +Matrix +------ +dkml_host_abi=$dkml_host_abi +. +" + +section_end checkout-info + +install -d .ci/sd4/g + +# dkml-runtime-distribution + +# For 'Diagnose Visual Studio environment variables (Windows)' we need dkml-runtime-distribution +# so that 'Import-Module Machine' and 'Get-VSSetupInstance' can be run. +# The version doesn't matter too much, as long as it has a functioning Get-VSSetupInstance +# that supports the Visual Studio versions of the latest GitLab CI and GitHub Actions machines. +# commit 4d6f1bfc3510c55ba4273cb240e43727854b5718 = WinSDK 19041 and VS 14.29 +case "$dkml_host_abi" in +windows_*) + section_begin checkout-dkml-runtime-distribution 'Checkout dkml-runtime-distribution' + git_checkout dkml-runtime-distribution https://github.com/diskuv/dkml-runtime-distribution.git "4d6f1bfc3510c55ba4273cb240e43727854b5718" + section_end checkout-dkml-runtime-distribution + ;; +esac + +'@ +Set-Content -Path ".ci\sd4\run-checkout-code.sh" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/run-checkout-code.sh' + + +$Content = @' +#!/bin/sh +set -euf + +# Constants +SHA512_DEVNULL='cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' + +setup_WORKSPACE_VARNAME=$1 +shift +setup_WORKSPACE=$1 +shift + +if [ -x /usr/bin/cygpath ]; then + setup_WORKSPACE=$(/usr/bin/cygpath -au "$setup_WORKSPACE") +fi + +# ------------------ Variables and functions ------------------------ + +# shellcheck source=./common-values.sh +. .ci/sd4/common-values.sh + +if [ "${VERBOSE:-}" = "true" ]; then + do_tar_rf() { + tar rvf "$@" + } +else + do_tar_rf() { + tar rf "$@" + } +fi + +# Make the standard input work as an OCaml string. +# This currently only escapes backslashes and double quotes. +escape_arg_as_ocaml_string() { + escape_arg_as_ocaml_string_ARG=$1 + shift + printf "%s" "$escape_arg_as_ocaml_string_ARG" | sed 's#\\#\\\\#g; s#"#\\"#g;' +} + +# Fixup opam_root on Windows to be mixed case. Set original_* and unix_* as well. +fixup_opam_root + +# Set TEMP variable for Windows +export_temp_for_windows + +# Load VS studio environment +if [ -e .ci/sd4/vsenv.sh ]; then + # shellcheck disable=SC1091 + . .ci/sd4/vsenv.sh +fi + +# ------------------------------------------------------------------- + +section_begin setup-info "Summary: setup-dkml" + +SKIP_OPAM_MODIFICATIONS=${SKIP_OPAM_MODIFICATIONS:-false} # default is false + +# shellcheck disable=SC2154 +echo " +============= +setup-dkml.sh +============= +. +--------- +Arguments +--------- +WORKSPACE_VARNAME=$setup_WORKSPACE_VARNAME +WORKSPACE=$setup_WORKSPACE +. +------ +Inputs +------ +FDOPEN_OPAMEXE_BOOTSTRAP=${FDOPEN_OPAMEXE_BOOTSTRAP:-} +DISKUV_OPAM_REPOSITORY=${DISKUV_OPAM_REPOSITORY:-} +DKML_COMPILER=${DKML_COMPILER:-} +OCAML_COMPILER=${OCAML_COMPILER:-} +CONF_DKML_CROSS_TOOLCHAIN=${CONF_DKML_CROSS_TOOLCHAIN:-} +SKIP_OPAM_MODIFICATIONS=${SKIP_OPAM_MODIFICATIONS:-} +SECONDARY_SWITCH=${SECONDARY_SWITCH:-} +PRIMARY_SWITCH_SKIP_INSTALL=${PRIMARY_SWITCH_SKIP_INSTALL:-} +MANYLINUX=${MANYLINUX:-} +DKML_HOME=${DKML_HOME:-} +VERBOSE=${VERBOSE:-} +. +------------------- +Generated Constants +------------------- +DKML_VERSION=$DKML_VERSION +DEFAULT_DISKUV_OPAM_REPOSITORY_TAG=$DEFAULT_DISKUV_OPAM_REPOSITORY_TAG +DEFAULT_DKML_COMPILER=$DEFAULT_DKML_COMPILER +. +------ +Matrix +------ +dkml_host_abi=$dkml_host_abi +bootstrap_opam_version=$bootstrap_opam_version +abi_pattern=$abi_pattern +opam_root=${opam_root} +opam_root_cacheable=${opam_root_cacheable} +original_opam_root=${original_opam_root} +original_opam_root_cacheable=${original_opam_root_cacheable} +unix_opam_root=${unix_opam_root} +unix_opam_root_cacheable=${unix_opam_root_cacheable} +dockcross_image=${dockcross_image:-} +dockcross_image_custom_prefix=${dockcross_image_custom_prefix:-} +dockcross_run_extra_args=${dockcross_run_extra_args:-} +docker_runner=${docker_runner:-} +in_docker=${in_docker:-} +ocaml_options=${ocaml_options:-} +. +---- +Pins +---- +" +set | grep ^PIN_ +echo ". +" +case "$dkml_host_abi" in +windows_*) + # shellcheck disable=SC2153 + echo " +------------- +Visual Studio +------------- +VS_DIR=$VS_DIR +VS_VCVARSVER=$VS_VCVARSVER +VS_WINSDKVER=$VS_WINSDKVER +VS_MSVSPREFERENCE=$VS_MSVSPREFERENCE +VS_CMAKEGENERATOR=$VS_CMAKEGENERATOR +. +" + ;; +esac +section_end setup-info + +do_bootstrap() { + # Bootstrap from historical release + runit_BOOTSTRAPPED=0 + + # Bootstrap opam from fdopen (Windows) + if [ "$runit_BOOTSTRAPPED" = 0 ] && [ "${FDOPEN_OPAMEXE_BOOTSTRAP:-}" = "true" ]; then + if [ -e .ci/sd4/opam64/bin/opam.exe ] && [ -e .ci/sd4/opam64/bin/opam-installer.exe ]; then + runit_BOOTSTRAPPED=1 + else + case "$dkml_host_abi" in + windows_*) + echo 'Bootstrap opam from fdopen (Windows) ...' + install -d .ci/sd4/bs/bin + wget -O "$setup_WORKSPACE"/.ci/sd4/opam64.tar.xz https://github.com/fdopen/opam-repository-mingw/releases/download/0.0.0.2/opam64.tar.xz + + # this stalls: tar xvCfJ "$setup_WORKSPACE"/.ci/sd4 "$setup_WORKSPACE"/.ci/sd4/opam64.tar.xz + xz -v -d "$setup_WORKSPACE"/.ci/sd4/opam64.tar.xz + tar xvCf .ci/sd4 .ci/sd4/opam64.tar + + rm -rf "$setup_WORKSPACE"/.ci/sd4/bs/bin/Opam.Runtime.amd64 + mv -v "$setup_WORKSPACE"/.ci/sd4/opam64/bin/Opam.Runtime.amd64/ "$setup_WORKSPACE"/.ci/sd4/bs/bin/ + mv -v "$setup_WORKSPACE"/.ci/sd4/opam64/bin/opam.exe "$setup_WORKSPACE"/.ci/sd4/bs/bin/ + mv -v "$setup_WORKSPACE"/.ci/sd4/opam64/bin/opam-installer.exe "$setup_WORKSPACE"/.ci/sd4/bs/bin/ + + # diagnostics + ldd "$setup_WORKSPACE"/.ci/sd4/bs/bin/opam.exe + ldd "$setup_WORKSPACE"/.ci/sd4/bs/bin/opam-installer.exe + + runit_BOOTSTRAPPED=1 + ;; + esac + fi + fi + + # Bootstrap from historical release + if [ "$runit_BOOTSTRAPPED" = 0 ] && [ "$bootstrap_opam_version" != "os" ]; then + install -d .ci/sd4/bs + cd .ci/sd4/bs + + if [ ! -e version ] || [ "$(cat version)" != "$bootstrap_opam_version" ]; then + echo 'Bootstrap opam from historical release (non-Windows; Windows non-fdopen) ...' + if command -v curl > /dev/null 2> /dev/null; then + curl -L -o opam.tar.gz "https://github.com/diskuv/dkml-component-opam/releases/download/v${bootstrap_opam_version}/dkml-component-staging-opam.tar.gz" + else + wget -O opam.tar.gz "https://github.com/diskuv/dkml-component-opam/releases/download/v${bootstrap_opam_version}/dkml-component-staging-opam.tar.gz" + fi + tar tvfz opam.tar.gz + tar xfz opam.tar.gz "./staging-files/${dkml_host_abi}/" + rm -rf bin/ + mv "staging-files/${dkml_host_abi}/bin" . + rm -rf "${abi_pattern}" + printf "%s" "${bootstrap_opam_version}" >version + fi + + rm -f opam.tar.gz + cd ../../.. + + runit_BOOTSTRAPPED=1 + fi + + # Bootstrap from package manager or GitHub ocaml/opam release + case "$runit_BOOTSTRAPPED,$bootstrap_opam_version,$dkml_host_abi" in + 0,os,darwin_*) + if ! command -v opam; then + echo 'Bootstrap opam from package manager (macOS) ...' + brew install gpatch + brew install opam + fi + runit_BOOTSTRAPPED=1 + ;; + 0,os,linux_x86) + if [ ! -x .ci/sd4/bs/bin/opam ]; then + echo 'Bootstrap opam from GitHub ocaml/opam release (Linux x86) ...' + install -d .ci/sd4/bs/bin + if command -v curl > /dev/null 2> /dev/null; then + curl -L -o .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-i686-linux + else + wget -O .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-i686-linux + fi + sha512_check=$(openssl sha512 2>&1 /dev/null | cut -f 2 -d ' ') + check="85a480d60e09a7d37fa0d0434ed97a3187434772ceb4e7e8faa5b06bc18423d004af3ad5849c7d35e72dca155103257fd6b1178872df8291583929eb8f884b6a" + test "$sha512" = "$check" + chmod +x .ci/sd4/bs/bin/opam.tmp + mv .ci/sd4/bs/bin/opam.tmp .ci/sd4/bs/bin/opam + else + echo "openssl 512 option unsupported." + exit 61 + fi + fi + runit_BOOTSTRAPPED=1 + ;; + 0,os,linux_x86_64) + if [ ! -x .ci/sd4/bs/bin/opam ]; then + echo 'Bootstrap opam from GitHub ocaml/opam release (Linux x86_64) ...' + install -d .ci/sd4/bs/bin + if command -v curl > /dev/null 2> /dev/null; then + curl -L -o .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-x86_64-linux + else + wget -O .ci/sd4/bs/bin/opam.tmp https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-x86_64-linux + fi + sha512_check=$(openssl sha512 2>&1 /dev/null | cut -f 2 -d ' ') + check="c0657ecbd4dc212587a4da70c5ff0402df95d148867be0e1eb1be8863a2851015f191437c3c99b7c2b153fcaa56cac99169c76ec94c5787750d7a59cd1fbb68b" + test "$sha512" = "$check" + chmod +x .ci/sd4/bs/bin/opam.tmp + mv .ci/sd4/bs/bin/opam.tmp .ci/sd4/bs/bin/opam + else + echo "openssl 512 option unsupported." + exit 61 + fi + fi + runit_BOOTSTRAPPED=1 + ;; + esac +} +section_begin bootstrap-opam 'Bootstrap opam' +do_bootstrap +section_end bootstrap-opam + +# Start environment distribution tarball +# We use .tar rather than .tar.gz/.tar.bz2 because we can repeatedly add to an uncompressed .tar. But we need to +# start with an empty tarball since some tar programs will only add ('tar rf xyz.tar') to an existing .tar. +install -d .ci/sd4/dist +tar cf .ci/sd4/dist/run-with-env.tar -T /dev/null + +do_get_dockcross() { + if [ -n "${dockcross_image:-}" ]; then + # The dockcross script is super-slow + section_begin get-dockcross 'Get dockcross binary (ManyLinux)' + install -d .ci/sd4 + # shellcheck disable=SC2086 + docker run ${dockcross_run_extra_args:-} --rm "${dockcross_image_custom_prefix:-}${dockcross_image:-}" >.ci/sd4/dockcross.gen + + # PROBLEM 1 + # --------- + # Super-annoying stderr output from dockcross at line: + # tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti + # When there is no tty, get: + # tty: ignoring all arguments + # not a tty + # So replace 'tty -s &&' with 'false &&' + sed 's/tty -s &&/false \&\&/' .ci/sd4/dockcross.gen >.ci/sd4/dockcross-real + rm -f .ci/sd4/dockcross.gen + chmod +x .ci/sd4/dockcross-real + + # PROBLEM 2 + # --------- + # By default dockcross for ManyLinux will chown -R all python packages; super-slow (~10 seconds)! + # Confer: https://github.com/dockcross/dockcross/blob/master/manylinux-common/pre_exec.sh + # That kills speed for any repetitive dockcross invocation. + # + # BUT it is unnecessary to chown -R when the current user is root, because inside the Docker container + # the files are already root! + # + # The chown -R (within pre_exec.sh) is not run when the user ids are not passed in. + # Confer: https://github.com/dockcross/dockcross/blob/96d87416f639af0204bdd42553e4b99315ca8476/imagefiles/entrypoint.sh#L21-L53 + # + # So explicitly call the entrypoint if root! + if echo "${dockcross_run_extra_args:-}" | grep -q linux/386; then + # https://github.com/dockcross/dockcross/blob/master/linux-x86/linux32-entrypoint.sh + # But only when `--platform linux/386` because the container image may be overridden. + dockcross_entrypoint=/dockcross/linux32-entrypoint.sh + else + dockcross_entrypoint=/dockcross/entrypoint.sh + fi + cat > .ci/sd4/dockcross <&2 "Missing functionality (\${f}) (in cygwin)." ; exit 1 ; } ; + done ; + HOST_PWD="\$( cygpath -w "\$( readlink -f "\$( pwd ;)" ; )" ; )" ; + else + HOST_PWD=\$PWD + [ -L \$HOST_PWD ] && HOST_PWD=\$(readlink \$HOST_PWD) + fi + + # ---------- End of dockcross script snippet ------- + + # Handle: dockcross --args "-v X:Y --platform P" + ARGS= + if [ "\$#" -ge 1 ] && [ "\$1" = "--args" ]; then + shift + ARGS=\$1 + shift + fi + + # Directly invoke entrypoint + exec docker run --entrypoint /bin/bash \ + --rm \ + \${ARGS:-} \ + -v "\$HOST_PWD":/work \ + ${dockcross_image_custom_prefix:-}${dockcross_image:-} ${dockcross_entrypoint} "\$@" +else + HERE=\$(dirname "\$0") + HERE=\$(cd "\$HERE" && pwd) + exec "\$HERE/dockcross-real" "\$@" +fi +EOF + chmod +x .ci/sd4/dockcross + + # Bundle for consumers of setup-dkml.yml + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/dockcross .ci/sd4/dockcross-real + + section_end get-dockcross + fi +} +do_get_dockcross + +if [ -n "${dockcross_image:-}" ]; then + # rsync needs to be available, even after Docker container disappears + if [ ! -e .ci/sd4/bs/bin/rsync ]; then + section_begin get-opam-prereqs-in-dockcross 'Get Opam prerequisites (ManyLinux)' + install -d .ci/sd4/bs/bin + # Install rsync with 'yum' (ManyLinux) or 'apt' (dockcross/linux-x64, etc.) + # if not present. + # shellcheck disable=SC2016 + .ci/sd4/dockcross --args "${dockcross_run_extra_args:-}" sh -c 'if ! command -v rsync; then if command -v yum; then sudo yum install -y rsync; else sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y rsync; fi; fi && install $(command -v rsync) .ci/sd4/bs/bin' + section_end get-opam-prereqs-in-dockcross + fi +fi + +# Opam prerequisites for using opam (not for installing opam) + +{ + if [ -n "${docker_runner:-}" ]; then + # rsync needs to be available, even after Docker container disappears + if [ ! -e .ci/sd4/bs/bin/rsync.deps ]; then + section_begin get-opam-prereqs-in-docker 'Get Opam prerequisites (Linux Docker)' + install -d .ci/sd4/bs/bin + ${docker_runner} sh -c ' + apt-get update -qq -o=Dpkg::Use-Pty=0 && + apt-get install -qq -o=Dpkg::Use-Pty=0 -y rsync && + ldd /usr/bin/rsync && + ls -l /lib/i386-linux-gnu/libpopt.so.0 /lib/i386-linux-gnu/libacl.so.1 /lib/i386-linux-gnu/libattr.so.1 && + tar cCfhz / /work/.ci/sd4/bs/bin/deps.tar.gz /usr/bin/rsync /lib/i386-linux-gnu/libpopt.so.0 + ' + touch .ci/sd4/bs/bin/rsync.deps + section_end get-opam-prereqs-in-docker + fi + fi + + # Bundle Opam prerequisites (ManyLinux or Linux Docker) + if [ -n "${docker_runner:-}" ] || [ -n "${dockcross_image:-}" ]; then + # Bundle for consumers of setup-dkml.yml + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/bs/bin/rsync + fi +} + +# Get Opam Cache +do_get_opam_cache() { + if [ "$unix_opam_root_cacheable" = "$unix_opam_root" ]; then return; fi + if [ ! -e "$unix_opam_root_cacheable" ]; then return; fi + section_begin get-opam-cache "Transferring Opam cache to $original_opam_root_cacheable" + echo Starting transfer # need some output or GitLab CI will not display the section duration + transfer_dir "$unix_opam_root_cacheable" "$unix_opam_root" + echo Finished transfer + section_end get-opam-cache +} +do_get_opam_cache + +# Setup Opam + +do_write_opam_scripts() { + case "${FDOPEN_OPAMEXE_BOOTSTRAP:-},$dkml_host_abi" in + true,windows_*) + # With fdopen's opam.exe, 'os-distribution = "cygwinports"'. But native Windows opam.exe has 'os-distribution = "win32"'. + # But on Windows we always want MSYS2 or native Windows libraries, not Cygwin. If cygwinports then + # code like https://github.com/ocaml/opam-repository/blob/08cbb8258bd4bf30cd6f307c958911a29d537b54/packages/conf-pkg-config/conf-pkg-config.2/opam#L36 + # will fail. So always set 'os-distribution = "win32"' on Windows. + PATCH_OS_DISTRIBUTION_WIN32=true + # With fdopen's opam.exe, no 'exe = ".exe"' is set because Cygwin does not need file extensions. + # Native Windows requires a .exe extension. + PATCH_EXE_WIN32=true + ;; + *) + PATCH_OS_DISTRIBUTION_WIN32=false + PATCH_EXE_WIN32=false + ;; + esac + + # --------------------- + # Empty opam repository + # --------------------- + + install -d .ci/sd4/eor + cat >.ci/sd4/eor/repo <.ci/sd4/troubleshoot-opam.sh </dev/null >/dev/null; then + FINDARGS="-mmin -240" # is -mmin supported? BSD (incl. macOS), MSYS2, GNU +else + FINDARGS="-mtime -1" # use 1 day instead. Solaris +fi +printf "\n\n========= [START OF TROUBLESHOOTING] ===========\n\n" >&2 +find "\$OPAMROOT"/log -mindepth 1 -maxdepth 1 \$FINDARGS -name "*.out" ! -name "log-*.out" ! -name "ocaml-variants-*.out" | while read -r dump_on_error_LOG; do + dump_on_error_BLOG=\$(basename "\$dump_on_error_LOG") + printf "\n\n========= [TROUBLESHOOTING] %s ===========\n\n" "\$dump_on_error_BLOG" >&2 + awk -v BLOG="\$dump_on_error_BLOG" '{print "[" BLOG "]", \$0}' "\$dump_on_error_LOG" >&2 +done +printf "\nScroll up to see the [TROUBLESHOOTING] logs that begin at the [START OF TROUBLESHOOTING] line\n" >&2 +EOF + + chmod +x .ci/sd4/troubleshoot-opam.sh + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/troubleshoot-opam.sh + + # --------------- + # Create Opam support scripts (not needed for all platforms) + # The PATH to find opam must work internally in setup-dkml.yml (sd4/bs/bin) and + # by consumers of setup-dkml.yml (sd4/opamexe) + # --------------- + + USER_ID=$(id -u) + GROUP_ID=$(id -g) + USER_NAME=$(id -un) + GROUP_NAME=$(id -gn) + + case "${opam_root}" in + /* | ?:*) # /a/b/c or C:\Windows + validate_supports_docker() { + echo "Docker only supported with relative paths for the opam root, not: ${opam_root}" >&2 + exit 3 + } + ;; + *) # relative path + validate_supports_docker() { + true + } + cat >.ci/sd4/run-in-docker <&2 +set +e +"\$prog" "\$@" +exitcode=\$? +if [ \$troubleshooting = 1 ] && [ \$prog = opam ]; then + [ \$exitcode = 0 ] || "/work/.ci/sd4/troubleshoot-opam.sh" \$OPAMROOT +fi +exit \$exitcode +EOF + chmod +x .ci/sd4/run-in-docker + ;; + esac + + cat >.ci/sd4/deescalate <.ci/sd4/run-with-env <&2 + cat .ci/sd4/run-in-docker >&2 + echo '___________________' >&2 + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/run-with-env .ci/sd4/run-in-docker .ci/sd4/edr + + elif [ -n "${docker_runner:-}" ]; then + + cat >.ci/sd4/run-with-env <&2 + cat .ci/sd4/run-in-docker >&2 + echo '________________________' >&2 + echo '__ deescalate __' >&2 + cat .ci/sd4/deescalate >&2 + echo '________________' >&2 + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/run-with-env .ci/sd4/run-in-docker .ci/sd4/deescalate + + else + + cat >.ci/sd4/run-with-env <&2 +set +e +"\$prog" "\$@" +exitcode=\$? +if [ \$troubleshooting = 1 ] && [ \$prog = opam ]; then + [ \$exitcode = 0 ] || "\${PROJECT_DIR}/.ci/sd4/troubleshoot-opam.sh" \$OPAMROOT +fi +exit \$exitcode +EOF + chmod +x .ci/sd4/run-with-env + + # Bundle for consumers of setup-dkml.yml + do_tar_rf .ci/sd4/dist/run-with-env.tar .ci/sd4/run-with-env + + fi + echo '__ run-with-env __' >&2 + cat .ci/sd4/run-with-env >&2 + echo '__________________' >&2 + + # ------ + # cmdrun + # ------ + + install -d .ci/sd4/opamrun + cat >.ci/sd4/opamrun/cmdrun <.ci/sd4/opamrun/opamrun <>"$GITHUB_PATH" + # Special case: GITHUB_PATH does not influence msys2.CMD of msys2/setup-msys2@v2, so place in real MSYS2 PATH + if [ -n "${MSYSTEM:-}" ]; then + install -d /usr/local/bin + install .ci/sd4/opamrun/opamrun /usr/local/bin/opamrun + fi +fi + +# Place opamrun in the immediate PATH +PATH="$setup_WORKSPACE/.ci/sd4/opamrun:$PATH" + +# Complicated Opam sequence is because: +# 1. Opam's default curl does not work on Windows, +# and `opam init` does not provide a way to change it (TODO: need +# a PR!). +# 2. We have to separate the Opam download cache from the other Opam +# caches +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ] && [ ! -s "$opam_root/.ci.root-init" ]; then # non-empty init file so can be cached irrespective of existence + section_begin opam-init 'Initialize opam root' + + # Clear any partial previous attempt + rm -rf "$opam_root" + + case "$dkml_host_abi,${in_docker:-}" in + windows_*,*) + eor=$(cygpath -am "$setup_WORKSPACE"/.ci/sd4/eor) + opamrun init --disable-sandboxing --no-setup --kind local --bare "$eor" + case "$(opamrun --version)" in + 2.0.*) echo 'download-command: wget' >>"$opam_root/config" ;; + *) opamrun option --yes --global download-command=wget ;; + esac + ;; + *,true) + opamrun init --disable-sandboxing --no-setup --kind local --bare "/work/.ci/sd4/eor" + ;; + *) + opamrun init --disable-sandboxing --no-setup --kind local --bare "$setup_WORKSPACE/.ci/sd4/eor" + ;; + esac + echo yes > "$opam_root/.ci.root-init" + + section_end opam-init +fi + +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + section_begin opam-vars "Summary: opam global variables" + opamrun --no-troubleshooting var --global || true + section_end opam-vars +fi + +# Build OCaml + +do_switch_create() { + do_switch_create_NAME=$1 + shift + + section_begin "switch-create-$do_switch_create_NAME" "Create opam switch '$do_switch_create_NAME'" + # Create, or recreate, the Opam switch. The Opam switch should not be + # cached except for the compiler (confer docs for setup-ocaml GitHub + # Action) which is the 'dkml' switch (or the 'two' switch). + # Check if the switch name is present in the Opam root (which may come from cache) + NOMINALLY_PRESENT=false + if opamrun switch list --short | grep "^${do_switch_create_NAME}\$"; then NOMINALLY_PRESENT=true; fi + + # Check if the switch is actually present in case of cache incoherence + # or corrupt Opam state that could result in: + # Error: No config file found for switch dkml. Switch broken? + if [ $NOMINALLY_PRESENT = true ] && [ ! -e "$opam_root/$do_switch_create_NAME/.opam-switch/switch-config" ]; then + # Remove the switch name from Opam root, and any partial switch state. + # Ignore inevitable warnings/failure about missing switch. + opamrun --no-troubleshooting switch remove "$do_switch_create_NAME" --yes || true + rm -rf "${opam_root:?}/$do_switch_create_NAME" + NOMINALLY_PRESENT=false + fi + + if [ $NOMINALLY_PRESENT = false ]; then + opamrun switch create "$do_switch_create_NAME" --empty --yes + fi + section_end "switch-create-$do_switch_create_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_switch_create dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_switch_create two + else + section_begin "switch-create-two" "Create empty opam switch 'two'" + # Always create a secondary switch ... just empty. Avoid problems with cache content missing + # and idempotency. + opamrun --no-troubleshooting switch remove two --yes || true + rm -rf "$opam_root/two" + opamrun switch create two --empty --yes + section_end "switch-create-two" + fi +fi + +do_switch_active() { + section_begin "switch-active" "Set dkml as active switch" + opamrun switch set dkml --yes + section_end "switch-active" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_switch_active +fi + +do_opam_repositories_add() { + section_begin "opam-repo-add" "Add 'diskuv' opam repository" + if ! opamrun --no-troubleshooting repository list -s | grep '^diskuv'; then + opamrun repository add diskuv "git+https://github.com/diskuv/diskuv-opam-repository.git#${DISKUV_OPAM_REPOSITORY:-$DEFAULT_DISKUV_OPAM_REPOSITORY_TAG}" --yes --dont-select + fi + section_end "opam-repo-add" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_opam_repositories_add +fi + +do_opam_repositories_config() { + do_opam_repositories_config_NAME=$1 + shift + + section_begin "opam-repo-$do_opam_repositories_config_NAME" "Attach repositories to $do_opam_repositories_config_NAME" + + if [ ! -s "$opam_root/.ci.$do_opam_repositories_config_NAME.repo-init" ]; then # non-empty init file so can be cached irrespective of existence + opamrun --no-troubleshooting repository remove default --switch "$do_opam_repositories_config_NAME" --yes || true + opamrun --no-troubleshooting repository remove diskuv --switch "$do_opam_repositories_config_NAME" --yes || true + opamrun repository add default --switch "$do_opam_repositories_config_NAME" --yes + opamrun repository add diskuv --switch "$do_opam_repositories_config_NAME" --yes + echo yes > "$opam_root/.ci.$do_opam_repositories_config_NAME.repo-init" + fi + + section_end "opam-repo-$do_opam_repositories_config_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_opam_repositories_config dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_opam_repositories_config two + fi +fi + +do_opam_repositories_update() { + section_begin "opam-repo-update" "Update opam repositories" + # The default repository may be the initial 'eor' (empty) repository + opamrun repository set-url default https://opam.ocaml.org --yes + # Always set the `diskuv` repository url since it can change + opamrun repository set-url diskuv "git+https://github.com/diskuv/diskuv-opam-repository.git#${DISKUV_OPAM_REPOSITORY:-$DEFAULT_DISKUV_OPAM_REPOSITORY_TAG}" --yes --dont-select + # Update both `default` and `diskuv` Opam repositories + opamrun update default diskuv + section_end "opam-repo-update" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_opam_repositories_update +fi + +do_pins() { + do_pins_NAME=$1 + shift + + section_begin "opam-pins-$do_pins_NAME" "Opam pins for $do_pins_NAME switch" + ### BEGIN pin-adds. DO NOT EDIT THE LINES IN THIS SECTION + # Managed by bump-packages.cmake + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version astring "${PIN_ASTRING}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version base "${PIN_BASE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version base64 "${PIN_BASE64}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version bigarray-compat "${PIN_BIGARRAY_COMPAT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version bos "${PIN_BOS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version camlp-streams "${PIN_CAMLP_STREAMS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version chrome-trace "${PIN_CHROME_TRACE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cmdliner "${PIN_CMDLINER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version conf-dkml-sys-opam "${PIN_CONF_DKML_SYS_OPAM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version conf-pkg-config "${PIN_CONF_PKG_CONFIG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version conf-sqlite3 "${PIN_CONF_SQLITE3}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cppo "${PIN_CPPO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version crunch "${PIN_CRUNCH}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version csexp "${PIN_CSEXP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cstruct "${PIN_CSTRUCT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ctypes "${PIN_CTYPES}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ctypes-foreign "${PIN_CTYPES_FOREIGN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version cudf "${PIN_CUDF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version digestif "${PIN_DIGESTIF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version diskuvbox "${PIN_DISKUVBOX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-apps "${PIN_DKML_APPS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-base-compiler "${PIN_DKML_BASE_COMPILER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-build-desktop "${PIN_DKML_BUILD_DESKTOP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-c-probe "${PIN_DKML_C_PROBE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-compiler-env "${PIN_DKML_COMPILER_ENV}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-compiler-src "${PIN_DKML_COMPILER_SRC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-common-desktop "${PIN_DKML_COMPONENT_COMMON_DESKTOP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-common-opam "${PIN_DKML_COMPONENT_COMMON_OPAM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-common-unixutils "${PIN_DKML_COMPONENT_COMMON_UNIXUTILS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-ocamlcompiler-common "${PIN_DKML_COMPONENT_OCAMLCOMPILER_COMMON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-ocamlcompiler-network "${PIN_DKML_COMPONENT_OCAMLCOMPILER_NETWORK}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-ocamlcompiler-offline "${PIN_DKML_COMPONENT_OCAMLCOMPILER_OFFLINE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-offline-desktop-full "${PIN_DKML_COMPONENT_OFFLINE_DESKTOP_FULL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-offline-opamshim "${PIN_DKML_COMPONENT_OFFLINE_OPAMSHIM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-offline-unixutils "${PIN_DKML_COMPONENT_OFFLINE_UNIXUTILS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-desktop-full "${PIN_DKML_COMPONENT_STAGING_DESKTOP_FULL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-dkmlconfdir "${PIN_DKML_COMPONENT_STAGING_DKMLCONFDIR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-ocamlrun "${PIN_DKML_COMPONENT_STAGING_OCAMLRUN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-opam32 "${PIN_DKML_COMPONENT_STAGING_OPAM32}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-opam64 "${PIN_DKML_COMPONENT_STAGING_OPAM64}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-unixutils "${PIN_DKML_COMPONENT_STAGING_UNIXUTILS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-staging-withdkml "${PIN_DKML_COMPONENT_STAGING_WITHDKML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-component-xx-console "${PIN_DKML_COMPONENT_XX_CONSOLE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-exe "${PIN_DKML_EXE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-exe-lib "${PIN_DKML_EXE_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-install "${PIN_DKML_INSTALL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-install-installer "${PIN_DKML_INSTALL_INSTALLER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-install-runner "${PIN_DKML_INSTALL_RUNNER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-installer-ocaml-common "${PIN_DKML_INSTALLER_OCAML_COMMON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-installer-ocaml-offline "${PIN_DKML_INSTALLER_OCAML_OFFLINE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-package-console "${PIN_DKML_PACKAGE_CONSOLE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtime-common "${PIN_DKML_RUNTIME_COMMON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtime-common-native "${PIN_DKML_RUNTIME_COMMON_NATIVE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtime-distribution "${PIN_DKML_RUNTIME_DISTRIBUTION}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtimelib "${PIN_DKML_RUNTIMELIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-runtimescripts "${PIN_DKML_RUNTIMESCRIPTS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dkml-workflows "${PIN_DKML_WORKFLOWS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune "${PIN_DUNE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-action-plugin "${PIN_DUNE_ACTION_PLUGIN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-build-info "${PIN_DUNE_BUILD_INFO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-configurator "${PIN_DUNE_CONFIGURATOR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-glob "${PIN_DUNE_GLOB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-private-libs "${PIN_DUNE_PRIVATE_LIBS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-rpc "${PIN_DUNE_RPC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-rpc-lwt "${PIN_DUNE_RPC_LWT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dune-site "${PIN_DUNE_SITE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version dyn "${PIN_DYN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version either "${PIN_EITHER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version eqaf "${PIN_EQAF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version extlib "${PIN_EXTLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ezjsonm "${PIN_EZJSONM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version feather "${PIN_FEATHER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fiber "${PIN_FIBER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fix "${PIN_FIX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fmt "${PIN_FMT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version fpath "${PIN_FPATH}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version graphics "${PIN_GRAPHICS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version hex "${PIN_HEX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version integers "${PIN_INTEGERS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jane-street-headers "${PIN_JANE_STREET_HEADERS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jingoo "${PIN_JINGOO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jsonm "${PIN_JSONM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jsonrpc "${PIN_JSONRPC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version jst-config "${PIN_JST_CONFIG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lambda-term "${PIN_LAMBDA_TERM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version logs "${PIN_LOGS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lsp "${PIN_LSP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lwt "${PIN_LWT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version lwt_react "${PIN_LWT_REACT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mccs "${PIN_MCCS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mdx "${PIN_MDX}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version menhir "${PIN_MENHIR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version menhirLib "${PIN_MENHIRLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version menhirSdk "${PIN_MENHIRSDK}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version merlin-lib "${PIN_MERLIN_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version metapp "${PIN_METAPP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version metaquot "${PIN_METAQUOT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mew "${PIN_MEW}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version mew_vi "${PIN_MEW_VI}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version num "${PIN_NUM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml "${PIN_OCAML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml-compiler-libs "${PIN_OCAML_COMPILER_LIBS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml-lsp-server "${PIN_OCAML_LSP_SERVER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocaml-version "${PIN_OCAML_VERSION}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlbuild "${PIN_OCAMLBUILD}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlc-loc "${PIN_OCAMLC_LOC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlfind "${PIN_OCAMLFIND}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlformat "${PIN_OCAMLFORMAT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlformat-lib "${PIN_OCAMLFORMAT_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocamlformat-rpc-lib "${PIN_OCAMLFORMAT_RPC_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocp-indent "${PIN_OCP_INDENT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ocplib-endian "${PIN_OCPLIB_ENDIAN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version odoc "${PIN_ODOC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version odoc-parser "${PIN_ODOC_PARSER}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ordering "${PIN_ORDERING}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version parsexp "${PIN_PARSEXP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version pp "${PIN_PP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_assert "${PIN_PPX_ASSERT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_base "${PIN_PPX_BASE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_cold "${PIN_PPX_COLD}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_compare "${PIN_PPX_COMPARE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_derivers "${PIN_PPX_DERIVERS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_deriving "${PIN_PPX_DERIVING}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_enumerate "${PIN_PPX_ENUMERATE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_expect "${PIN_PPX_EXPECT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_globalize "${PIN_PPX_GLOBALIZE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_hash "${PIN_PPX_HASH}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_here "${PIN_PPX_HERE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_ignore_instrumentation "${PIN_PPX_IGNORE_INSTRUMENTATION}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_inline_test "${PIN_PPX_INLINE_TEST}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_optcomp "${PIN_PPX_OPTCOMP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_pipebang "${PIN_PPX_PIPEBANG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_sexp_conv "${PIN_PPX_SEXP_CONV}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppx_yojson_conv_lib "${PIN_PPX_YOJSON_CONV_LIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ppxlib "${PIN_PPXLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version ptime "${PIN_PTIME}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version qrc "${PIN_QRC}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version re "${PIN_RE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version react "${PIN_REACT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version refl "${PIN_REFL}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version result "${PIN_RESULT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version rresult "${PIN_RRESULT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version seq "${PIN_SEQ}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sexplib "${PIN_SEXPLIB}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sexplib0 "${PIN_SEXPLIB0}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sha "${PIN_SHA}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version spawn "${PIN_SPAWN}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version sqlite3 "${PIN_SQLITE3}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdcompat "${PIN_STDCOMPAT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdio "${PIN_STDIO}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdlib-shims "${PIN_STDLIB_SHIMS}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version stdune "${PIN_STDUNE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version time_now "${PIN_TIME_NOW}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version topkg "${PIN_TOPKG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version traverse "${PIN_TRAVERSE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version trie "${PIN_TRIE}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version tsort "${PIN_TSORT}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version tyxml "${PIN_TYXML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uchar "${PIN_UCHAR}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version utop "${PIN_UTOP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uucp "${PIN_UUCP}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uuidm "${PIN_UUIDM}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uuseg "${PIN_UUSEG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version uutf "${PIN_UUTF}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version with-dkml "${PIN_WITH_DKML}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version xdg "${PIN_XDG}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version yojson "${PIN_YOJSON}" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action -k version zed "${PIN_ZED}" + ### END pin-adds. DO NOT EDIT THE LINES ABOVE + section_end "opam-pins-$do_pins_NAME" + + # -------------- + # REMAINING PINS + # -------------- + + # These come after [pin-adds] section since [pin-adds] may need to be overridden by + # users' choice. + + # dkml-base-compiler + + if [ "${DKML_COMPILER:-}" != '@repository@' ] && [ -z "${DKML_COMPILER:-}" ] && [ -z "${OCAML_COMPILER:-}" ]; then + section_begin checkout-dkml-base-compiler "Pin dkml-base-compiler to default ${DEFAULT_DKML_COMPILER} (neither dkml-base-compiler nor OCAML_COMPILER specified) for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action dkml-base-compiler "https://github.com/diskuv/dkml-compiler.git#${DEFAULT_DKML_COMPILER}" + section_end checkout-dkml-base-compiler + elif [ "${DKML_COMPILER:-}" != '@repository@' ] && [ -n "${DKML_COMPILER:-}" ] && [ -z "${OCAML_COMPILER:-}" ]; then + section_begin checkout-dkml-base-compiler "Pin dkml-base-compiler to $DKML_COMPILER (dkml-base-compiler specified; no OCAML_COMPILER specified) for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action dkml-base-compiler "https://github.com/diskuv/dkml-compiler.git#${DKML_COMPILER}" + section_end checkout-dkml-base-compiler + elif [ -n "${OCAML_COMPILER:-}" ]; then + # Validate OCAML_COMPILER (OCAML_COMPILER specified) + case "${OCAML_COMPILER:-}" in + 4.12.1) true ;; + 4.14.0) true ;; + *) + echo "OCAML_COMPILER version ${OCAML_COMPILER:-} is not supported" >&2 + exit 109 + ;; + esac + + section_begin checkout-dkml-base-compiler "Pin dkml-base-compiler (OCAML_COMPILER specified) for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action dkml-base-compiler "https://github.com/diskuv/dkml-compiler.git#${OCAML_COMPILER}-v${DKML_VERSION}" + section_end checkout-dkml-base-compiler + fi + + # conf-dkml-cross-toolchain + + if [ "${CONF_DKML_CROSS_TOOLCHAIN:-}" != '@repository@' ]; then + section_begin checkout-conf-dkml-cross-toolchain "Pin conf-dkml-cross-toolchain for $do_pins_NAME switch" + opamrun pin add --switch "$do_pins_NAME" --yes --no-action conf-dkml-cross-toolchain "https://github.com/diskuv/conf-dkml-cross-toolchain.git#$CONF_DKML_CROSS_TOOLCHAIN" + section_end checkout-conf-dkml-cross-toolchain + fi +} + +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_pins dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_pins two + fi +fi + +do_use_vsstudio() { + do_use_vsstudio_NAME=$1 + shift + case "$dkml_host_abi" in + windows_*) + section_begin "use-vsstudio-$do_use_vsstudio_NAME" "Use Visual Studio in dkml-* Opam packages (Windows) for $do_use_vsstudio_NAME switch" + + # shellcheck disable=SC2153 + E_VS_DIR=$(escape_arg_as_ocaml_string "$VS_DIR") + # shellcheck disable=SC2153 + E_VS_VCVARSVER=$(escape_arg_as_ocaml_string "$VS_VCVARSVER") + # shellcheck disable=SC2153 + E_VS_WINSDKVER=$(escape_arg_as_ocaml_string "$VS_WINSDKVER") + # shellcheck disable=SC2153 + E_VS_MSVSPREFERENCE=$(escape_arg_as_ocaml_string "$VS_MSVSPREFERENCE") + # shellcheck disable=SC2153 + E_VS_CMAKEGENERATOR=$(escape_arg_as_ocaml_string "$VS_CMAKEGENERATOR") + + case "$(opamrun --version)" in + 2.0.*) + if [ "${in_docker}" = "true" ]; then + echo Opam 2.0 support in dockcross to use a portable opam var prefix not yet implemented + exit 67 + fi + OP=$(opamrun var prefix --switch "$do_use_vsstudio_NAME") + OPSC=$OP/.opam-switch/switch-config + if grep setenv: "$OPSC"; then + echo "INFO: Updating switch-config. Old was:" + awk '{print ">> " $0}' "$OPSC" + + awk '$1=="setenv:"{x=1} x==0{print} x==1 && $0=="]"{x=0}' "$OPSC" >"$OPSC".trimmed + mv "$OPSC".trimmed "$OPSC" + fi + echo 'setenv: [' >>"$OPSC" + echo ' [DKML_COMPILE_SPEC = "1"]' >>"$OPSC" + echo ' [DKML_COMPILE_TYPE = "VS"]' >>"$OPSC" + echo " [DKML_COMPILE_VS_DIR = \"$E_VS_DIR\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_VCVARSVER = \"$E_VS_VCVARSVER\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_WINSDKVER = \"$E_VS_WINSDKVER\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_MSVSPREFERENCE = \"$E_VS_MSVSPREFERENCE\"]" >>"$OPSC" + echo " [DKML_COMPILE_VS_CMAKEGENERATOR = \"$E_VS_CMAKEGENERATOR\"]" >>"$OPSC" + echo " [DKML_HOST_ABI = \"${dkml_host_abi}\"]" >>"$OPSC" + echo ']' >>"$OPSC" + cat "$OPSC" >&2 # print + ;; + *) + opamrun option --switch "$do_use_vsstudio_NAME" setenv= # reset + opamrun option --switch "$do_use_vsstudio_NAME" setenv+='DKML_COMPILE_SPEC = "1"' + opamrun option --switch "$do_use_vsstudio_NAME" setenv+='DKML_COMPILE_TYPE = "VS"' + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_DIR = \"$E_VS_DIR\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_VCVARSVER = \"$E_VS_VCVARSVER\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_WINSDKVER = \"$E_VS_WINSDKVER\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_MSVSPREFERENCE = \"$E_VS_MSVSPREFERENCE\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_COMPILE_VS_CMAKEGENERATOR = \"$E_VS_CMAKEGENERATOR\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv+="DKML_HOST_ABI = \"${dkml_host_abi}\"" + opamrun option --switch "$do_use_vsstudio_NAME" setenv # print + ;; + esac + + # shellcheck disable=SC2016 + opamrun exec --switch "$do_use_vsstudio_NAME" -- sh -c 'echo $VCToolsRedistDir' + + section_end "use-vsstudio-$do_use_vsstudio_NAME" + ;; + esac +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_use_vsstudio dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_use_vsstudio two + fi +fi + +# Because dune.X.Y.Z+shim (and any user DKML packages) requires DKML installed (after all, it is just +# a with-dkml.exe shim), we need either dkmlvars-v2.sexp or DKML environment +# variables. Confer: Dkml_runtimelib.Dkml_context.get_dkmlversion +# +# grep matches either: +# [... [DiskuvOCamlVersion = "1.0.1"] ...] +# DiskuvOCamlVersion = "1.0.1" +do_setenv() { + do_setenv_SWITCH=$1 + shift + section_begin "setenv-$do_setenv_SWITCH" "Set opam option for $do_setenv_SWITCH switch" + opamrun option --switch "$do_setenv_SWITCH" setenv > ".ci/sd4/setenv.$do_setenv_SWITCH.txt" + if ! grep -q '\(^|\[\)DiskuvOCamlVarsVersion ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+='DiskuvOCamlVarsVersion = "2"' + fi + if ! grep -q '\(^|\[\)DiskuvOCamlVersion ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlVersion = \"$DKML_VERSION\"" + fi + if [ "$do_setenv_SWITCH" = dkml ] && [ -n "${DKML_HOME:-}" ]; then + do_setenv_DKMLHOME_ESCAPED="$DKML_HOME" + do_setenv_USRBIN_ESCAPED="$DKML_HOME/usr/bin" + do_setenv_BIN_ESCAPED="$DKML_HOME/bin" + if [ -x /usr/bin/cygpath ]; then + do_setenv_DKMLHOME_ESCAPED=$(/usr/bin/cygpath -aw "$do_setenv_DKMLHOME_ESCAPED" | sed 's/\\/\\\\/g') + do_setenv_USRBIN_ESCAPED=$(/usr/bin/cygpath -aw "$do_setenv_USRBIN_ESCAPED" | sed 's/\\/\\\\/g') + do_setenv_BIN_ESCAPED=$(/usr/bin/cygpath -aw "$do_setenv_BIN_ESCAPED" | sed 's/\\/\\\\/g') + fi + if ! grep -q '\(^|\[\)DiskuvOCamlHome ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlHome = \"$do_setenv_DKMLHOME_ESCAPED\"" + fi + if ! grep -q '\(^|\[\)DiskuvOCamlBinaryPaths ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlBinaryPaths = \"$do_setenv_USRBIN_ESCAPED;$do_setenv_BIN_ESCAPED\"" + fi + if ! grep -q '\(^|\[\)DiskuvOCamlDeploymentId ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlDeploymentId = \"setup-dkml-switch-$do_setenv_SWITCH\"" + fi + fi + case "${dkml_host_abi}" in + windows_*) + if ! grep -q '\(^|\[\)DiskuvOCamlMSYS2Dir ' ".ci/sd4/setenv.$do_setenv_SWITCH.txt"; then + if [ -x /usr/bin/cygpath ]; then + MSYS2_DIR_NATIVE=$(/usr/bin/cygpath -aw /) + else + # If we are already inside MSYS2 then MSYSTEM_PREFIX should be set. But cygpath should be there as well!! + echo "FATAL: Could not locate MSYS2: there was no cygpath" >&2 + exit 3 + fi + MSYS2_DIR_NATIVE_ESCAPED=$(printf "%s" "$MSYS2_DIR_NATIVE" | sed 's/\\/\\\\/g') + opamrun option --switch "$do_setenv_SWITCH" setenv+="DiskuvOCamlMSYS2Dir = \"$MSYS2_DIR_NATIVE_ESCAPED\"" + fi + esac + section_end "setenv-$do_setenv_SWITCH" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_setenv dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_setenv two + fi +fi + +do_install_compiler() { + do_install_compiler_NAME=$1 + shift + section_begin "install-compiler-$do_install_compiler_NAME" "Install OCaml compiler for $do_install_compiler_NAME switch" + opamrun pin list --switch "$do_install_compiler_NAME" + # shellcheck disable=SC2086 + opamrun upgrade --switch "$do_install_compiler_NAME" --yes dkml-base-compiler conf-dkml-cross-toolchain ${ocaml_options:-} + section_end "install-compiler-$do_install_compiler_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + if ! [ "${PRIMARY_SWITCH_SKIP_INSTALL:-}" = "true" ]; then + do_install_compiler dkml + fi + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_install_compiler two + fi +fi + +do_summary() { + do_summary_NAME=$1 + shift + section_begin "summary-$do_summary_NAME" "Summary: $do_summary_NAME switch" + opamrun var --switch "$do_summary_NAME" + opamrun exec --switch "$do_summary_NAME" -- ocamlc -config + section_end "summary-$do_summary_NAME" +} +if [ "${SKIP_OPAM_MODIFICATIONS:-}" = "false" ]; then + do_summary dkml + if [ "${SECONDARY_SWITCH:-}" = "true" ]; then + do_summary two + fi +fi + +'@ +Set-Content -Path ".ci\sd4\run-setup-dkml.sh" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/run-setup-dkml.sh' + +$Content = @' +# MSVC environment variables: +# 1. https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170 +# 2. https://docs.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-170#link-environment-variables (except TMP) +# 3. VCToolsRedistDir: https://docs.microsoft.com/en-us/cpp/windows/redistributing-visual-cpp-files?view=msvc-170#locate-the-redistributable-files +BEGIN{FS="="} +$1=="CL"||$1=="_CL_"||$1=="INCLUDE"||$1=="LIBPATH" {print "export " $0} +$1=="LINK"||$1=="_LINK_"||$1=="LIB"||$1=="PATH" {print "export " $0} +$1=="VCToolsRedistDir" {print "export " $0} + +'@ +Set-Content -Path ".ci\sd4\msvcenv.awk" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/msvcenv.awk' + + +$Content = @' +{ + # trim leading and trailing space + sub(/^ */, ""); + sub(/ *$/, ""); + + print "export PATH='" $0 "'"; +} +'@ +Set-Content -Path ".ci\sd4\msvcpath.awk" -Encoding Unicode -Value $Content +msys64\usr\bin\bash -lc 'dos2unix .ci/sd4/msvcpath.awk' + +# PowerShell (UTF-16) and Batch (ANSI) scripts + + +$Content = @' +# Diagnose Visual Studio environment variables (Windows) +# This wastes time and has lots of rows! Only run if "VERBOSE" GitHub input key. +if ( "${env:VERBOSE}" -eq "true" ) { + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\include") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\include" + } + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop" + } + + $env:PSModulePath += "$([System.IO.Path]::PathSeparator).ci\sd4\g\dkml-runtime-distribution\src\windows" + Import-Module Machine + + $allinstances = Get-VSSetupInstance + $allinstances | ConvertTo-Json -Depth 5 +} + +# Make export expression [SN]NAME=[SV]VALUE[EV] +# where [SN] is start name and [SV] and [EV] are start and end value +if (("${env:GITLAB_CI}" -eq "true") -or ("${env:PC_CI}" -eq "true")) { + # Executed immediately in POSIX shell, so must be a real POSIX shell variable declaration + $ExportSN = "export " + $ExportSV = "'" + $ExportEV = "'" + $ExportExt = ".sh" +} else { + # Goes into $env:GITHUB_ENV, so must be plain NAME=VALUE + $ExportSN = "" + $ExportSV = "" + $ExportEV = "" + $ExportExt = ".github" +} + +# Locate Visual Studio (Windows) +if ("${env:vsstudio_dir}" -eq "" -and (!(Test-Path -Path .ci/sd4/vsenv${ExportExt}) -or !(Test-Path -Path .ci/sd4/vsenv.ps1))) { + $env:PSModulePath += "$([System.IO.Path]::PathSeparator).ci\sd4\g\dkml-runtime-distribution\src\windows" + Import-Module Machine + + $CompatibleVisualStudios = Get-CompatibleVisualStudios -ErrorIfNotFound + $CompatibleVisualStudios + $ChosenVisualStudio = ($CompatibleVisualStudios | Select-Object -First 1) + $VisualStudioProps = Get-VisualStudioProperties -VisualStudioInstallation $ChosenVisualStudio + $VisualStudioProps + + Write-Output "${ExportSN}VS_DIR=${ExportSV}$($VisualStudioProps.InstallPath)${ExportEV}" > .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_VCVARSVER=${ExportSV}$($VisualStudioProps.VcVarsVer)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_WINSDKVER=${ExportSV}$($VisualStudioProps.WinSdkVer)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_MSVSPREFERENCE=${ExportSV}$($VisualStudioProps.MsvsPreference)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_CMAKEGENERATOR=${ExportSV}$($VisualStudioProps.CMakeGenerator)${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + + Write-Output "`$env:VS_DIR='$($VisualStudioProps.InstallPath)'" > .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_VCVARSVER='$($VisualStudioProps.VcVarsVer)'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_WINSDKVER='$($VisualStudioProps.WinSdkVer)'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_MSVSPREFERENCE='$($VisualStudioProps.MsvsPreference)'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_CMAKEGENERATOR='$($VisualStudioProps.CMakeGenerator)'" >> .ci/sd4/vsenv.ps1 +} + +# Link to hardcoded Visual Studio (Windows) +if ("${env:vsstudio_dir}" -ne "") { + Write-Output "${ExportSN}VS_DIR=${ExportSV}${env:vsstudio_dir}${ExportEV}" > .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_VCVARSVER=${ExportSV}${env:vsstudio_vcvarsver}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_WINSDKVER=${ExportSV}${env:vsstudio_winsdkver}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_MSVSPREFERENCE=${ExportSV}${env:vsstudio_msvspreference}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + Write-Output "${ExportSN}VS_CMAKEGENERATOR=${ExportSV}${env:vsstudio_cmakegenerator}${ExportEV}" >> .ci/sd4/vsenv${ExportExt} + + Write-Output "`$env:VS_DIR='${env:vsstudio_dir}'" > .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_VCVARSVER='${env:vsstudio_vcvarsver}'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_WINSDKVER='${env:vsstudio_winsdkver}'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_MSVSPREFERENCE='${env:vsstudio_msvspreference}'" >> .ci/sd4/vsenv.ps1 + Write-Output "`$env:VS_CMAKEGENERATOR='${env:vsstudio_cmakegenerator}'" >> .ci/sd4/vsenv.ps1 +} + +'@ +Set-Content -Path ".ci\sd4\config-vsstudio.ps1" -Encoding Unicode -Value $Content + + +$Content = @' +@ECHO OFF + +REM The OCaml dkml-base-compiler will compile fine but any other +REM packages (ocamlbuild, etc.) which +REM need a native compiler will fail without the MSVC compiler in the +REM PATH. There isn't a `with-dkml.exe` alternative available at +REM this stage of the GitHub workflow. +SET VSCMD_DEBUG=2 +SET VSCMD_SKIP_SENDTELEMETRY=1 +call "%VS_DIR%\Common7\Tools\VsDevCmd.bat" -no_logo -host_arch=%vsstudio_hostarch% -arch=%vsstudio_arch% -vcvars_ver=%VS_VCVARSVER% -winsdk=%VS_WINSDKVER% +if %ERRORLEVEL% neq 0 ( + echo. + echo.The "%VS_DIR%\Common7\Tools\VsDevCmd.bat" command failed + echo.with exit code %ERRORLEVEL%. + echo. + exit /b %ERRORLEVEL% +) + +REM VsDevCmd.bat turns off echo; be explicit if we want it on or off +@echo OFF + +REM MSVC environment variables in Unix format. +echo %PATH% > .ci\sd4\msvcpath + + +REM * We can't use `bash -lc` directly to query for all MSVC environment variables +REM because it stomps over the PATH. So we are inside a Batch script to do the query. +msys64\usr\bin\bash -lc "set | grep -v '^PATH=' | awk -f .ci/sd4/msvcenv.awk > .ci/sd4/msvcenv" +'@ +Set-Content -Path ".ci\sd4\get-msvcpath-into-msys2.bat" -Encoding Default -Value $Content + +msys64\usr\bin\bash -lc "sh .ci/sd4/run-checkout-code.sh PC_PROJECT_DIR '${env:PC_PROJECT_DIR}'" +if ($LASTEXITCODE -ne 0) { + throw "run-checkout-code.sh failed" +} + +# Diagnose Visual Studio environment variables (Windows) +# This wastes time and has lots of rows! Only run if "VERBOSE" GitHub input key. + +If ( "${env:VERBOSE}" -eq "true" ) { + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\include") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\include" + } + if (Test-Path -Path "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop") { + Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\Extension SDKs\WindowsDesktop" + } + + $env:PSModulePath += "$([System.IO.Path]::PathSeparator).ci\sd4\g\dkml-runtime-distribution\src\windows" + Import-Module Machine + + $allinstances = Get-VSSetupInstance + $allinstances | ConvertTo-Json -Depth 5 +} +.ci\sd4\config-vsstudio.ps1 +msys64\usr\bin\bash -lc "dos2unix .ci/sd4/vsenv.sh" +Get-Content .ci/sd4/vsenv.sh +Get-Content .ci/sd4/vsenv.ps1 + +# Capture Visual Studio compiler environment +& .ci\sd4\vsenv.ps1 +& .ci\sd4\get-msvcpath-into-msys2.bat +msys64\usr\bin\bash -lc "cat .ci/sd4/msvcpath | tr -d '\r' | cygpath --path -f - | awk -f .ci/sd4/msvcpath.awk >> .ci/sd4/msvcenv" +msys64\usr\bin\bash -lc "tail -n100 .ci/sd4/msvcpath .ci/sd4/msvcenv" + +msys64\usr\bin\bash -lc "sh .ci/sd4/run-setup-dkml.sh PC_PROJECT_DIR '${env:PC_PROJECT_DIR}'" +if ($LASTEXITCODE -ne 0) { + throw "run-setup-dkml.sh failed" +} + +########################### script ############################### + +Write-Host @" +Finished setup. + +To continue your testing, run in PowerShell: + `$env:CHERE_INVOKING = "yes" + `$env:MSYSTEM = "$env:msys2_system" + `$env:dkml_host_abi = "$env:dkml_host_abi" + `$env:abi_pattern = "$env:abi_pattern" + `$env:opam_root = "$env:opam_root" + `$env:exe_ext = "$env:exe_ext" + +Now you can use 'opamrun' to do opam commands like: + + msys64\usr\bin\bash -lc 'PATH="`$PWD/.ci/sd4/opamrun:`$PATH"; opamrun install XYZ.opam' + msys64\usr\bin\bash -lc 'PATH="`$PWD/.ci/sd4/opamrun:`$PATH"; opamrun exec -- bash' + msys64\usr\bin\bash -lc 'sh ci/build-test.sh' +"@ diff --git a/.gitattributes b/.gitattributes index 09de0a89..783af180 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,7 @@ *.ml linguist-language=OCaml + +# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_character_encoding?view=powershell-7.1 +*.ps1 text working-tree-encoding=UTF-16 eol=crlf +*.psm1 text working-tree-encoding=UTF-16 eol=crlf +# Other file types that must be CRLF +*.sln text eol=crlf diff --git a/.github/workflows/dkml.yml b/.github/workflows/dkml.yml new file mode 100644 index 00000000..ea2e5522 --- /dev/null +++ b/.github/workflows/dkml.yml @@ -0,0 +1,106 @@ +########################################################################## +# File: dktool/cmake/scripts/dkml/workflow/compilers-github-workflows-dkml.in.yml# +# # +# Copyright 2022 Diskuv, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # +# implied. See the License for the specific language governing # +# permissions and limitations under the License. # +# # +########################################################################## + +# Updating +# -------- +# +# 1. Delete this file. +# 2. Run dk with your original arguments: +# ./dk dkml.workflow.compilers CI GitHub Desktop OS Windows +# or get help to come up with new arguments: +# ./dk dkml.workflow.compilers HELP + +name: Build with DkML compiler + +on: + # trigger on any push + push: + # ... or trigger manually from GitHub web interface + workflow_dispatch: + +jobs: + build: + strategy: + matrix: + include: # + - gh_os: windows-2019 + abi_pattern: win32-windows_x86 + dkml_host_abi: windows_x86 + - gh_os: windows-2019 + abi_pattern: win32-windows_x86_64 + dkml_host_abi: windows_x86_64 + + runs-on: ${{ matrix.gh_os }} + name: build / ${{ matrix.abi_pattern }} + + # mirage-crypto does not support MSVC as of 2023-09-03. Remove + # this when MSVC is properly supported. + continue-on-error: true + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Cache DkML compilers code + uses: actions/cache@v3 + id: cache-dkml-compilers + with: + path: .ci/dkml-compilers + key: ${{ runner.os }} + + - name: Checkout DkML compilers code + if: steps.cache-dkml-compilers.outputs.cache-hit != 'true' + # For help: ./dk dkml.workflow.compilers HELP + run: ./dk dkml.workflow.compilers CI GitHub + + # The .ci/dkml-compilers "pre" actions will create the environment variables: + # opam_root, exe_ext, dkml_host_abi, abi_pattern (and many more) + # + - name: Setup DkML compilers on a Windows host + if: startsWith(matrix.dkml_host_abi, 'windows_') + uses: ./.ci/dkml-compilers/gh-windows/pre + with: + DKML_COMPILER: ${{ env.DKML_COMPILER }} + CACHE_PREFIX: ${{ env.CACHE_PREFIX }} + + # This section is for your own build logic which you should place in + # ci/build-test.sh or a similar file + + - name: Build and test on Windows host + if: startsWith(matrix.dkml_host_abi, 'windows_') + shell: msys2 {0} + run: ci/build-test.sh + + - name: Build and test on non-Windows host + if: "!startsWith(matrix.dkml_host_abi, 'windows_')" + run: ci/build-test.sh + + # The .ci/dkml-compilers "post" actions will finalize caching, etc. + + - name: Teardown DkML compilers on a Windows host + if: startsWith(matrix.dkml_host_abi, 'windows_') + uses: ./.ci/dkml-compilers/gh-windows/post + + - name: Teardown DkML compilers on a Darwin host + if: startsWith(matrix.dkml_host_abi, 'darwin_') + uses: ./.ci/dkml-compilers/gh-darwin/post + + - name: Teardown DkML compilers on a Linux host + if: startsWith(matrix.dkml_host_abi, 'linux_') + uses: ./.ci/dkml-compilers/gh-linux/post diff --git a/.gitignore b/.gitignore index 48d95161..7aeb30c2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,13 @@ mirage/myocamlbuild.ml mirage/.mirage.config _opam *.install + +# CI using dkml-workflows' DkML compilers. +# DkML compilers populate the .opam folder. +/.opam/ +# GitHub, unlike GitLab, does not need its CI files to exist +# before referencing them. That means the GitHub scripts do not need +# to be checked in. +/.ci/dkml-compilers/gh-* +# Desktop testing on Windows uses MSYS2. +/msys64/ diff --git a/ci/build-test.sh b/ci/build-test.sh new file mode 100644 index 00000000..4653874e --- /dev/null +++ b/ci/build-test.sh @@ -0,0 +1,84 @@ +#!/bin/sh +########################################################################## +# File: dktool/cmake/scripts/dkml/workflow/compilers-build-test.in.sh # +# # +# Copyright 2022 Diskuv, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # +# implied. See the License for the specific language governing # +# permissions and limitations under the License. # +# # +########################################################################## + +# Updating +# -------- +# +# 1. Delete this file. +# 2. Run dk with your original arguments: +# ./dk dkml.workflow.compilers CI GitHub Desktop OS Windows +# or get help to come up with new arguments: +# ./dk dkml.workflow.compilers HELP + +set -euf + +# Set project directory +if [ -n "${CI_PROJECT_DIR:-}" ]; then + PROJECT_DIR="$CI_PROJECT_DIR" +elif [ -n "${PC_PROJECT_DIR:-}" ]; then + PROJECT_DIR="$PC_PROJECT_DIR" +elif [ -n "${GITHUB_WORKSPACE:-}" ]; then + PROJECT_DIR="$GITHUB_WORKSPACE" +else + PROJECT_DIR="$PWD" +fi +if [ -x /usr/bin/cygpath ]; then + PROJECT_DIR=$(/usr/bin/cygpath -au "$PROJECT_DIR") +fi + +# shellcheck disable=SC2154 +echo " +============= +build-test.sh +============= +. +--------- +Arguments +--------- +$* +. +------ +Matrix +------ +dkml_host_abi=$dkml_host_abi +abi_pattern=$abi_pattern +opam_root=$opam_root +exe_ext=${exe_ext:-} +. +" + +# PATH. Add opamrun +export PATH="$PROJECT_DIR/.ci/sd4/opamrun:$PATH" + +# Initial Diagnostics (optional but useful) +opamrun switch +opamrun list +opamrun var +opamrun config report +opamrun option +opamrun exec -- ocamlc -config + +# Update +opamrun update + +# Make your own build logic! +opamrun install --yes --deps-only -t mirage-crypto mirage-crypto-rng mirage-crypto-rng-lwt mirage-crypto-rng-mirage mirage-crypto-pk mirage-crypto-ec +opamrun exec -- dune build -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec +opamrun exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec diff --git a/cmake/FindDkToolScripts.cmake b/cmake/FindDkToolScripts.cmake new file mode 100644 index 00000000..94090176 --- /dev/null +++ b/cmake/FindDkToolScripts.cmake @@ -0,0 +1,235 @@ +########################################################################## +# File: dktool/cmake/FindDkToolScripts.cmake # +# # +# Copyright 2023 Diskuv, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # +# implied. See the License for the specific language governing # +# permissions and limitations under the License. # +# # +########################################################################## + +# Recommendation: Place this file in source control. +# Auto-generated by `./dk dksdk.project.new` of dktool. + +include(FetchContent) + +function(parse_dktool_command_line) + # The first argument is . All dots will be replaced with a + # triple underscore as a convenience and to be pretty for the user. + # However, we do not error if no is given ... we'll do + # that later. + set(command) + set(expected_function_name) + set(quotedArgs "") + if(ARGC EQUAL 0 OR (ARGC EQUAL 1 AND ARGV0 STREQUAL HELP)) + message(NOTICE [[Usage: + ./dk HELP + ./dk [args] +]]) + else() + set(command ${ARGV0}) + string(REPLACE "." "___" expected_function_name ${command}) + message(VERBOSE "Searching for ${expected_function_name}") + + # Parse the remainder of the arguments [args] + # * Use technique from [Professional CMake: A Practical Guide - Forwarding Command Arguments] + # to be able to forward arguments correctly to an inner function (the function). + cmake_parse_arguments(PARSE_ARGV 1 FWD "" "" "") + foreach(arg IN LISTS FWD_UNPARSED_ARGUMENTS) + string(APPEND quotedArgs " [===[${arg}]===]") + endforeach() + endif() + + # Set policies (we are in a new EVAL CODE context) + # Included scripts do automatic cmake_policy PUSH and POP + if(POLICY CMP0011) + cmake_policy(SET CMP0011 NEW) + endif() + # Allow GIT_SUBMODULES empty to mean no submodules + if(POLICY CMP0097) + cmake_policy(SET CMP0097 NEW) + endif() + + # Setup the binary directory + if(NOT DKTOOL_WORKDIR) + message(FATAL_ERROR "Illegal state. Expecting DKTOOL_WORKDIR") + endif() + set(CMAKE_BINARY_DIR ${DKTOOL_WORKDIR}) + set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_BINARY_DIR}) + + # Search in all the user scripts + set(dot_function_names) + file(GLOB_RECURSE command_files + LIST_DIRECTORIES FALSE + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts + cmake/scripts/*.cmake) + foreach(command_file IN LISTS command_files) + # Normalize and lowercase + cmake_path(NORMAL_PATH command_file) + string(TOLOWER "${command_file}" command_file) + cmake_path(REMOVE_EXTENSION command_file OUTPUT_VARIABLE command_file_no_ext) + + # Convert to list + string(REPLACE "/" ";" command_stems_no_namespace ${command_file_no_ext}) + + # Make a pretty description only for validation + set(pretty_stems ${command_stems_no_namespace}) + list(TRANSFORM pretty_stems PREPEND "'") + list(TRANSFORM pretty_stems APPEND "'") + string(JOIN ", " pretty_stems_str ${pretty_stems}) + string(REGEX REPLACE ",([^,]*)" " and \\1" pretty_stems_str "${pretty_stems_str}") + + # Validate that only alphanumeric with underscores (but not the reserved three underscores) + string(REGEX MATCH "[/a-z0-9_]*" only_alphanum_and_underscores "${command_file_no_ext}") + if(NOT only_alphanum_and_underscores STREQUAL "${command_file_no_ext}") + message(WARNING "Ignoring user script ${CMAKE_CURRENT_SOURCE_DIR}/${command_file}. +The stems of the user script (${pretty_stems_str}) must only contain letters, numbers and underscores.") + continue() + endif() + string(FIND "${command_file_no_ext}" "___" reserved_underscores) + if(reserved_underscores GREATER_EQUAL 0) + message(WARNING "Ignoring user script ${CMAKE_CURRENT_SOURCE_DIR}/${command_file}. +No stem of the user script (${pretty_stems_str}) can contain a triple underscore ('___').") + continue() + endif() + + # Translate dev/xxx.cmake to the "user" namespaced function name + # `user__dev__xxx` and `user.dev.xxx`. + set(command_stems ${command_stems_no_namespace}) + list(PREPEND command_stems "user") + string(JOIN "___" command_function_name ${command_stems}) + string(JOIN "." dot_function_name ${command_stems}) + list(APPEND dot_function_names ${dot_function_name}) + + # In a new scope (to avoid a global, leaky namespace) register the function. + message(VERBOSE "Shimming ${command_function_name}") + cmake_language(EVAL CODE " +function(${command_function_name}) + include(\"${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/${command_file}\") + if(COMMAND run) + run(${quotedArgs}) + else() + message(FATAL_ERROR [[The user script ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/${command_file} was missing: + function(run) + # Your user code + endfunction() +]]) + endif() +endfunction() +") + endforeach() + + # Include all the system scripts. + # - Since the system scripts come after the user scripts, the user scripts + # don't override the system scripts unless the user scripts use deferred + # hooks or redefine CMake built-in functions. Regardless, the user + # scripts are namespaced with `user__` prefix + if(NOT IS_DIRECTORY cmake/scripts/dksdk) + # If this project (ex. dktool) has the system scripts, it must + # have all of them. Otherwise we download the system scripts. + FetchContent_Populate(dktool + QUIET + GIT_REPOSITORY https://gitlab.com/diskuv/dktool.git + GIT_TAG 1.0 + # As of 3.25.3 the bug https://gitlab.kitware.com/cmake/cmake/-/issues/24578 + # has still not been fixed. That means empty strings get removed. + # ExternalProject_Add(GIT_SUBMODULES) in dktool-subbuild/CMakeLists.txt + # means fetch all submodules. + # https://gitlab.kitware.com/cmake/cmake/-/issues/20579#note_734045 + # has a workaround. + GIT_SUBMODULES cmake # Non-git-submodule dir that already exists + GIT_SUBMODULES_RECURSE OFF + ) + file(GLOB_RECURSE system_command_files + LIST_DIRECTORIES FALSE + RELATIVE ${dktool_SOURCE_DIR}/cmake/scripts + ${dktool_SOURCE_DIR}/cmake/scripts/dkml/*.cmake + ${dktool_SOURCE_DIR}/cmake/scripts/dksdk/*.cmake) + foreach(command_file IN LISTS system_command_files) + # Normalize and lowercase + cmake_path(NORMAL_PATH command_file) + string(TOLOWER "${command_file}" command_file) + cmake_path(REMOVE_EXTENSION command_file OUTPUT_VARIABLE command_file_no_ext) + + # Convert to list + string(REPLACE "/" ";" command_stems_no_namespace ${command_file_no_ext}) + + # Translate dksdk/xxx.cmake to the function name `dksdk__xxx` and `dksdk.xxx` + set(command_stems ${command_stems_no_namespace}) + string(JOIN "___" command_function_name ${command_stems}) + string(JOIN "." dot_function_name ${command_stems}) + list(APPEND dot_function_names ${dot_function_name}) + + # In a new scope (to avoid a global, leaky namespace) register the function. + message(VERBOSE "Shimming ${command_function_name}") + cmake_language(EVAL CODE " +function(${command_function_name}) + include(\"${dktool_SOURCE_DIR}/cmake/scripts/${command_file}\") + if(COMMAND run) + run(${quotedArgs}) + else() + message(FATAL_ERROR [[The system script ${dktool_SOURCE_DIR}/cmake/scripts/${command_file} was missing: + function(run) + # The system code + endfunction() +]]) + endif() +endfunction() +") + + endforeach() + endif() + + # Pretty function names that are available + set(pretty_function_names ${dot_function_names}) + list(TRANSFORM pretty_function_names PREPEND " ") + list(TRANSFORM pretty_function_names APPEND "\n") + string(JOIN "" str_pretty_function_names ${pretty_function_names}) + + # Exit if no + if(NOT command) + message(NOTICE "The following commands are available: +${str_pretty_function_names}") + return() + endif() + + # Validate the exists + if(NOT COMMAND ${expected_function_name}) + message(FATAL_ERROR "No command '${command}' exists. The following commands are available: +${str_pretty_function_names}") + message(FATAL_ERROR "No command '${command}' exists") + endif() + + # Call the function + cmake_language(EVAL CODE "${expected_function_name}()") +endfunction() + +# DkML data home +if(WIN32) + set(DKML_DATA_HOME "$ENV{LOCALAPPDATA}/Programs/DiskuvOCaml") +elseif(DEFINED ENV{XDG_DATA_HOME}) + set(DKML_DATA_HOME "$ENV{XDG_DATA_HOME}/diskuv-ocaml") +else() + set(DKML_DATA_HOME "$ENV{HOME}/.local/share/diskuv-ocaml") +endif() + +# DkSDK data home +if(WIN32) + set(DKSDK_DATA_HOME "$ENV{LOCALAPPDATA}/Programs/DkSDK") +elseif(DEFINED ENV{XDG_DATA_HOME}) + set(DKSDK_DATA_HOME "$ENV{XDG_DATA_HOME}/dksdk") +else() + set(DKSDK_DATA_HOME "$ENV{HOME}/.local/share/dksdk") +endif() + +# Splat DKTOOL_CMDLINE +cmake_language(EVAL CODE "parse_dktool_command_line(${DKTOOL_CMDLINE})") diff --git a/dk b/dk new file mode 100644 index 00000000..44d8adc3 --- /dev/null +++ b/dk @@ -0,0 +1,723 @@ +#!/bin/sh +########################################################################## +# File: dktool/dk # +# # +# Copyright 2023 Diskuv, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # +# implied. See the License for the specific language governing # +# permissions and limitations under the License. # +# # +########################################################################## + +# Recommendation: Place this file in source control. +# Auto-generated by `./dk dksdk.project.new` of dktool. +# +# Invoking: ./dk +# That works in Powershell on Windows, and in Unix. Copy-and-paste works! +# +# Purpose: Install CMake if not already. Then invoke CMake. + +set -euf + +dk_pwd=$PWD + +# --- Imports of dkml-runtime-common's crossplatform-functions.sh --- + +# Get standard locations of Unix system binaries like `/usr/bin/mv` (or `/bin/mv`). +# +# Will not return anything in `/usr/local/bin` or `/usr/sbin`. Use when you do not +# know whether the PATH has been set correctly, or when you do not know if the +# system binary exists. +# +# At some point in the future, this function will error out if the required system binaries +# do not exist. Most system binaries are common to all Unix/Linux/macOS installations but +# some (like `comm`) may need to be installed for proper functioning of DKML. +# +# Outputs: +# - env:DKMLSYS_MV - Location of `mv` +# - env:DKMLSYS_CHMOD - Location of `chmod` +# - env:DKMLSYS_UNAME - Location of `uname` +# - env:DKMLSYS_ENV - Location of `env` +# - env:DKMLSYS_AWK - Location of `awk` +# - env:DKMLSYS_SED - Location of `sed` +# - env:DKMLSYS_COMM - Location of `comm` +# - env:DKMLSYS_INSTALL - Location of `install` +# - env:DKMLSYS_RM - Location of `rm` +# - env:DKMLSYS_SORT - Location of `sort` +# - env:DKMLSYS_CAT - Location of `cat` +# - env:DKMLSYS_STAT - Location of `stat` +# - env:DKMLSYS_GREP - Location of `grep` +# - env:DKMLSYS_CURL - Location of `curl` (empty if not found) +# - env:DKMLSYS_WGET - Location of `wget` (empty if not found) +# - env:DKMLSYS_TR - Location of `tr` +autodetect_system_binaries() { + if [ -z "${DKMLSYS_MV:-}" ]; then + if [ -x /usr/bin/mv ]; then + DKMLSYS_MV=/usr/bin/mv + else + DKMLSYS_MV=/bin/mv + fi + fi + if [ -z "${DKMLSYS_CHMOD:-}" ]; then + if [ -x /usr/bin/chmod ]; then + DKMLSYS_CHMOD=/usr/bin/chmod + else + DKMLSYS_CHMOD=/bin/chmod + fi + fi + if [ -z "${DKMLSYS_UNAME:-}" ]; then + if [ -x /usr/bin/uname ]; then + DKMLSYS_UNAME=/usr/bin/uname + else + DKMLSYS_UNAME=/bin/uname + fi + fi + if [ -z "${DKMLSYS_ENV:-}" ]; then + if [ -x /usr/bin/env ]; then + DKMLSYS_ENV=/usr/bin/env + else + DKMLSYS_ENV=/bin/env + fi + fi + if [ -z "${DKMLSYS_AWK:-}" ]; then + if [ -x /usr/bin/awk ]; then + DKMLSYS_AWK=/usr/bin/awk + else + DKMLSYS_AWK=/bin/awk + fi + fi + if [ -z "${DKMLSYS_SED:-}" ]; then + if [ -x /usr/bin/sed ]; then + DKMLSYS_SED=/usr/bin/sed + else + DKMLSYS_SED=/bin/sed + fi + fi + if [ -z "${DKMLSYS_COMM:-}" ]; then + if [ -x /usr/bin/comm ]; then + DKMLSYS_COMM=/usr/bin/comm + else + DKMLSYS_COMM=/bin/comm + fi + fi + if [ -z "${DKMLSYS_INSTALL:-}" ]; then + if [ -x /usr/bin/install ]; then + DKMLSYS_INSTALL=/usr/bin/install + else + DKMLSYS_INSTALL=/bin/install + fi + fi + if [ -z "${DKMLSYS_RM:-}" ]; then + if [ -x /usr/bin/rm ]; then + DKMLSYS_RM=/usr/bin/rm + else + DKMLSYS_RM=/bin/rm + fi + fi + if [ -z "${DKMLSYS_SORT:-}" ]; then + if [ -x /usr/bin/sort ]; then + DKMLSYS_SORT=/usr/bin/sort + else + DKMLSYS_SORT=/bin/sort + fi + fi + if [ -z "${DKMLSYS_CAT:-}" ]; then + if [ -x /usr/bin/cat ]; then + DKMLSYS_CAT=/usr/bin/cat + else + DKMLSYS_CAT=/bin/cat + fi + fi + if [ -z "${DKMLSYS_STAT:-}" ]; then + if [ -x /usr/bin/stat ]; then + DKMLSYS_STAT=/usr/bin/stat + else + DKMLSYS_STAT=/bin/stat + fi + fi + if [ -z "${DKMLSYS_GREP:-}" ]; then + if [ -x /usr/bin/grep ]; then + DKMLSYS_GREP=/usr/bin/grep + else + DKMLSYS_GREP=/bin/grep + fi + fi + if [ -z "${DKMLSYS_CURL:-}" ]; then + if [ -x /usr/bin/curl ]; then + DKMLSYS_CURL=/usr/bin/curl + elif [ -x /bin/curl ]; then + DKMLSYS_CURL=/bin/curl + else + DKMLSYS_CURL= + fi + fi + if [ -z "${DKMLSYS_WGET:-}" ]; then + if [ -x /usr/bin/wget ]; then + DKMLSYS_WGET=/usr/bin/wget + elif [ -x /bin/wget ]; then + DKMLSYS_WGET=/bin/wget + else + DKMLSYS_WGET= + fi + fi + if [ -z "${DKMLSYS_TR:-}" ]; then + if [ -x /usr/bin/tr ]; then + DKMLSYS_TR=/usr/bin/tr + else + DKMLSYS_TR=/bin/tr + fi + fi + export DKMLSYS_MV DKMLSYS_CHMOD DKMLSYS_UNAME DKMLSYS_ENV DKMLSYS_AWK DKMLSYS_SED DKMLSYS_COMM DKMLSYS_INSTALL + export DKMLSYS_RM DKMLSYS_SORT DKMLSYS_CAT DKMLSYS_STAT DKMLSYS_GREP DKMLSYS_CURL DKMLSYS_WGET DKMLSYS_TR +} + +# Is a Windows build machine if we are in a MSYS2 or Cygwin environment. +# +# Better alternatives +# ------------------- +# +# 1. If you are checking to see if you should do a cygpath, then just guard it +# like so: +# if [ -x /usr/bin/cygpath ]; then +# do_something $(/usr/bin/cygpath ...) ... +# fi +# This clearly guards what you are about to do (cygpath) with what you will +# need (cygpath). +# 2. is_arg_windows_platform +is_unixy_windows_build_machine() { + if is_msys2_msys_build_machine || is_cygwin_build_machine; then + return 0 + fi + return 1 +} + +# Is a MSYS2 environment with the MSYS or MINGW64 subsystem? +# * MSYS2 can also do MinGW 32-bit and 64-bit subsystems. Used by Diskuv OCaml +# * MINGW64 used by Git Bash (aka. GitHub Actions `shell: bash`) +# https://www.msys2.org/docs/environments/ +is_msys2_msys_build_machine() { + if [ -e /usr/bin/msys-2.0.dll ] && { + [ "${MSYSTEM:-}" = "MSYS" ] || [ "${MSYSTEM:-}" = "MINGW64" ] || [ "${MSYSTEM:-}" = "UCRT64" ] || [ "${MSYSTEM:-}" = "CLANG64" ] || [ "${MSYSTEM:-}" = "MINGW32" ] || [ "${MSYSTEM:-}" = "CLANG32" ] || [ "${MSYSTEM:-}" = "CLANGARM64" ] + }; then + return 0 + fi + return 1 +} + +is_cygwin_build_machine() { + if [ -e /usr/bin/cygwin1.dll ]; then + return 0 + fi + return 1 +} + +# Tries to find the host ABI. +# +# Beware: This function uses `uname` probing which is inaccurate during +# cross-compilation. +# +# Outputs: +# - env:BUILDHOST_ARCH will contain the host ABI. +autodetect_buildhost_arch() { + # Set DKMLSYS_* + autodetect_system_binaries + + autodetect_buildhost_arch_SYSTEM=$("$DKMLSYS_UNAME" -s) + autodetect_buildhost_arch_MACHINE=$("$DKMLSYS_UNAME" -m) + # list from https://en.wikipedia.org/wiki/Uname and https://stackoverflow.com/questions/45125516/possible-values-for-uname-m + case "${autodetect_buildhost_arch_SYSTEM}-${autodetect_buildhost_arch_MACHINE}" in + Linux-armv7*) + BUILDHOST_ARCH=linux_arm32v7;; + Linux-armv6* | Linux-arm) + BUILDHOST_ARCH=linux_arm32v6;; + Linux-aarch64 | Linux-arm64 | Linux-armv8*) + BUILDHOST_ARCH=linux_arm64;; + Linux-i386 | Linux-i686) + BUILDHOST_ARCH=linux_x86;; + Linux-x86_64) + BUILDHOST_ARCH=linux_x86_64;; + Darwin-arm64) + BUILDHOST_ARCH=darwin_arm64;; + Darwin-x86_64) + BUILDHOST_ARCH=darwin_x86_64;; + *-i386 | *-i686) + if is_unixy_windows_build_machine; then + BUILDHOST_ARCH=windows_x86 + else + printf "%s\n" "FATAL: Unsupported build machine type obtained from 'uname -s' and 'uname -m': $autodetect_buildhost_arch_SYSTEM and $autodetect_buildhost_arch_MACHINE" >&2 + exit 1 + fi + ;; + *-x86_64) + if is_unixy_windows_build_machine; then + BUILDHOST_ARCH=windows_x86_64 + else + printf "%s\n" "FATAL: Unsupported build machine type obtained from 'uname -s' and 'uname -m': $autodetect_buildhost_arch_SYSTEM and $autodetect_buildhost_arch_MACHINE" >&2 + exit 1 + fi + ;; + *) + # Since: + # 1) MSYS2 does not run on ARM/ARM64 (https://www.msys2.org/docs/environments/) + # 2) MSVC does not use ARM/ARM64 as host machine (https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-160) + # we do not support Windows ARM/ARM64 as a build machine + printf "%s\n" "FATAL: Unsupported build machine type obtained from 'uname -s' and 'uname -m': $autodetect_buildhost_arch_SYSTEM and $autodetect_buildhost_arch_MACHINE" >&2 + exit 1 + ;; + esac +} + +# A function that will try to print an ISO8601 timestamp, but will fallback to +# the system default. Always uses UTC timezone. +try_iso8601_timestamp() { + date -u -Iseconds 2>/dev/null || TZ=UTC date +} + +# A function that will print the command and possibly time it (if and only if it uses a full path to +# an executable, so that 'time' does not fail on internal shell functions). +# If --return-error-code is the first argument or LOG_TRACE_RETURN_ERROR_CODE=ON, then instead of exiting the +# function will return the error code. +log_trace() { + log_trace_RETURN=${LOG_TRACE_RETURN_ERROR_CODE:-OFF} + + log_trace_1="$1" + if [ "$log_trace_1" = "--return-error-code" ]; then + shift + log_trace_RETURN=ON + fi + + if [ "${DKML_BUILD_TRACE:-OFF}" = ON ]; then + printf "[%s] %s\n" "$(try_iso8601_timestamp)" "+ $*" >&2 + if [ -x "$1" ]; then + time "$@" + else + "$@" + fi + else + # use judgement so we essentially have log at an INFO level + case "$1" in + rm|cp) + # debug level. only show when DKML_BUILD_TRACE=ON + ;; + git|make|ocaml_configure|ocaml_make|make_host|make_target) + # info level. and can show entire command without polluting the screen + printf "[%s] %s\n" "$(try_iso8601_timestamp)" "$*" >&2 + ;; + *) printf "[%s] %s\n" "$(try_iso8601_timestamp)" "$1" >&2 + esac + "$@" + fi + log_trace_ec="$?" + if [ "$log_trace_ec" -ne 0 ]; then + if [ "$log_trace_RETURN" = ON ]; then + return "$log_trace_ec" + else + printf "FATAL: Command failed with exit code %s: %s\n" "$log_trace_ec" "$*" >&2 + exit "$log_trace_ec" + fi + fi +} + +# [sha256compute FILE] writes the SHA256 checksum (hex encoded) of file FILE to the standard output. +sha256compute() { + sha256compute_FILE="$1" + shift + # For reasons unclear doing the following in MSYS2: + # sha256sum 'Z:\source\README.md' + # will produce a backslash like: + # \5518c76ed7234a153941fb7bc94b6e91d9cb8f1c4e22daf169a59b5878c3fc8a *Z:\\source\\README.md + # So always cygpath the filename if available + if [ -x /usr/bin/cygpath ]; then + sha256compute_FILE=$(/usr/bin/cygpath -a "$sha256compute_FILE") + fi + + if [ -x /usr/bin/shasum ]; then + /usr/bin/shasum -a 256 "$sha256compute_FILE" | awk '{print $1}' + elif [ -x /usr/bin/sha256sum ]; then + /usr/bin/sha256sum "$sha256compute_FILE" | awk '{print $1}' + else + printf "FATAL: %s\n" "No sha256 checksum utility found" >&2 + exit 107 + fi +} + +# [sha256check FILE SUM] checks that the file FILE has a SHA256 checksum (hex encoded) of SUM. +# The function will return nonzero (and exit with failure if `set -e` is enabled) if the checksum does not match. +sha256check() { + sha256check_FILE="$1" + shift + sha256check_SUM="$1" + shift + if [ -x /usr/bin/shasum ]; then + printf "%s %s" "$sha256check_SUM" "$sha256check_FILE" | /usr/bin/shasum -a 256 -c >&2 + elif [ -x /usr/bin/sha256sum ]; then + printf "%s %s" "$sha256check_SUM" "$sha256check_FILE" | /usr/bin/sha256sum -c >&2 + else + printf "FATAL: %s\n" "No sha256 checksum utility found" >&2 + exit 107 + fi +} + +# [downloadfile URL FILE SUM] downloads from URL into FILE and verifies the SHA256 checksum of SUM. +# If the FILE already exists with the correct checksum it is not redownloaded. +# The function will exit with failure if the checksum does not match. +downloadfile() { + downloadfile_URL="$1" + shift + downloadfile_FILE="$1" + shift + downloadfile_SUM="$1" + shift + + # Set DKMLSYS_* + autodetect_system_binaries + + if [ -e "$downloadfile_FILE" ]; then + if sha256check "$downloadfile_FILE" "$downloadfile_SUM"; then + return 0 + else + $DKMLSYS_RM -f "$downloadfile_FILE" + fi + fi + if [ "${CI:-}" = true ]; then + if [ -n "$DKMLSYS_CURL" ]; then + log_trace "$DKMLSYS_CURL" -L -s "$downloadfile_URL" -o "$downloadfile_FILE".tmp + elif [ -n "$DKMLSYS_WGET" ]; then + log_trace "$DKMLSYS_WGET" -q -O "$downloadfile_FILE".tmp "$downloadfile_URL" + else + echo "No curl or wget available on the system paths" >&2 + exit 107 + fi + else + if [ -n "$DKMLSYS_CURL" ]; then + log_trace "$DKMLSYS_CURL" -L "$downloadfile_URL" -o "$downloadfile_FILE".tmp + elif [ -n "$DKMLSYS_WGET" ]; then + log_trace "$DKMLSYS_WGET" -O "$downloadfile_FILE".tmp "$downloadfile_URL" + else + echo "No curl or wget available on the system paths" >&2 + exit 107 + fi + fi + if ! sha256check "$downloadfile_FILE".tmp "$downloadfile_SUM"; then + printf "%s\n" "FATAL: Encountered a corrupted or compromised download from $downloadfile_URL" >&2 + exit 1 + fi + $DKMLSYS_MV "$downloadfile_FILE".tmp "$downloadfile_FILE" +} + +# --- Environment detection --- + +# Set DKMLSYS_* +autodetect_system_binaries + +# Find host ABI. Set in BUILDHOST_ARCH +autodetect_buildhost_arch + +# Use the project tree as the current directory +PROJ_DIR=$(dirname "$0") +PROJ_DIR=$(cd "$PROJ_DIR" && pwd) +cd "$PROJ_DIR" + +# --- Tool directory selection --- + +tools_dir= +tools_name=dktool +# 1. Check if CI since many CI providers can only cache content in a subdirectory +# of the project. +if [ -z "$tools_dir" ] && [ "${CI:-}" = true ]; then + install -d "$PROJ_DIR/.tools" + tools_dir="$PROJ_DIR/.tools" +fi +# 2. Check in locations rooted under /opt/diskuv +# We look under a /opt/diskuv early because +# - Especially important for WSL2 to use a pure Linux filesystem (ext4) for +# best performance. +# - Using a canonical location (especially /opt/diskuv/usr/share) makes +# it easy to use CMake presets for non-Windows hosts. +if [ -z "$tools_dir" ] && [ -n "${XDG_DATA_HOME:-}" ] && [ -w "/opt/diskuv/$XDG_DATA_HOME" ]; then + install -d "/opt/diskuv/$XDG_DATA_HOME/$tools_name" + tools_dir="/opt/diskuv/$XDG_DATA_HOME/$tools_name" +fi +if [ -z "$tools_dir" ] && [ -n "${HOME:-}" ] && [ -w "/opt/diskuv/$HOME" ]; then + install -d "/opt/diskuv/$HOME/.local/share/$tools_name" + tools_dir="/opt/diskuv/$HOME/.local/share/$tools_name" +fi +if [ -z "$tools_dir" ] && [ -w "/opt/diskuv/usr/share" ]; then + install -d "/opt/diskuv/usr/share/$tools_name" + tools_dir="/opt/diskuv/usr/share/$tools_name" +fi +# 3. Check in the conventional locations rooted under / +if [ -z "$tools_dir" ] && [ -n "${XDG_DATA_HOME:-}" ] && [ -w "$XDG_DATA_HOME" ]; then + install -d "$XDG_DATA_HOME/$tools_name" + tools_dir="$XDG_DATA_HOME/$tools_name" +fi +if [ -z "$tools_dir" ] && [ -n "${HOME:-}" ] && [ -w "$HOME" ]; then + install -d "$HOME/.local/share/$tools_name" + tools_dir="$HOME/.local/share/$tools_name" +fi +# 4. Validate +if [ -z "$tools_dir" ]; then + echo "FATAL: Could not find a location to install the tools necessary for this project." >&2 + echo " ...: Make sure you have a home directory and that it is write-able, or define" >&2 + echo " ...: the environment variable XDG_DATA_HOME in a shell profile script after" >&2 + echo " ...: creating the \$XDG_DATA_HOME directory." >&2 + exit 2 +fi + +# --- Tool downloads and installs --- + +# PREREQS +# ------- + +install_linux_prog() { + install_linux_prog_NAME=$1 + shift + install_linux_prog_PKG=$1 + shift + if [ -x "/usr/bin/$install_linux_prog_NAME" ]; then + export DK_PROG_INSTALLED_LOCATION="/usr/bin/$install_linux_prog_NAME" + else + if command -v yum > /dev/null 2> /dev/null; then + if [ "$(id -u)" -eq 0 ]; then + yum install -y "$install_linux_prog_PKG" + else + echo "Running: sudo yum install -y $install_linux_prog_PKG" + sudo yum install -y "$install_linux_prog_PKG" + fi + else + if [ "$(id -u)" -eq 0 ]; then + apt-get -q install -y "$install_linux_prog_PKG" + else + echo "Running: sudo -q apt-get -qq install -y --no-install-suggests $install_linux_prog_PKG" + sudo apt-get -qq install -y --no-install-suggests "$install_linux_prog_PKG" + fi + fi + DK_PROG_INSTALLED_LOCATION=$(command -v "$install_linux_prog_NAME") + export DK_PROG_INSTALLED_LOCATION + fi +} + +get_homebrew_binary() { + get_homebrew_binary_NAME=$1 + shift + if command -v brew > /dev/null 2> /dev/null; then + get_homebrew_binary_PREFIX=$(brew --prefix) + if [ -x "$get_homebrew_binary_PREFIX/bin/$get_homebrew_binary_NAME" ]; then + export DK_PROG_INSTALLED_LOCATION="$get_homebrew_binary_PREFIX/bin/$get_homebrew_binary_NAME" + return 0 + fi + fi + return 1 +} + +install_macos_prog() { + install_macos_prog_NAME=$1 + shift + install_macos_prog_PKG=$1 + shift + if [ -x "/usr/bin/$install_macos_prog_NAME" ]; then + export DK_PROG_INSTALLED_LOCATION="/usr/bin/$install_macos_prog_NAME" + elif [ -x "/usr/local/bin/$install_macos_prog_NAME" ]; then + export DK_PROG_INSTALLED_LOCATION="/usr/local/bin/$install_macos_prog_NAME" + elif get_homebrew_binary "$install_macos_prog_NAME"; then + # DK_PROG_INSTALLED_LOCATION already set by [get_homebrew_binary] + true + else + if command -v brew > /dev/null 2> /dev/null; then + brew install --quiet --formula "$install_macos_prog_PKG" >&2 + get_homebrew_binary "$install_macos_prog_NAME" + # DK_PROG_INSTALLED_LOCATION already set by [get_homebrew_binary] + elif command -v port > /dev/null 2> /dev/null; then + if [ "$(id -u)" -eq 0 ]; then + port install "$install_macos_prog_PKG" + else + echo "Running: sudo port install $install_macos_prog_PKG" + sudo port install "$install_macos_prog_PKG" + fi + DK_PROG_INSTALLED_LOCATION=$(command -v "$install_macos_prog_NAME") + export DK_PROG_INSTALLED_LOCATION + else + echo "FATAL: Neither Homebrew nor MacPorts are available on your macOS. You can follow https://docs.brew.sh/Installation to install Homebrew." >&2 + exit 2 + fi + fi +} + +case $BUILDHOST_ARCH in + linux_*) + install_linux_prog wget wget # For [downloadfile] + install_linux_prog tar tar # For handling tar balls later in this script + ;; +esac + +# NINJA +# ----- +# We need a valid CMAKE_GENERATOR to do FetchContent_Populate() in script mode + +NINJA_EXE= +case $BUILDHOST_ARCH in + darwin_*) + install_macos_prog ninja ninja + NINJA_EXE=$DK_PROG_INSTALLED_LOCATION;; + linux_*) + install_linux_prog ninja ninja-build + NINJA_EXE=$DK_PROG_INSTALLED_LOCATION;; +esac + +# CMAKE +# ----- + +case $BUILDHOST_ARCH in + linux_*) + # This is for CMake to do FetchContent() + install_linux_prog git git ;; +esac +case $BUILDHOST_ARCH in + linux_x86) + # This is for Python wheel extraction + install_linux_prog unzip unzip ;; +esac + +cmake_base= +cmake_majmin_ver=3.25 +cmake_majminpat_ver=3.25.2 +cmake_bindir= +cmake_destdir=$tools_dir/cmake-$cmake_majminpat_ver +install -d "$tools_dir/dl" +download_cmake() { + case $BUILDHOST_ARCH in + darwin_*) + install_macos_prog cmake cmake + cmake_bindir=$(dirname "$DK_PROG_INSTALLED_LOCATION") + ;; + linux_x86_64) + cmake_base="cmake-$cmake_majminpat_ver-linux-x86_64" + printf "%s\n\n" "-- Downloading cmake-$cmake_majminpat_ver for Linux x86_64" >&2 + downloadfile \ + "https://github.com/Kitware/CMake/releases/download/v$cmake_majminpat_ver/$cmake_base.tar.gz" \ + "$tools_dir/dl/cmake.tar.gz" \ + 783da74f132fd1fea91b8236d267efa4df5b91c5eec1dea0a87f0cf233748d99 + cmake_bindir="$cmake_destdir/bin" ;; + linux_x86) + # CMake does not provide 32-bit binaries. But pypi does at https://pypi.org/project/cmake/ + printf "%s\n\n" "-- Downloading cmake-$cmake_majminpat_ver for Linux x86" >&2 + downloadfile \ + https://files.pythonhosted.org/packages/11/6e/aeeddf2f5b16542b6a30ceab4896421e8705d8e9a9296dba79395db11b00/cmake-3.25.2-py2.py3-none-manylinux_2_17_i686.manylinux2014_i686.whl \ + "$tools_dir/dl/cmake.whl" \ + 715ef82e81b48db3e4c7744614c15ff361d53f6987fd70b1b66b0880595f2e2c + cmake_bindir="$cmake_destdir/bin" ;; + linux_arm64) + cmake_base="cmake-$cmake_majminpat_ver-linux-aarch64" + printf "%s\n\n" "-- Downloading cmake-$cmake_majminpat_ver for Linux ARM64" >&2 + downloadfile \ + "https://github.com/Kitware/CMake/releases/download/v$cmake_majminpat_ver/$cmake_base.tar.gz" \ + "$tools_dir/dl/cmake.tar.gz" \ + 9216ecf0449ade700e66e0def11eeaebf9fa7d4428c02f49cb59f11418d3f8a5 + cmake_bindir="$cmake_destdir/bin" ;; + esac +} +export_cmake_vars() { + case $BUILDHOST_ARCH in + darwin_*) + if command -v brew > /dev/null 2> /dev/null; then + cmake_bindir=$(brew --prefix cmake)/bin + else + cmake_bindir=$(command -v cmake) + cmake_bindir=$(dirname "$cmake_bindir") + fi + ;; + linux_x86_64) + cmake_bindir="$cmake_destdir/bin" ;; + linux_x86) + cmake_bindir="$cmake_destdir/bin" ;; + esac +} +have_correct_cmake=0 +if [ -x "$tools_dir/cmake-$cmake_majminpat_ver/bin/cmake" ]; then + # shellcheck disable=SC2016 + have_correct_cmake_VER=$("$tools_dir/cmake-$cmake_majminpat_ver/bin/cmake" --version | $DKMLSYS_AWK 'NR==1{print $NF}') + if [ "$have_correct_cmake_VER" = "$cmake_majminpat_ver" ]; then + have_correct_cmake=1 + fi +fi +if [ $have_correct_cmake -eq 0 ]; then + download_cmake +fi +# Handle tarball +if [ -e "$tools_dir/dl/cmake.tar.gz" ] && [ -n "$cmake_base" ]; then + rm -rf "$tools_dir/cmake-$cmake_majminpat_ver" + install -d "$cmake_destdir" + tar xCfz "$cmake_destdir" "$tools_dir/dl/cmake.tar.gz" + rm -f "$tools_dir/dl/cmake.tar.gz" + set +f + if [ -e "$cmake_destdir/$cmake_base/CMake.app" ]; then + mv "$cmake_destdir/$cmake_base/CMake.app/Contents"/* "$cmake_destdir/" + else + mv "$cmake_destdir/$cmake_base"/* "$cmake_destdir/" + fi + set -f +fi +# Handle Python wheel +if [ -e "$tools_dir/dl/cmake.whl" ]; then + rm -rf "$tools_dir/cmake-$cmake_majminpat_ver" + cd "$tools_dir/dl" + rm -rf cmake/data + # Don't want cmake/data/{aclocal,bash-completion,emacs,vim} + unzip -q cmake.whl 'cmake/data/bin/**' + unzip -q cmake.whl 'cmake/data/doc/**' + # Don't want cmake/data/share/cmake-$cmake_majmin_ver/Help + unzip -q cmake.whl "cmake/data/share/cmake-$cmake_majmin_ver/"'include/**' + unzip -q cmake.whl "cmake/data/share/cmake-$cmake_majmin_ver/"'Modules/**' + unzip -q cmake.whl "cmake/data/share/cmake-$cmake_majmin_ver/"'Templates/**' + rm -f cmake.whl + cd - + set +f + install -d "$cmake_destdir/share" "$cmake_destdir/doc" "$cmake_destdir/bin" + mv "$tools_dir/dl/cmake/data/bin"/* "$cmake_destdir/bin/" + rm -rf "$cmake_destdir/share/cmake-$cmake_majmin_ver" "$cmake_destdir/doc/cmake-$cmake_majmin_ver" "$cmake_destdir/doc/cmake" + mv "$tools_dir/dl/cmake/data/share/cmake-$cmake_majmin_ver" "$cmake_destdir/share/" + if [ -e "$tools_dir/dl/cmake/data/doc/cmake" ]; then # Windows wheel + mv "$tools_dir/dl/cmake/data/doc/cmake" "$cmake_destdir/doc/" + fi + if [ -e "$tools_dir/dl/cmake/data/doc/cmake-$cmake_majmin_ver" ]; then # Linux wheel + mv "$tools_dir/dl/cmake/data/doc/cmake-$cmake_majmin_ver" "$cmake_destdir/doc/" + fi + set -f + # other dirs: aclocal bash-completion emacs vim + rm -rf "$tools_dir/dl/cmake/data/share" + # be pedantic. if we don't know about a directory, it may be important. so error + # if some directory is non-empty + rmdir "$tools_dir/dl/cmake/data/bin" "$tools_dir/dl/cmake/data/doc" + rmdir "$tools_dir/dl/cmake/data" +fi + +# Put tools in PATH +export_cmake_vars +if [ -n "$cmake_bindir" ] && [ -d "$cmake_bindir" ]; then + tools_bin_dir=$(cd "$cmake_bindir" && pwd) + export PATH="$tools_bin_dir:$PATH" +else + echo "This platform is not supported. No cmake 3.25+ download logic has been added" >&2 + exit 1 +fi + +# Validate +"$cmake_bindir/cmake" --version > /dev/null + +# --- Run finder script --- + +cd "$PROJ_DIR" +"$cmake_bindir/cmake" \ + -D CMAKE_GENERATOR=Ninja -D CMAKE_MAKE_PROGRAM="$NINJA_EXE" \ + -D "DKTOOL_PWD:FILEPATH=$dk_pwd" \ + -D "DKTOOL_WORKDIR:FILEPATH=$tools_dir/work" -D "DKTOOL_CMDLINE:STRING=$*" \ + -P cmake/FindDkToolScripts.cmake diff --git a/dk.cmd b/dk.cmd new file mode 100644 index 00000000..a523c9d2 --- /dev/null +++ b/dk.cmd @@ -0,0 +1,183 @@ +@ECHO OFF + +REM ########################################################################## +REM # File: dktool/dk.cmd # +REM # # +REM # Copyright 2023 Diskuv, Inc. # +REM # # +REM # Licensed under the Apache License, Version 2.0 (the "License"); # +REM # you may not use this file except in compliance with the License. # +REM # You may obtain a copy of the License at # +REM # # +REM # http://www.apache.org/licenses/LICENSE-2.0 # +REM # # +REM # Unless required by applicable law or agreed to in writing, software # +REM # distributed under the License is distributed on an "AS IS" BASIS, # +REM # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # +REM # implied. See the License for the specific language governing # +REM # permissions and limitations under the License. # +REM # # +REM ########################################################################## + +REM Recommendation: Place this file in source control. +REM Auto-generated by `./dk dksdk.project.new` of dktool. + +REM The canonical way to run this script is: ./dk +REM That works in Powershell on Windows, and in Unix. Copy-and-paste works! + +SETLOCAL + +REM Coding guidelines +REM 1. Microsoft way of getting around PowerShell permissions: +REM https://github.com/microsoft/vcpkg/blob/71422c627264daedcbcd46f01f1ed0dcd8460f1b/bootstrap-vcpkg.bat +REM 2. Write goto downward please so code flow is top to bottom. + +SET DK_CMAKE_VER=3.25.3 +SET DK_NINJA_VER=1.11.1 +SET DK_BUILD_TYPE=Release +SET DK_SHARE=%LOCALAPPDATA%\Programs\DkSDK\dktool +SET DK_PROJ_DIR=%~dp0 +SET DK_PWD=%CD% + +REM -------------- CMAKE -------------- + +REM Find CMAKE.EXE +where.exe /q cmake.exe >NUL 2>NUL +IF %ERRORLEVEL% neq 0 ( + goto FindDownloadedCMake +) +FOR /F "tokens=* usebackq" %%F IN (`where.exe cmake.exe`) DO ( + SET "DK_CMAKE_EXE=%%F" +) + +REM Check if present at /cmake-VER/bin/cmake.exe +:FindDownloadedCMake +IF EXIST %DK_SHARE%\cmake-%DK_CMAKE_VER%-windows-x86_64\bin\cmake.exe ( + SET "DK_CMAKE_EXE=%DK_SHARE%\cmake-%DK_CMAKE_VER%-windows-x86_64\bin\cmake.exe" + GOTO ValidateCMake +) + +REM Download CMAKE.EXE +bitsadmin /transfer dktool-cmake /download /priority FOREGROUND ^ + "https://github.com/Kitware/CMake/releases/download/v%DK_CMAKE_VER%/cmake-%DK_CMAKE_VER%-windows-x86_64.zip" ^ + "%TEMP%\cmake-%DK_CMAKE_VER%-windows-x86_64.zip" +IF %ERRORLEVEL% equ 0 ( + GOTO UnzipCMakeZip +) +REM Try PowerShell 3+ instead +powershell -NoProfile -ExecutionPolicy Bypass -Command ^ + "Invoke-WebRequest https://github.com/Kitware/CMake/releases/download/v%DK_CMAKE_VER%/cmake-%DK_CMAKE_VER%-windows-x86_64.zip -OutFile '%TEMP%\cmake-%DK_CMAKE_VER%-windows-x86_64.zip'" +IF %ERRORLEVEL% neq 0 ( + echo. + echo.Could not download CMake %DK_CMAKE_VER%. Make sure that PowerShell is installed + echo.and has not been disabled by a corporate policy. + echo. + EXIT /b 1 +) + +REM Unzip CMAKE.EXE (use PowerShell; could download unzip.exe and sha256sum.exe as well in case corporate policy) +:UnzipCMakeZip +powershell -NoProfile -ExecutionPolicy Bypass -Command ^ + "Expand-Archive '%TEMP%\cmake-%DK_CMAKE_VER%-windows-x86_64.zip' -DestinationPath '%DK_SHARE%'" +IF %ERRORLEVEL% neq 0 ( + echo. + echo.Could not unzip CMake %DK_CMAKE_VER%. Make sure that PowerShell is installed + echo.and has not been disabled by a corporate policy. + echo. + EXIT /b 1 +) +SET "DK_CMAKE_EXE=%DK_SHARE%\cmake-%DK_CMAKE_VER%-windows-x86_64\bin\cmake.exe" + +REM Validate cmake.exe +:ValidateCMake +"%DK_CMAKE_EXE%" -version >NUL 2>NUL +if %ERRORLEVEL% neq 0 ( + echo. + echo.%DK_CMAKE_EXE% + echo.is not responding to the -version option. Make sure that + echo.CMake is installed correctly. + echo. + exit /b 1 +) + +REM -------------- NINJA -------------- + +REM Find NINJA.EXE +where.exe /q ninja.exe >NUL 2>NUL +IF %ERRORLEVEL% neq 0 ( + goto FindDownloadedNinja +) +FOR /F "tokens=* usebackq" %%F IN (`where.exe ninja.exe`) DO ( + SET "DK_NINJA_EXE=%%F" +) + +REM Check if present at /ninja-VER/bin/ninja.exe +:FindDownloadedNinja +IF EXIST %DK_SHARE%\ninja-%DK_NINJA_VER%-windows-x86_64\bin\ninja.exe ( + SET "DK_NINJA_EXE=%DK_SHARE%\ninja-%DK_NINJA_VER%-windows-x86_64\bin\ninja.exe" + GOTO ValidateNinja +) + +REM Download NINJA.EXE +bitsadmin /transfer dktool-ninja /download /priority FOREGROUND ^ + "https://github.com/ninja-build/ninja/releases/download/v%DK_NINJA_VER%/ninja-win.zip" ^ + "%TEMP%\ninja-%DK_NINJA_VER%-windows-x86_64.zip" +IF %ERRORLEVEL% equ 0 ( + GOTO UnzipNinjaZip +) +REM Try PowerShell 3+ instead +powershell -NoProfile -ExecutionPolicy Bypass -Command ^ + "Invoke-WebRequest https://github.com/ninja-build/ninja/releases/download/v%DK_NINJA_VER%/ninja-win.zip -OutFile '%TEMP%\ninja-%DK_NINJA_VER%-windows-x86_64.zip'" +IF %ERRORLEVEL% neq 0 ( + echo. + echo.Could not download Ninja %DK_NINJA_VER%. Make sure that PowerShell is installed + echo.and has not been disabled by a corporate policy. + echo. + EXIT /b 1 +) + +REM Unzip NINJA.EXE (use PowerShell; could download unzip.exe and sha256sum.exe as well in case corporate policy) +:UnzipNinjaZip +powershell -NoProfile -ExecutionPolicy Bypass -Command ^ + "Expand-Archive '%TEMP%\ninja-%DK_NINJA_VER%-windows-x86_64.zip' -DestinationPath '%DK_SHARE%\ninja-%DK_NINJA_VER%-windows-x86_64\bin'" +IF %ERRORLEVEL% neq 0 ( + echo. + echo.Could not unzip Ninja %DK_NINJA_VER%. Make sure that PowerShell is installed + echo.and has not been disabled by a corporate policy. + echo. + EXIT /b 1 +) +SET "DK_NINJA_EXE=%DK_SHARE%\ninja-%DK_NINJA_VER%-windows-x86_64\bin\ninja.exe" + +REM Validate ninja.exe +:ValidateNinja +"%DK_NINJA_EXE%" --version >NUL 2>NUL +if %ERRORLEVEL% neq 0 ( + echo. + echo.%DK_NINJA_EXE% + echo.is not responding to the --version option. Make sure that + echo.Ninja is installed correctly. + echo. + exit /b 1 +) + +REM -------------- DkML PATH --------- +REM We get "git-sh-setup: file not found" in Git for Windows because +REM Command Prompt has the "Path" environment variable, while PowerShell +REM and `with-dkml` use the PATH environment variable. Sadly both +REM can be present in Command Prompt at the same time. Git for Windows +REM (called by FetchContent in CMake) does not comport with what Command +REM Prompt is using. So we let Command Prompt be the source of truth by +REM removing any duplicated PATH twice and resetting to what Command Prompt +REM thinks the PATH is. + +SET _DK_PATH=%PATH% +SET PATH= +SET PATH= +SET PATH=%_DK_PATH% +SET _DK_PATH= + +REM -------------- Run finder -------------- + +cd /d %DK_PROJ_DIR% +"%DK_CMAKE_EXE%" -D CMAKE_GENERATOR=Ninja -D "CMAKE_MAKE_PROGRAM=%DK_NINJA_EXE%" -D "DKTOOL_PWD:FILEPATH=%DK_PWD%" -D "DKTOOL_WORKDIR:FILEPATH=%DK_SHARE%\work" -D "DKTOOL_CMDLINE:STRING=%*" -P cmake/FindDkToolScripts.cmake