Skip to content

Commit de3b121

Browse files
willieyzmkannwischer
authored andcommitted
HOL-Light: Allow interactive use of hol.sh in the hol_light shell
- Ported from mlkem-native PR #1244 - Previously, while compiling and running the HOL-Light proofs in `nix develop .#hol_light` worked, trying to start the interactive shell `hol.sh` for proof development would fail. This required proof developers to install HOL-Light and s2n-bignum locally, both inconvenient and error proone because one would need to keep that local version and the nix version in sync. - This commit adjusts the nix flake to setup HOL-Light in such a way that hol.sh can be used interactively inside the `hol_light` shell. You can test for this PR with following in nix hol_light shell: ``` hol.sh ``` Now, when you enter the shell via `nix develop .#hol_light`, the interactive shell `hol.sh` is in the PATH, and within it, both s2n-bignum and proofs/hol_light/arm are added to HOL-Light's own search path (`load_path`). - Note that mldsa-native currently does not have any HOL-Light proofs. Therefore, we have not ported the HOL-Light interactive shell tests to mldsa-native. Signed-off-by: willieyz <[email protected]>
1 parent d25a7d1 commit de3b121

File tree

5 files changed

+76
-41
lines changed

5 files changed

+76
-41
lines changed

flake.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,17 @@
9393
inherit (pkgs) gcc-arm-embedded qemu coreutils python3 git;
9494
};
9595
};
96-
devShells.hol_light = util.mkShell {
96+
devShells.hol_light = (util.mkShell {
9797
packages = builtins.attrValues {
98-
inherit (config.packages) hol_light s2n_bignum;
98+
inherit (config.packages) linters hol_light s2n_bignum;
9999
};
100-
};
100+
}).overrideAttrs (old: {
101+
shellHook = ''
102+
export PATH=$PWD/scripts:$PATH
103+
# Set PROOF_DIR_ARM based on where we entered the shell
104+
export PROOF_DIR_ARM="$PWD/proofs/hol_light/arm"
105+
'';
106+
});
101107
devShells.ci = util.mkShell {
102108
packages = builtins.attrValues { inherit (config.packages) linters toolchains_native; };
103109
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
diff --git a/hol_4.14.sh b/hol_4.14.sh
3+
index 1311255..8b2bc36 100755
4+
--- a/hol_4.14.sh
5+
+++ b/hol_4.14.sh
6+
@@ -5,7 +5,7 @@ export HOLLIGHT_DIR=__DIR__
7+
8+
if [ "$#" -eq 1 ]; then
9+
if [ "$1" == "-pp" ]; then
10+
- echo "camlp5r pa_lexer.cmo pa_extend.cmo q_MLast.cmo -I "__DIR__" pa_j.cmo"
11+
+ echo "camlp5r pa_lexer.cmo pa_extend.cmo q_MLast.cmo -I ${HOLLIGHT_DIR} pa_j.cmo"
12+
exit 0
13+
elif [ "$1" == "-dir" ]; then
14+
echo "${HOLLIGHT_DIR}"
15+
@@ -32,4 +32,13 @@ if [ "${HOL_ML_PATH}" == "" ]; then
16+
HOL_ML_PATH="${HOLLIGHT_DIR}/hol.ml"
17+
fi
18+
19+
-${LINE_EDITOR} ${HOLLIGHT_DIR}/ocaml-hol -init ${HOL_ML_PATH} -I ${HOLLIGHT_DIR}
20+
+# Add site-lib directory for topfind
21+
+SITELIB=$(dirname $(ocamlfind query findlib 2>/dev/null) 2>/dev/null)
22+
+
23+
+# Set HOLLIGHT_LOAD_PATH to include S2N_BIGNUM_DIR and mldsa-native proofs
24+
+export HOLLIGHT_LOAD_PATH="${S2N_BIGNUM_DIR}:${PROOF_DIR_ARM}:${HOLLIGHT_LOAD_PATH}"
25+
+
26+
+# Change to mldsa-native proofs directory if set, so define_from_elf can find object files
27+
+[ -n "${PROOF_DIR_ARM}" ] && cd "${PROOF_DIR_ARM}"
28+
+
29+
+${LINE_EDITOR} ${HOLLIGHT_DIR}/ocaml-hol -init ${HOL_ML_PATH} -I ${HOLLIGHT_DIR} ${SITELIB:+-I "$SITELIB"}
30+
diff --git a/hol_4.sh b/hol_4.sh
31+
index 0aaa5c7..5adaf4c 100755
32+
--- a/hol_4.sh
33+
+++ b/hol_4.sh
34+
@@ -5,7 +5,7 @@ export HOLLIGHT_DIR=__DIR__
35+
36+
if [ "$#" -eq 1 ]; then
37+
if [ "$1" == "-pp" ]; then
38+
- echo "camlp5r pa_lexer.cmo pa_extend.cmo q_MLast.cmo -I "__DIR__" pa_j.cmo"
39+
+ echo "camlp5r pa_lexer.cmo pa_extend.cmo q_MLast.cmo -I "${HOLLIGHT_DIR}" pa_j.cmo"
40+
exit 0
41+
elif [ "$1" == "-dir" ]; then
42+
echo "${HOLLIGHT_DIR}"
43+
@@ -32,4 +32,4 @@ if [ "${HOL_ML_PATH}" == "" ]; then
44+
HOL_ML_PATH="${HOLLIGHT_DIR}/hol.ml"
45+
fi
46+
47+
-${LINE_EDITOR} ${HOLLIGHT_DIR}/ocaml-hol -I `camlp5 -where` camlp5o.cma -init ${HOL_ML_PATH} -safe-string -I ${HOLLIGHT_DIR}
48+
+${LINE_EDITOR} ${HOLLIGHT_DIR}/ocaml-hol -I $(camlp5 -where) camlp5o.cma -init ${HOL_ML_PATH} -safe-string -I ${HOLLIGHT_DIR}

nix/hol_light/0005-Fix-hollight-path.patch

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
diff --git a/Makefile b/Makefile
3+
index abc1234..def5678 100644
4+
--- a/Makefile
5+
+++ b/Makefile
6+
@@ -100,7 +100,7 @@ hol.sh: pa_j.cmo ${HOLSRC} bignum.cmo hol_loader.cmo update_database.ml
7+
if [ `uname` = "Linux" ] || [ `uname` = "Darwin" ] ; then \
8+
if [ ${OCAML_UNARY_VERSION} = "5" ] || [ ${OCAML_VERSION} = "4.14" ] ; then \
9+
- ocamlfind ocamlmktop -package zarith -o ocaml-hol zarith.cma bignum.cmo hol_loader.cmo ; \
10+
+ ocamlfind ocamlmktop -package zarith,findlib -o ocaml-hol zarith.cma bignum.cmo hol_loader.cmo ; \
11+
sed "s^__DIR__^`pwd`^g; s^__USE_MODULE__^$(HOLLIGHT_USE_MODULE)^g" hol_4.14.sh > hol.sh ; \
12+
else \
13+
ocamlmktop -o ocaml-hol nums.cma bignum.cmo hol_loader.cmo ; \

nix/hol_light/default.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) The mldsa-native project authors
33
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
44

5-
{ hol_light, fetchFromGitHub, writeText, ... }:
5+
{ hol_light, fetchFromGitHub, writeText, ocamlPackages, ledit, ... }:
66
hol_light.overrideAttrs (old: {
77
setupHook = writeText "setup-hook.sh" ''
88
export HOLDIR="$1/lib/hol_light"
@@ -15,8 +15,11 @@ hol_light.overrideAttrs (old: {
1515
rev = "0e4b1bd8c7d400214d6fa6027f15a4221b54f8d4";
1616
hash = "sha256-M6ddzqoAFyMBmaznuz31+o035xdEz4VXZMHhH4Dm4c8=";
1717
};
18-
patches = [ ./0005-Fix-hollight-path.patch ];
19-
propagatedBuildInputs = old.propagatedBuildInputs ++ old.nativeBuildInputs;
18+
patches = [
19+
./0005-Configure-hol-sh-for-mldsa-native.patch
20+
./0006-Add-findlib-to-ocaml-hol.patch
21+
];
22+
propagatedBuildInputs = old.propagatedBuildInputs ++ old.nativeBuildInputs ++ [ ocamlPackages.pcre2 ledit ];
2023
buildPhase = ''
2124
HOLLIGHT_USE_MODULE=1 make hol.sh
2225
patchShebangs hol.sh

0 commit comments

Comments
 (0)