Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with dune #212

Merged
merged 26 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
21d59dd
step 1: reorder targets
tahina-pro May 20, 2021
977c5e7
step 2: use dune to build kremlib extra
tahina-pro May 20, 2021
c1aebd4
step 3: use dune to build krml
tahina-pro May 20, 2021
ab4cac4
move all sources to src/
tahina-pro Jul 12, 2021
94913e4
Merge branch 'taramana_dune_20210712' into taramana_dune
tahina-pro Jul 12, 2021
e151bfe
Merge branch 'master' of github.com:FStarLang/karamel into taramana_dune
tahina-pro Feb 4, 2023
d123962
kremlin -> karamel
tahina-pro Feb 4, 2023
e923c07
missing dune-project in krmllib
tahina-pro Feb 4, 2023
5048cd9
regenerate src/FStar_Version.ml
tahina-pro Feb 4, 2023
addf91f
Merge branch 'master' of github.com:FStarLang/kremlin into taramana_dune
tahina-pro Mar 6, 2023
005c3ce
fstarlib -> fstar.lib
tahina-pro Mar 6, 2023
6df4e93
"convert" ctypes-test to dune
tahina-pro Mar 7, 2023
f815223
Merge branch 'master' into taramana_dune
msprotz Apr 8, 2023
beacaa3
Add a reference Makefile that captures the build hacl-packages
msprotz Apr 8, 2023
14eaa69
Missing dependency edge in the generated file
msprotz Apr 8, 2023
85c5dcb
try
msprotz Apr 8, 2023
895a077
pre-merge: revert changes on some hints file
tahina-pro Apr 19, 2023
0d32469
Merge branch 'master' of github.com:FStarLang/karamel into taramana_dune
tahina-pro Apr 19, 2023
30c24bb
restore overlooked KRML_HOME
tahina-pro Apr 19, 2023
7eb9fa3
remove unused OCaml krmllib "extra"
tahina-pro Apr 19, 2023
69a40f1
redundant +$(MAKE) -> $(MAKE)
tahina-pro Apr 19, 2023
f8a67bc
remove ocamlbuild remnants
tahina-pro Apr 19, 2023
704f38b
without KRML_HOME, now assume dune's build path instead of ocamlbuild's
tahina-pro Apr 19, 2023
5379b45
allow test/sepcomp without KRML_HOME, assume a Karamel source tree
tahina-pro Apr 19, 2023
05ebb4d
restore OCaml warning comments
tahina-pro Apr 19, 2023
0601a57
ignore OCaml warning 7 (method-override)
tahina-pro Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# make src/Ast.processed.ml
include $(shell ocamlfind query visitors)/Makefile.preprocess

.PHONY: all minimal clean test

OCAMLBUILD=ocamlbuild -I src -I lib -I parser -I krmllib -use-menhir -use-ocamlfind \
-menhir "menhir --infer --explain" -quiet
FLAVOR?=native
TARGETS=Karamel.$(FLAVOR)
EXTRA_TARGETS=Ast.inferred.mli krmllib/C.cmx krmllib/TestLib.cmx krmllib/C.cmo krmllib/TestLib.cmo
.PHONY: all minimal clean test pre extra krmllib install

ifeq ($(OS),Windows_NT)
OCAMLPATH_SEP=;
else
OCAMLPATH_SEP=:
endif

all: minimal krmllib extra

ifdef FSTAR_HOME
OCAMLPATH:=$(OCAMLPATH)$(OCAMLPATH_SEP)$(FSTAR_HOME)/lib
else
Expand All @@ -29,18 +25,16 @@ endif
export FSTAR_HOME
export OCAMLPATH

all: minimal krmllib
@OCAML_ERROR_STYLE="short" \
$(OCAMLBUILD) $(EXTRA_TARGETS)
extra: pre krmllib
+ OCAML_ERROR_STYLE="short" \
OCAMLPATH="$(OCAMLPATH)$(OCAMLPATH_SEP)$(FSTAR_HOME)/bin" $(MAKE) -C krmllib extra

minimal: src/AutoConfig.ml src/Version.ml
@# Workaround Windows bug in OCamlbuild
$(shell [ -f Karamel.$(FLAVOR) ] && rm Karamel.$(FLAVOR))
@OCAML_ERROR_STYLE="short" $(OCAMLBUILD) $(TARGETS)
ln -sf Karamel.$(FLAVOR) krml
+ OCAML_ERROR_STYLE="short" $(MAKE) -C src
ln -sf src/_build/default/Karamel.exe krml

krmllib: minimal
$(MAKE) -C krmllib
+$(MAKE) -C krmllib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the GNU make manual, "5.7.1 How the MAKE Variable Works":

Using the MAKE variable has the same effect as using a ‘+’ character at the beginning of the recipe line.

Is there a reason why you added these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can remove this redundant + for clarity, thanks for pointing out!

Copy link
Member Author

@tahina-pro tahina-pro Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, f3fac5a introduced +$(MAKE) for the test rule, but it was keeping a pre-existing +, so I could remove it from there as well


src/AutoConfig.ml:
@if [ x"$(PREFIX)" != x ]; then \
Expand All @@ -60,9 +54,10 @@ src/Version.ml:
@echo "let version = \"$(shell git rev-parse HEAD)\"" > $@ \

clean:
rm -rf krml _build Karamel.$(FLAVOR)
$(MAKE) -C test clean
rm -rf krml
$(MAKE) -C src clean
$(MAKE) -C krmllib clean
$(MAKE) -C test clean

test: all
+$(MAKE) -C test
Expand All @@ -76,7 +71,7 @@ pre:
install: all
@if [ x"$(PREFIX)" = x ]; then echo "please define PREFIX"; exit 1; fi
mkdir -p $(PREFIX)/bin
cp _build/src/Karamel.native $(PREFIX)/bin/krml
cp src/_build/default/Karamel.exe $(PREFIX)/bin/krml
mkdir -p $(PREFIX)/include
cp -r include/* $(PREFIX)/include
mkdir -p $(PREFIX)/lib/krml
Expand Down
20 changes: 14 additions & 6 deletions krmllib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

all: verify-all compile-all

extra:
+dune build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. based on my understanding of the GNU Make manual, section "9.3 Instead of Executing Recipes": adding a + here means that if someone runs, e.g., make -n extra to see what would be done by make, then dune is still invoked... do I understand this right, and is this a desired behavior?

  2. do you know who uses C.ml and TestLib.ml? I don't, and the last reference to them comes from 2017. Can we just remove those files, and the corresponding targets and dune-project files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I wasn't aware of 9.3, thanks for pointing out. However, I was concerned with Appendix B:

‘warning: jobserver unavailable: using -j1. Add `+' to parent make rule.’

where I initially anticipated dune to make use of GNU Make's jobserver (which finally dune doesn't), so let me remove this.
(This also means that there is no way to make the jobserver available to a non-Make process while also honoring make -n)

  1. I'm not aware of any F* code depending on krmllib being extracted to OCaml using the handwritten C.ml or TestLib.ml. Not even the (now disabled) miTLS extraction to OCaml does that. So yes, let me simplify things and remove that extra rule.

Thanks again for chiming in!


.PHONY: all verify-all compile-all extra


################################################################################
# Verification & extraction #
################################################################################
Expand Down Expand Up @@ -52,15 +58,18 @@ ROOTS = $(wildcard *.fst) $(wildcard *.fsti) $(wildcard ../runtime/*.fst) \
FStar.HyperStack.IO.fst FStar.IO.fst FStar.Int.Cast.Full.fst \
FStar.Bytes.fsti FStar.Dyn.fsti LowStar.Printf.fst LowStar.Endianness.fst

.PHONY: clean clean-c
clean: clean-c
.PHONY: clean clean-c clean-ml
clean: clean-c clean-ml
rm -rf *.checked *.source .depend

SHELL:=$(shell which bash)

clean-c:
rm -rf dist out extract-all */*.o

clean-ml:
dune clean

ifndef NODEPEND
ifndef MAKE_RESTARTS
.depend: .FORCE obj
Expand Down Expand Up @@ -108,7 +117,7 @@ $(GENERIC_DIR):
mkdir -p $@

# Everything in the universe
$(GENERIC_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(wildcard c/*.c) $(wildcard c/*.h) ../_build/src/Karamel.native
$(GENERIC_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(wildcard c/*.c) $(wildcard c/*.h) ../src/_build/default/Karamel.exe
../krml $(KRML_ARGS) -tmpdir $(GENERIC_DIR) \
-warn-error +9+11 \
$(MACHINE_INTS) \
Expand All @@ -123,7 +132,7 @@ $(GENERIC_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(wildcard c
cp c/*.c c/*.h $(dir $@)

# Minimalistic build (just machine integers and endianness)
$(MINI_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(MINI_DIR) $(wildcard c/fstar_uint128*.h) ../_build/src/Karamel.native
$(MINI_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(MINI_DIR) $(wildcard c/fstar_uint128*.h) ../src/_build/default/Karamel.exe
mkdir -p $(dir $@)
KRML_HOME=$(shell pwd)/.. \
../krml $(KRML_ARGS) -tmpdir $(MINI_DIR) \
Expand All @@ -144,8 +153,7 @@ $(MINI_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(MINI_DIR) $(wildcard c/fstar
# Extracted (and verified) uint128s; copied into generic and minimal. Note that
# FStar.UInt64 shares the same bundle name, meaning that
# FStar_UInt128_Verified.h can be dropped in any of the two krmllibs above.
$(UINT128_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(MINI_DIR) ../_build/src/Karamel.native
KRML_HOME=$(shell pwd)/.. \
$(UINT128_DIR)/Makefile.include: $(ALL_KRML_FILES) | $(GENERIC_DIR) $(MINI_DIR) ../src/_build/default/Karamel.exe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for removing KRML_HOME when it's present in the other recipe above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably an overlook, let me restore that. Thanks!

../krml $(KRML_ARGS) -tmpdir $(UINT128_DIR) \
$(addprefix -add-include ,'<inttypes.h>' '<stdbool.h>' '"krml/internal/types.h"' '"krml/internal/target.h"') \
-bundle FStar.UInt64[rename=FStar_UInt_8_16_32_64] \
Expand Down
6 changes: 6 additions & 0 deletions krmllib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name krmllib)
(libraries
fstar.lib)
(wrapped false)
)
2 changes: 2 additions & 0 deletions krmllib/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 2.0)
(name krmllib)
7 changes: 7 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all:
+dune build

clean:
dune clean

.PHONY: all clean
24 changes: 24 additions & 0 deletions src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(include_subdirs unqualified)

(executable
(name Karamel)
(libraries
ppx_deriving.std
ppx_deriving_yojson
zarith
pprint
unix
menhirLib
sedlex
process
fix
wasm
visitors.ppx
visitors.runtime
sedlex.ppx
)
(preprocess
(pps ppx_deriving.std ppx_deriving_yojson sedlex.ppx visitors.ppx)
)
(flags (:standard -warn-error -A -w @[email protected]@[email protected]@31..38-39-40-41@43@57))
)
3 changes: 3 additions & 0 deletions src/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 2.0)
(name karamel)
(using menhir 2.0)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/parser/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(menhir
(modules KParser)
(flags --explain --dump)
(infer true)
)
11 changes: 5 additions & 6 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ifneq ($(CRYPTO),)
CRYPTO_OPTS = -I $(CRYPTO) -I $(CRYPTO)/real
endif
TEST_OPTS = -warn-error @4 -verbose -skip-makefiles
KRML_BIN = ../_build/src/Karamel.native
KRML_BIN = ../src/_build/default/Karamel.exe
KRML = $(KRML_BIN) $(KOPTS) $(TEST_OPTS)

# TODO: disambiguate between broken tests that arguably should work (maybe
Expand Down Expand Up @@ -242,19 +242,18 @@ $(LOWLEVEL_DIR)/%: ctypes/%
cp $< $@

ctypes-test: $(LOWLEVEL_DIR)/Client.native
cd $(LOWLEVEL_DIR)/_build && export LD_LIBRARY_PATH=. && \
./Client.native && ./Client.byte
cd $(LOWLEVEL_DIR)/_build/default && export LD_LIBRARY_PATH=. && \
./Client.exe && ./Client.bc

sepcomp-test:
+$(MAKE) -C sepcomp
.PHONY: sepcomp-test

CTYPES_HAND_WRITTEN_FILES=myocamlbuild.ml Client.ml _tags
CTYPES_HAND_WRITTEN_FILES=Client.ml dune dune-workspace lib/dune lib_gen/dune

.PHONY: $(LOWLEVEL_DIR)/Client.native
$(LOWLEVEL_DIR)/Client.native: $(OUTPUT_DIR)/Ctypes2.exe $(addprefix $(LOWLEVEL_DIR)/,$(CTYPES_HAND_WRITTEN_FILES))
cd $(dir $@) && \
CTYPES_LIB_DIR=$(shell ocamlfind query ctypes) ocamlbuild -use-ocamlfind $(notdir $@) Client.byte
cd $(dir $@) && env CTYPES_LIB_DIR=$(shell ocamlfind query ctypes) LOWLEVEL_DIR=$(realpath $(LOWLEVEL_DIR)) dune build


# A pseudo-target for WASM compilation that does not match any specific file.
Expand Down
4 changes: 0 additions & 4 deletions test/ctypes/_tags

This file was deleted.

39 changes: 39 additions & 0 deletions test/ctypes/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(executable
(name Client)
(libraries
Ctypes1_stubs
Lowlevel_bindings
Lowlevel_stubs
Ctypes2_bindings
Ctypes2_stubs
Client_foreign
)
(link_flags "-linkall")
(modes (byte exe) (native exe))
(flags (:standard -w -32-33))
)

(library
(name Client_foreign)
(modules)
(wrapped false)
(foreign_stubs (language c) (names Lowlevel Ctypes1 Ctypes2 Lowlevel_c_stubs Ctypes1_c_stubs Ctypes2_c_stubs) (include_dirs %{env:KRML_HOME=../../..}/include %{env:KRML_HOME=../../..}/krmllib/dist/generic internal %{env:CTYPES_LIB_DIR=.}))
)

(rule
(target Ctypes1_c_stubs.c)
(deps lib/Ctypes1_c_stubs.c)
(action (copy %{deps} %{target}))
)

(rule
(target Lowlevel_c_stubs.c)
(deps lib/Lowlevel_c_stubs.c)
(action (copy %{deps} %{target}))
)

(rule
(target Ctypes2_c_stubs.c)
(deps lib/Ctypes2_c_stubs.c)
(action (copy %{deps} %{target}))
)
1 change: 1 addition & 0 deletions test/ctypes/dune-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.2)
77 changes: 77 additions & 0 deletions test/ctypes/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
(library
(name Ctypes1_bindings)
(wrapped false)
(libraries
ctypes
)
(modules Ctypes1_bindings)
(flags (:standard -w -A))
)

(library
(name Lowlevel_bindings)
(wrapped false)
(libraries
ctypes
Ctypes1_bindings
Ctypes1_stubs
)
(modules Lowlevel_bindings)
(flags (:standard -w -A))
)

(library
(name Ctypes2_bindings)
(wrapped false)
(modules Ctypes2_bindings)
(libraries
Ctypes1_bindings
Ctypes1_stubs
)
(flags (:standard -w -A))
)

(library
(name Lowlevel_stubs)
(wrapped false)
(modules Lowlevel_stubs)
(libraries
ctypes.stubs
)
)

(library
(name Ctypes1_stubs)
(wrapped false)
(modules Ctypes1_stubs)
(libraries
ctypes.stubs
)
)

(library
(name Ctypes2_stubs)
(wrapped false)
(modules Ctypes2_stubs)
(libraries
ctypes.stubs
)
)

(rule
(targets Ctypes1_stubs.ml Ctypes1_c_stubs.c)
(deps ../lib_gen/Ctypes1_gen.exe)
(action (chdir .. (run %{dep:../lib_gen/Ctypes1_gen.exe})))
)

(rule
(targets Lowlevel_stubs.ml Lowlevel_c_stubs.c)
(deps ../lib_gen/Lowlevel_gen.exe)
(action (chdir .. (run %{dep:../lib_gen/Lowlevel_gen.exe})))
)

(rule
(targets Ctypes2_stubs.ml Ctypes2_c_stubs.c)
(deps ../lib_gen/Ctypes2_gen.exe)
(action (chdir .. (run %{dep:../lib_gen/Ctypes2_gen.exe})))
)
29 changes: 29 additions & 0 deletions test/ctypes/lib_gen/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(executable
(name Ctypes1_gen)
(modules Ctypes1_gen)
(libraries
ctypes.stubs
Ctypes1_bindings
)
(link_flags "-linkall")
)

(executable
(name Lowlevel_gen)
(modules Lowlevel_gen)
(libraries
ctypes.stubs
Lowlevel_bindings
)
(link_flags "-linkall")
)

(executable
(name Ctypes2_gen)
(modules Ctypes2_gen)
(libraries
ctypes.stubs
Ctypes2_bindings
)
(link_flags "-linkall")
)
Loading