Skip to content

Commit

Permalink
Makefile: simplifying F* detection (of library, ocaml files, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtzguido committed Jan 4, 2025
1 parent d75bc9f commit fee6cb3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ obj/libhaclml.cmxa: $(filter-out $(HACL_HOME)/obj/Meta_Interface.cmx,$(ALL_CMX_F
# JP: doesn't work because a PPX is prepended for some reason
# ocamlfind mklib -o haclml -package fstar.lib -g -I $(HACL_HOME)/obj $(addprefix $(HACL_HOME)/obj/*.,cmo cmx ml o)
$(call run-with-log,\
OCAMLFIND_IGNORE_DUPS_IN="`ocamlc -where`/compiler-libs" ocamlfind opt -thread -a -o $@ -package fstar.lib -g -I $(HACL_HOME)/obj $^ \
OCAMLFIND_IGNORE_DUPS_IN="`ocamlc -where`/compiler-libs" $(FSTAR_EXE) --ocamlenv ocamlfind opt -thread -a -o $@ -package fstar.lib -g -I $(HACL_HOME)/obj $^ \
,[OCAMLOPT-CMXA] libhaclml,$(call to-obj-dir,$@))


Expand Down
32 changes: 7 additions & 25 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,19 @@ ifndef KRML_HOME
KRML_HOME := $(HACL_HOME)/../karamel
endif

ifndef FSTAR_HOME
FSTAR_EXE=$(shell which fstar.exe)
ifeq ($(FSTAR_EXE),)
# F* not found in PATH, assuming an Everest source tree
FSTAR_HOME := $(HACL_HOME)/../FStar
else
# F* found in PATH, assuming directory name ends with /bin
FSTAR_HOME := $(dir $(FSTAR_EXE))/..
endif
endif

FSTAR_EXE := $(FSTAR_HOME)/bin/fstar.exe
include locate_fstar.mk

# Check that the relevant homes and executables at least exist.
mustexist = \
$(if $(wildcard $(value $(strip $1))),, \
$(error $1 ($(value $(strip $1))) does not exist))

$(call mustexist, FSTAR_HOME)
# $(call mustexist, FSTAR_HOME)
# ^ No longer needed, we just need the .exe
$(call mustexist, FSTAR_EXE)
$(call mustexist, KRML_HOME)

ifndef FSTAR_ULIB
FSTAR_ULIB := $(shell if test -d "$(FSTAR_HOME)/ulib" ; then echo "$(FSTAR_HOME)/ulib" ; else echo "$(FSTAR_HOME)/lib/fstar" ; fi)
endif
FSTAR_ULIB := $(shell $(FSTAR_EXE) --locate_lib)

ifndef VALE_HOME
# assuming an Everest source tree
Expand All @@ -67,7 +55,6 @@ sanitize_path=$(call maybe_cygpath,$(realpath $(1)))

HACL_HOME := $(call sanitize_path,$(HACL_HOME))
KRML_HOME := $(call sanitize_path,$(KRML_HOME))
FSTAR_HOME := $(call sanitize_path,$(FSTAR_HOME))
FSTAR_ULIB := $(call sanitize_path,$(FSTAR_ULIB))
VALE_HOME := $(call sanitize_path,$(VALE_HOME))

Expand Down Expand Up @@ -243,14 +230,9 @@ TAC = $(shell which tac >/dev/null 2>&1 && echo "tac" || echo "tail -r")

ALL_CMX_FILES = $(subst obj/Lib_Buffer.cmx,obj/Lib_Memzero0.cmx obj/Lib_Buffer.cmx,$(patsubst %.ml,%.cmx,$(shell echo $(ALL_ML_FILES) | $(TAC))))

ifeq ($(OS),Windows_NT)
export OCAMLPATH := $(FSTAR_HOME)/lib;$(OCAMLPATH)
else
export OCAMLPATH := $(FSTAR_HOME)/lib:$(OCAMLPATH)
endif

# Warning 8: this pattern-matching is not exhaustive.
# Warning 20: this argument will not be used by the function.
# Warning 26: unused variable
OCAMLOPT = OCAMLFIND_IGNORE_DUPS_IN="`ocamlc -where`/compiler-libs" ocamlfind opt -package fstar.lib -linkpkg -thread -g -I $(HACL_HOME)/obj -w -8-20-26
OCAMLSHARED = OCAMLFIND_IGNORE_DUPS_IN="`ocamlc -where`/compiler-libs" ocamlfind opt -shared -package fstar.lib -thread -g -I $(HACL_HOME)/obj -w -8-20-26
export OCAMLFIND_IGNORE_DUPS_IN="`ocamlc -where`/compiler-libs"
OCAMLOPT = $(FSTAR_EXE) --ocamlenv ocamlfind opt -package fstar.lib -linkpkg -thread -g -I $(HACL_HOME)/obj -w -8-20-26
OCAMLSHARED = $(FSTAR_EXE) --ocamlenv ocamlfind opt -shared -package fstar.lib -thread -g -I $(HACL_HOME)/obj -w -8-20-26
27 changes: 27 additions & 0 deletions locate_fstar.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Find fstar.exe and set FSTAR_EXE to its absolute path.

# If FSTAR_EXE is already externally set, we just use it. Note the use
# of ?= everywhere below.

# If FSTAR_HOME is set, we honor it and pick that F*.
ifdef FSTAR_HOME
FSTAR_EXE ?= $(abspath $(FSTAR_HOME)/bin/fstar.exe)
endif

# Otherwise we try to find it from the PATH.

# Bash's 'type -P' is essentially 'which'. This relies on having bash
# around, but does not require 'which'.
FSTAR_EXE ?= $(shell bash -c 'type -P fstar.exe')

# Force eval
FSTAR_EXE := $(FSTAR_EXE)

# Don't fail if we're cleaning
ifneq ($(MAKECMDGOALS),clean)
ifeq (,$(FSTAR_EXE))
$(error "Did not find fstar.exe in PATH and FSTAR_EXE/FSTAR_HOME unset, aborting.")
endif
endif

export FSTAR_EXE

0 comments on commit fee6cb3

Please sign in to comment.