Skip to content

Commit 2b3c1aa

Browse files
committed
Improve build script
Mostly Windows fixes
1 parent e097731 commit 2b3c1aa

9 files changed

Lines changed: 136 additions & 27 deletions

File tree

hadrian/src/Builder.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,14 @@ instance H.Builder Builder where
333333
cmd' [Cwd dir] [bash, path] buildArgs
334334

335335
Configure dir -> do
336-
-- Inject /bin/bash into `libtool`, instead of /bin/sh,
337-
-- otherwise Windows breaks. TODO: Figure out why.
338-
bash <- bashPath
339-
let env = AddEnv "CONFIG_SHELL" bash
340-
cmd' env [Cwd dir] ["sh", path] buildOptions buildArgs
336+
-- Note: we intentionally do NOT set CONFIG_SHELL here.
337+
-- Setting it causes autoconf's configure to re-exec under
338+
-- the specified shell, and on Windows this spawns a new
339+
-- MSYS2 process whose runtime may pull in conflicting
340+
-- tools (e.g. Git for Windows' expr with a different
341+
-- msys-2.0.dll) via the Windows system PATH, breaking
342+
-- autoconf's BRE-based option parsing.
343+
cmd' [Cwd dir] ["sh", path] buildOptions buildArgs
341344

342345
GenApply -> captureStdout
343346

hadrian/src/Rules/Libffi.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ fixLibffiMakefile top =
124124
replace "-MD" "-MMD"
125125
. replace "@toolexeclibdir@" "$(libdir)"
126126
. replace "@INSTALL@" ("$(subst ../install-sh," ++ top ++ "/install-sh,@INSTALL@)")
127+
-- Remove 'man' from SUBDIRS to avoid broken man page installation on
128+
-- MSYS2/Windows where the automake sed pipeline in install-man3 fails.
129+
. replace "SUBDIRS = include testsuite man" "SUBDIRS = include testsuite"
127130

128131
-- TODO: check code duplication w.r.t. ConfCcArgs
129132
configureEnvironment :: Stage -> Action [CmdOption]

hadrian/src/Settings/Builders/Configure.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ configureBuilderArgs = do
3636
++ (if wayUnit Dynamic way
3737
then "yes"
3838
else "no")
39+
, "--disable-multi-os-directory"
40+
, "--disable-docs"
3941
, "--host=" ++ targetPlatform ] ]

mk/get-win32-tarballs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,39 @@
33

44
from pathlib import Path
55
import urllib.request
6+
import ssl
67
import subprocess
78
import argparse
89
import sys
910
from sys import stderr
1011

12+
# On Windows (MSYS2/MinGW), Python's bundled OpenSSL may not find
13+
# system CA certificates. Build a context that tries multiple sources.
14+
def _make_ssl_context():
15+
ctx = ssl.create_default_context()
16+
if ctx.cert_store_stats()['x509_ca'] > 0:
17+
return ctx
18+
import os
19+
# Try common CA bundle locations (Windows paths for native Python)
20+
candidates = [os.environ.get('SSL_CERT_FILE', '')]
21+
# Add Git for Windows and MSYS2 paths
22+
for prefix in ['C:/Program Files/Git', 'C:/msys64']:
23+
candidates.append(prefix + '/mingw64/etc/ssl/certs/ca-bundle.crt')
24+
candidates.append(prefix + '/usr/ssl/certs/ca-bundle.crt')
25+
for ca in candidates:
26+
if ca and os.path.isfile(ca):
27+
try:
28+
ctx.load_verify_locations(ca)
29+
return ctx
30+
except Exception:
31+
pass
32+
return ctx
33+
34+
_ssl_ctx = _make_ssl_context()
35+
_https_handler = urllib.request.HTTPSHandler(context=_ssl_ctx)
36+
_opener = urllib.request.build_opener(_https_handler)
37+
urllib.request.install_opener(_opener)
38+
1139
TARBALL_VERSION = '0.8'
1240
BASE_URL = "https://downloads.haskell.org/ghc/mingw/{}".format(TARBALL_VERSION)
1341
DEST = Path('ghc-tarballs/mingw-w64')

plinth-build.sh

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,26 @@ set -euo pipefail
33
LOCAL_HAPPY="$PWD/_build/tools/happy"
44
LOCAL_ALEX="$PWD/_build/tools/alex"
55

6+
UNAME_S=$(uname -s)
7+
case "$UNAME_S" in
8+
MINGW*|MSYS*) IS_WINDOWS=1; EXE_EXT=".exe" ;;
9+
*) IS_WINDOWS=0; EXE_EXT="" ;;
10+
esac
11+
612
RELEASE_HADRIAN_ARGS=""
713
DEV_HADRIAN_ARGS="--docs=none"
8-
RELEASE_CONFIGURE_ARGS="--enable-tarballs-autodownload"
9-
DEV_CONFIGURE_ARGS="--enable-tarballs-autodownload"
14+
RELEASE_FLAVOUR="release"
15+
DEV_FLAVOUR="release+debug_info+debug_ghc+assertions"
16+
17+
# platform-specific default configure arguments
18+
case "$UNAME_S" in
19+
MINGW*|MSYS*) DEFAULT_CONFIGURE_ARGS="--enable-tarballs-autodownload" ;;
20+
Darwin*) DEFAULT_CONFIGURE_ARGS="--with-intree-gmp" ;;
21+
*) DEFAULT_CONFIGURE_ARGS="" ;;
22+
esac
23+
24+
RELEASE_CONFIGURE_ARGS="$DEFAULT_CONFIGURE_ARGS"
25+
DEV_CONFIGURE_ARGS="$DEFAULT_CONFIGURE_ARGS"
1026

1127
####################################################################
1228
# edit configuration here:
@@ -15,16 +31,18 @@ DEV_CONFIGURE_ARGS="--enable-tarballs-autodownload"
1531
: ${RELEASE:=0} # set to 1 to build release version including documentation (more build dependencies)
1632

1733
# program locations
18-
: ${GHC:=$(which ghc-9.6.7 2>/dev/null || true)}
19-
: ${CABAL:=$(which cabal 2>/dev/null || true)}
20-
: ${HAPPY:=$( [ -x "$LOCAL_HAPPY" ] && echo "$LOCAL_HAPPY" || which happy-1.20.1.1 2>/dev/null || true)}
21-
: ${ALEX:=$( [ -x "$LOCAL_ALEX" ] && echo "$LOCAL_ALEX" || which alex 2>/dev/null || true)}
22-
: ${TAR:=$(which tar 2>/dev/null || true)}
23-
: ${XZ:=$(which xz 2>/dev/null || true)}
34+
: ${GHC:=$(command -v ghc-9.6.7 2>/dev/null || true)}
35+
: ${CABAL:=$(command -v cabal 2>/dev/null || true)}
36+
: ${PYTHON:=$(command -v python3 2>/dev/null || true)}
37+
: ${HAPPY:=$( [ -x "$LOCAL_HAPPY" ] && echo "$LOCAL_HAPPY" || command -v happy-1.20.1.1 2>/dev/null || true)}
38+
: ${ALEX:=$( [ -x "$LOCAL_ALEX" ] && echo "$LOCAL_ALEX" || command -v alex 2>/dev/null || true)}
39+
: ${TAR:=$(command -v tar 2>/dev/null || true)}
40+
: ${XZ:=$(command -v xz 2>/dev/null || true)}
2441

2542
# override default arguments
2643
: ${HADRIAN_ARGS:=$( [ "$RELEASE" -eq 1 ] && echo "$RELEASE_HADRIAN_ARGS" || echo "$DEV_HADRIAN_ARGS" )}
2744
: ${CONFIGURE_ARGS:=$( [ "$RELEASE" -eq 1 ] && echo "$RELEASE_CONFIGURE_ARGS" || echo "$DEV_CONFIGURE_ARGS" )}
45+
: ${FLAVOUR:=$( [ "$RELEASE" -eq 1 ] && echo "$RELEASE_FLAVOUR" || echo "$DEV_FLAVOUR" )}
2846

2947
# end configuration
3048
####################################################################
@@ -74,17 +92,23 @@ if [ -z "$XZ" ] || [ ! -x "$XZ" ]; then
7492
echo "xz not found"
7593
exit 1
7694
fi
95+
if [ -z "$PYTHON" ] || [ ! -x "$PYTHON" ]; then
96+
echo "python3 not found"
97+
exit 1
98+
fi
7799

78100
export GHC
79101
export CABAL
80102
export HAPPY
81103
export ALEX
104+
export PYTHON
82105

83106
echo "using tools: "
84107
echo " GHC: $GHC"
85108
echo " cabal: $CABAL ($CABAL_VERSION)"
86109
echo " happy: $HAPPY"
87110
echo " alex: $ALEX"
111+
echo " python: $PYTHON"
88112
echo " tar: $TAR"
89113
echo " xz: $XZ"
90114

@@ -99,15 +123,37 @@ if [ ! -d plutus/plutus-tx ]; then
99123
exit 1
100124
fi
101125
# build boot GHC
126+
DID_BOOT_OR_CONFIGURE=0
102127
if [ ! -x ./configure ] || [ "$REBUILD" -eq 1 ]; then
128+
echo "booting..."
103129
./boot
130+
DID_BOOT_OR_CONFIGURE=1
104131
fi
105132
if [ ! -e ./mk/config.h ] || [ "$REBUILD" -eq 1 ]; then
133+
echo "configuring..."
134+
(
135+
# On Windows/MinGW64, ensure we use the CA bundle from MSYS2 to avoid SSL errors when downloading tarballs
136+
if [ "$IS_WINDOWS" -eq 1 ]; then
137+
export SSL_CERT_FILE="$(cygpath -w /mingw64/etc/ssl/certs/ca-bundle.crt)"
138+
fi
106139
./configure $CONFIGURE_ARGS
140+
)
141+
DID_BOOT_OR_CONFIGURE=1
142+
fi
143+
144+
# On Windows, plinth/ghc may not be a a real symlink, recreate it to
145+
# prevent it from becoming stale.
146+
if [ "$DID_BOOT_OR_CONFIGURE" -eq 1 ] && [ "$IS_WINDOWS" -eq 1 ] && [ -d plinth/ghc ] && [ ! -L plinth/ghc ]; then
147+
echo "re-creating plinth/ghc symlink..."
148+
rm -rf plinth/ghc
149+
ln -s ../ghc plinth/ghc
107150
fi
108151

109152
if [ ! -x ./_build/stage1/bin/ghc ] || [ "$REBUILD" -eq 1 ]; then
110-
./hadrian/build -j --flavour=release $HADRIAN_ARGS binary-dist
153+
echo "building..."
154+
echo "./hadrian/build -j --flavour=$FLAVOUR $HADRIAN_ARGS binary-dist"
155+
156+
./hadrian/build -j --flavour=$FLAVOUR $HADRIAN_ARGS binary-dist
111157
fi
112158

113159
# build Plinth GHC
@@ -129,20 +175,31 @@ CABAL_BUILD_ARGS="\
129175
--builddir=_build/${STAGE}/${TARGET_PLATFORM} \
130176
--ghc-options=\"-fhide-source-paths\""
131177

178+
# On Windows/MinGW64, ensure we use Git for Windows (not MSYS2 git) and
179+
# prevent git from hanging on interactive credential/host-key prompts
180+
# when called as a subprocess by cabal.
181+
if [ "$IS_WINDOWS" -eq 1 ]; then
182+
if [ -d "/c/Program Files/Git/bin" ]; then
183+
export PATH="/c/Program Files/Git/bin:$PATH"
184+
fi
185+
export GIT_TERMINAL_PROMPT=0
186+
export GIT_CONFIG_COUNT=1
187+
export GIT_CONFIG_KEY_0="core.longpaths"
188+
export GIT_CONFIG_VALUE_0="true"
189+
fi
190+
132191
(
192+
echo "building uplc-ghc"
133193
cd plinth
194+
echo "cabal update..."
134195
"$CABAL" ${CABAL_PROJECT_ARGS} ${CABAL_ARGS} update
196+
echo "cabal build..."
135197
"$CABAL" ${CABAL_PROJECT_ARGS} ${CABAL_ARGS} build ${CABAL_BUILD_ARGS} ghc:ghc
136198
)
137199

138200
# add uplc-ghc to the _build dir and the bindists
139201
CWRAPPER_DIR="$BASE/hadrian/bindist/cwrappers"
140202

141-
case "$TARGET_PLATFORM" in
142-
*-mingw32|*-windows) IS_WINDOWS=1; EXE_EXT=".exe" ;;
143-
*) IS_WINDOWS=0; EXE_EXT="" ;;
144-
esac
145-
146203
DEST_UPLC_GHC="$BASE/_build/stage1/bin/uplc-ghc${EXE_EXT}"
147204

148205
(

plinth-test.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ set -euo pipefail
66

77
# build Plinth test project
88

9-
GHC="$PWD/_build/stage1/bin/uplc-ghc"
9+
UNAME_S=$(uname -s)
10+
11+
case "$UNAME_S" in
12+
MINGW*|MSYS*) EXE_EXT=".exe" ;;
13+
*) EXE_EXT="" ;;
14+
esac
15+
16+
GHC="$PWD/_build/stage1/bin/uplc-ghc${EXE_EXT}"
1017

1118
if [ ! -x "$GHC" ]; then
12-
echo "Plinth GHC not found. Please run build-plinth.sh first."
19+
echo "Plinth GHC not found. Please run plinth-build.sh first."
1320
exit 1
1421
fi
1522

23+
case "$UNAME_S" in
24+
MINGW*|MSYS*) GHC=$(cygpath -w "$GHC") ;;
25+
esac
26+
1627
CABAL_PROJECT_ARGS="--project-file=cabal.project"
1728

1829
CABAL_ARGS="\
@@ -30,7 +41,8 @@ CABAL_BUILD_ARGS="\
3041
if [ "$CLEAN" -eq 1 ]; then
3142
rm -rf _build
3243
fi
44+
echo "Building Plinth test project... current dir: $(pwd)"
3345
cabal ${CABAL_PROJECT_ARGS} ${CABAL_ARGS} update
3446
cabal ${CABAL_PROJECT_ARGS} ${CABAL_ARGS} build ${CABAL_BUILD_ARGS} .
35-
cabal ${CABAL_PROJECT_ARGS} ${CABAL_ARGS} run gen-examples
36-
)
47+
cabal ${CABAL_PROJECT_ARGS} ${CABAL_ARGS} run ${CABAL_BUILD_ARGS} gen-examples
48+
)

plinth/plutus-tx-plugin/plutus-tx-plugin.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cabal-version: 3.0
2-
name: plutus-tx-plugin-stub
2+
name: plutus-tx-plugin
33
version: 1.57.0.0
44
license: Apache-2.0
55
license-files:
@@ -47,7 +47,7 @@ common ghc-version-support
4747
buildable: False
4848

4949
common os-support
50-
if (impl(ghcjs) || os(windows))
50+
if impl(ghcjs)
5151
buildable: False
5252

5353
library

plinth/test/cabal.project

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ index-state:
1717

1818
packages:
1919
./.
20-
../plutus-tx-plugin/plutus-tx-plugin.cabal
20+
../plutus-tx-plugin
2121

2222
optional-packages:
2323
../../plutus/plutus-tx
@@ -50,6 +50,7 @@ source-repository-package
5050
location: https://github.com/haskell-cryptography/secp256k1-clib
5151
tag: 211b95baad422966c9e719ed70cbc189c58eaae5
5252

53+
5354
package secp256k1-clib
5455
flags: +schnorrsig +recovery +ecdh +extrakeys
5556

@@ -59,3 +60,4 @@ package sodium-clib
5960
-- and the link phase fails with cryptic error messages.
6061
configure-options: --enable-pie=no
6162

63+
constraints: mempack == 0.1.2.0

rts/Linker.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ int ghciInsertSymbolTable(
381381
: pinfo->owner->fileName
382382
);
383383

384-
return 0;
384+
return 1;
385+
386+
// return 0;
385387
}
386388

387389
/* -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)