Skip to content

Commit 303c873

Browse files
authored
Merge pull request #3674 from mtzguido/win_prepare
Preparing for a native Windows build
2 parents 27da2e0 + f980983 commit 303c873

21 files changed

Lines changed: 315 additions & 142 deletions

.github/workflows/build-linux.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defaults:
1212
shell: bash
1313

1414
jobs:
15-
build:
15+
build-linux:
1616
runs-on: ubuntu-22.04
1717
# We prefer slightly older Ubuntu so we get binaries that work on
1818
# all more recent versions.
@@ -37,6 +37,7 @@ jobs:
3737
echo FSTAR_VERSION="nightly-$(date -I)" >> $GITHUB_ENV
3838
elif [[ "${{github.workflow_ref}}" =~ "release.yml" ]]; then
3939
echo FSTAR_VERSION="$(cat version.txt)" >> $GITHUB_ENV
40+
echo FSTAR_RELEASE=1 >> $GITHUB_ENV
4041
fi
4142
4243
# NB: release workflow later adds version number to the name
@@ -45,8 +46,10 @@ jobs:
4546
eval $(opam env)
4647
KERNEL=$(uname -s)
4748
ARCH=$(uname -m)
48-
make -skj$(nproc) package FSTAR_TAG=-$KERNEL-$ARCH
49+
export FSTAR_TAG=-$KERNEL-$ARCH
50+
make -skj$(nproc) package
4951
make -skj$(nproc) package-src FSTAR_TAG=
52+
# ^ no tag in source package
5053
5154
- uses: actions/upload-artifact@v4
5255
with:

.github/workflows/build-macos.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
workflow_call:
66

77
jobs:
8-
build:
8+
build-macos:
99
runs-on: macos-latest
1010
steps:
1111
- uses: actions/checkout@master
@@ -29,6 +29,7 @@ jobs:
2929
echo FSTAR_VERSION="nightly-$(date -I)" >> $GITHUB_ENV
3030
elif [[ "${{github.workflow_ref}}" =~ "release.yml" ]]; then
3131
echo FSTAR_VERSION="$(cat version.txt)" >> $GITHUB_ENV
32+
echo FSTAR_RELEASE=1 >> $GITHUB_ENV
3233
fi
3334
3435
# Note *g*make below!
@@ -38,7 +39,8 @@ jobs:
3839
eval $(opam env)
3940
KERNEL=$(uname -s)
4041
ARCH=$(uname -m)
41-
gmake -skj$(nproc) package FSTAR_TAG=-$KERNEL-$ARCH
42+
export FSTAR_TAG=-$KERNEL-$ARCH
43+
gmake -skj$(nproc) package
4244
4345
- uses: actions/upload-artifact@v4
4446
with:

.scripts/bin-install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# This is called by the Makefile *after* an installation into the
4+
# prefix, so we add the rest of the files that go into a binary package.
5+
6+
set -eu
7+
8+
windows () {
9+
# This seems portable enough and does not trigger an
10+
# undefined variable error (see set -u above) if $OS
11+
# is unset (like in linux/mac). Note: OSX's bash is usually
12+
# old and does not support '[ -v OS ]'.
13+
[[ "${OS:-}" = "Windows_NT" ]]
14+
}
15+
16+
if [ $# -ne 1 ]; then
17+
echo "Usage: $0 <prefix>" >&2
18+
exit 1
19+
fi
20+
21+
PREFIX="$1"
22+
mkdir -p "$PREFIX"
23+
PREFIX="$(realpath "$PREFIX")"
24+
25+
if ! [ -v FSTAR_PACKAGE_Z3 ] || ! [ "$FSTAR_PACKAGE_Z3" = false ]; then
26+
.scripts/package_z3.sh "$PREFIX"
27+
fi
28+
29+
if windows; then
30+
# This dll is needed. It must be installed if we're packaging, as we
31+
# must have run F* already, but it should probably be obtained from
32+
# somewhere else..
33+
LIBGMP=$(which libgmp-10.dll) || echo "error: libgmp-10.dll not found! Carrying on..." >&2
34+
cp "$LIBGMP" "$PREFIX/bin"
35+
fi
36+
37+
# License and extra files. Not there on normal installs, but present in
38+
# package.
39+
cp LICENSE* "$PREFIX"
40+
cp README.md "$PREFIX"
41+
cp INSTALL.md "$PREFIX"
42+
cp version.txt "$PREFIX"
43+
44+
# Save the megabytes! Strip binaries
45+
STRIP=strip
46+
47+
if windows; then
48+
STRIP="$(pwd)/mk/winwrap.sh $STRIP"
49+
fi
50+
51+
$STRIP "$PREFIX"/bin/* || true
52+
$STRIP "$PREFIX"/lib/fstar/z3-*/bin/* || true

.scripts/check-snapshot-diff.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

.scripts/get_fstar_z3.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ download_z3() {
6060
z3_path="${base_name%.zip}/bin/z3"
6161
if [ "$kernel" = Windows ]; then z3_path="$z3_path.exe"; fi
6262

63-
pushd "$tmp_dir"
64-
curl -L "$url" -o "$base_name"
63+
pushd "$tmp_dir" > /dev/null
64+
curl -s -L "$url" -o "$base_name"
6565

6666
unzip -q "$base_name" "$z3_path"
67-
popd
67+
popd > /dev/null
6868
install -m0755 "$tmp_dir/$z3_path" "$destination_file_name"
6969
echo ">>> Installed Z3 $version to $destination_file_name"
7070
}
@@ -77,17 +77,17 @@ full_install_z3() {
7777
dest_dir="$3"
7878

7979
mkdir -p "$dest_dir/z3-$version"
80-
pushd "$dest_dir/z3-$version"
80+
pushd "$dest_dir/z3-$version" > /dev/null
8181

8282
echo ">>> Downloading Z3 $version from $url ..."
8383
base_name="$(basename "$url")"
84-
curl -L "$url" -o "$base_name"
84+
curl -s -L "$url" -o "$base_name"
8585

8686
unzip -q "$base_name"
8787
mv "${base_name%.zip}"/* .
8888
rmdir "${base_name%.zip}"
8989
rm "$base_name"
90-
popd
90+
popd > /dev/null
9191
}
9292

9393
usage() {

.scripts/make_fstar_version.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env bash
22

3+
windows () {
4+
[[ "${OS:-}" = "Windows_NT" ]]
5+
}
6+
37
if [[ -z "$FSTAR_VERSION" ]]; then
48
FSTAR_VERSION=$(head -n 1 version.txt)~dev
59
fi
610

7-
if [ "$OS" = "Windows_NT" ]
8-
then
11+
if windows; then
912
if [ "$PROCESSOR_ARCHITECTURE" = "AMD64" ]
1013
then
1114
PLATFORM="Windows_x64"

.scripts/mk-package.sh

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,117 @@
11
#!/bin/bash
22

3+
set -eu
4+
5+
# This will just create a tar.gz or zip out of a directory.
6+
# You may want to look at src-install.sh and bin-install.sh
7+
# that generate the layouts for a source and binary package,
8+
# and are then packaged up with this script.
9+
310
if [ $# -ne 2 ]; then
4-
echo "usage: $0 <install_root> <package_basename>" >&2
5-
echo "Default format is tar.gz. Optionally set FSTAR_PACKAGE_FORMAT=zip to generate a zip instead." >&2
6-
echo "Output filename is <package_basename> + proper extension." >&2
7-
exit 1
11+
exec >&2
12+
echo "usage: $0 <install_root> <package_basename>"
13+
echo "The archive format and command used depends on the system and installed tools,"
14+
echo "see script for details."
15+
echo "Optionally set FSTAR_PACKAGE_FORMAT to: "
16+
echo " - 'zip': create a .zip via 'zip' command"
17+
echo " - '7z': create a .zip via '7z' command"
18+
echo " - 'tar.gz': create a .tar.gz, via calling"
19+
echo "Output filename is <package_basename> + proper extension"
20+
echo "If FSTAR_RELEASE is non-empty, we use maximum compression."
21+
exit 1
822
fi
923

1024
PREFIX="$1"
1125
ARCHIVE="$2"
1226

27+
windows () {
28+
# This seems portable enough and does not trigger an
29+
# undefined variable error (see set -u above) if $OS
30+
# is unset (like in linux/mac). Note: OSX's bash is usually
31+
# old and does not support '[ -v OS ]'.
32+
[[ "${OS:-}" = "Windows_NT" ]]
33+
}
34+
35+
release () {
36+
[[ -n "${FSTAR_RELEASE:-}" ]]
37+
}
38+
39+
# Computes a (hopefully) sensible default for the current system
40+
detect_format () {
41+
if windows; then
42+
# Github actions runner do not have 'zip'
43+
if which zip > /dev/null; then
44+
FSTAR_PACKAGE_FORMAT=zip
45+
elif which 7z > /dev/null; then
46+
FSTAR_PACKAGE_FORMAT=7z
47+
else
48+
echo "error: no zip or 7z command found." >&2
49+
exit 1
50+
fi
51+
else
52+
FSTAR_PACKAGE_FORMAT=tar.gz
53+
fi
54+
}
55+
56+
# If unset, pick a default for the system.
57+
if ! [ -v FSTAR_PACKAGE_FORMAT ]; then
58+
detect_format
59+
fi
60+
61+
# Fix for stupid path confustion in windows
62+
if windows; then
63+
WRAP=$(pwd)/mk/winwrap.sh
64+
else
65+
WRAP=
66+
fi
67+
1368
case $FSTAR_PACKAGE_FORMAT in
1469
zip)
1570
TGT="$ARCHIVE.zip"
16-
TGT="$(realpath "$TGT")"
17-
pushd "$PREFIX"
18-
zip -q -r -9 "$TGT" .
19-
popd
71+
ATGT="$(realpath "$TGT")"
72+
pushd "$PREFIX" >/dev/null
73+
LEVEL=
74+
if release; then
75+
LEVEL=-9
76+
fi
77+
$WRAP zip -q -r $LEVEL "$ATGT" .
78+
popd >/dev/null
79+
;;
80+
7z)
81+
TGT="$ARCHIVE.zip"
82+
ATGT="$(realpath "$TGT")"
83+
LEVEL=
84+
if release; then
85+
LEVEL=-mx9
86+
fi
87+
pushd "$PREFIX" >/dev/null
88+
$WRAP 7z $LEVEL a "$ATGT" .
89+
popd >/dev/null
2090
;;
21-
tar.gz|tgz|"")
91+
tar.gz|tgz)
2292
# -h: resolve symlinks
23-
tar czf "$ARCHIVE.tar.gz" -h -C "$PREFIX" .
93+
TGT="$ARCHIVE.tar.gz"
94+
$WRAP tar cf "$ARCHIVE.tar" -h -C "$PREFIX" .
95+
LEVEL=
96+
if release; then
97+
LEVEL=-9
98+
fi
99+
$WRAP gzip -f $LEVEL "$ARCHIVE.tar"
24100
;;
25101
*)
26102
echo "unrecognized FSTAR_PACKAGE_FORMAT: $FSTAR_PACKAGE_FORMAT" >&2
27103
exit 1
28104
;;
29105
esac
106+
107+
if ! [ -f "$TGT" ] ; then
108+
echo "error: something seems wrong, archive '$TGT' not found?" >&2
109+
exit 1
110+
fi
111+
112+
# bytes=$(stat -c%s "$TGT")
113+
# echo "Wrote $TGT" ($bytes bytes)"
114+
# ^ Does not work in Mac (no -c option for stat)
115+
116+
echo "Wrote $TGT"
117+
ls -l "$TGT" || true

.scripts/package_z3.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#!/bin/bash
22

3-
PREFIX="$(realpath -m "$1")" # -m: leading dirs allowed to not exist
3+
PREFIX="$1"
4+
mkdir -p "$PREFIX"
5+
PREFIX="$(realpath "$PREFIX")"
6+
47
D="$(dirname "$0")"
58

69
mkdir -p "$PREFIX"/lib/fstar
710

811
TMP=$(mktemp -d)
912
$D/get_fstar_z3.sh --full "$TMP"
1013

11-
pushd "$TMP"
14+
pushd "$TMP" > /dev/null
1215

1316
inst1 () {
1417
TGT="$PREFIX/lib/fstar/$1"
@@ -21,6 +24,6 @@ inst1 ./z3-4.8.5/LICENSE.txt
2124
inst1 ./z3-4.13.3/bin/z3
2225
inst1 ./z3-4.13.3/LICENSE.txt
2326

24-
popd
27+
popd > /dev/null
2528

2629
rm -r "$TMP"

.scripts/src-install.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ if [ $# -ne 2 ]; then
88
fi
99

1010
BROOT="$(realpath "$1")"
11-
PREFIX="$(realpath -m "$2")" # -m: leading dirs allowed to not exist
1211

13-
if [ -e "${PREFIX}" ]; then
14-
echo "Destination directory already exists: ${PREFIX}"
15-
exit 1
16-
fi
17-
18-
mkdir -p "${PREFIX}"
12+
PREFIX="$2"
13+
mkdir -p "$PREFIX"
14+
PREFIX="$(realpath "$PREFIX")"
1915

2016
# Note: we must exclude everything in the Dune build directories, since
2117
# if some files "vanish" during this copy, rsync will fail (even if
@@ -49,7 +45,13 @@ cp mk/src_package_mk.mk "${PREFIX}/Makefile"
4945
mkdir "${PREFIX}/mk"
5046
cp mk/lib.mk "${PREFIX}/mk/lib.mk"
5147
cp mk/common.mk "${PREFIX}/mk/common.mk"
48+
cp mk/winwrap.sh "${PREFIX}/mk/winwrap.sh"
5249
cp -H mk/fstar-12.mk "${PREFIX}/mk/fstar-12.mk"
50+
mkdir "${PREFIX}/.scripts"
51+
cp .scripts/bin-install.sh "${PREFIX}/.scripts"
52+
cp .scripts/mk-package.sh "${PREFIX}/.scripts"
53+
cp .scripts/get_fstar_z3.sh "${PREFIX}/.scripts"
54+
cp .scripts/package_z3.sh "${PREFIX}/.scripts"
5355

5456
# Remove extra ML files, rsync has resolved the links
5557
# into the corresponding files already, and these would be

0 commit comments

Comments
 (0)