Skip to content

Commit 988a013

Browse files
authored
Merge pull request #3620 from FStarLang/_guido_windows
Fixes to make the windows binary build work
2 parents fd93201 + f0c4ca6 commit 988a013

File tree

14 files changed

+142
-84
lines changed

14 files changed

+142
-84
lines changed

examples/dependencies/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ FSTAR_EXE ?= $(shell which fstar.exe)
66

77
V != $(FSTAR_EXE) --version
88

9+
HAS_OCAML := $(shell which ocamlfind 2>/dev/null)
10+
# NB: This is overriden (to empty) when testing the binary package
11+
# so we skip the build test. (Variables given in the command line, not
12+
# the environment, override those defined in the script.)
13+
914
ifeq ($(V),)
1015
$(error "fstar.exe --version failed... place a valid F* in your PATH or set FSTAR_EXE")
1116
endif
@@ -23,7 +28,7 @@ ENABLE_HINTS ?= --use_hints
2328

2429
FSTAR = $(FSTAR_EXE) $(FSTAR_FLAGS)
2530

26-
.PHONY: all test clean
31+
.PHONY: all test clean run
2732

2833
all:
2934
rm -f .depend && $(MAKE) .depend # Always re-generate dependencies
@@ -55,7 +60,14 @@ $(OUT_DIR)/%.ml:
5560
$(OUT_DIR)/test.exe: $(subst .ml,.cmx,$(ALL_ML_FILES)) | $(OUT_DIR)
5661
$(FSTAR_EXE) --ocamlopt -I $(OUT_DIR) -o $(OUT_DIR)/test.exe $(subst .ml,.cmx,$(ALL_ML_FILES))
5762

58-
test: $(OUT_DIR)/test.exe
63+
# If we don't have OCaml, just extract the ML files.
64+
ifneq (,$(HAS_OCAML))
65+
test: run
66+
else
67+
test: $(ALL_ML_FILES)
68+
endif
69+
70+
run: $(OUT_DIR)/test.exe
5971
$(OUT_DIR)/test.exe
6072

6173
clean:

mk/test.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ ifeq ($(NOVERIFY),)
155155
all: __verify
156156
endif
157157

158+
HAS_OCAML ?= 1
159+
# We assume we have ocaml, unless HAS_OCAML= was given as an argument
160+
# to make (this is done by binary package CI). If we don't have ocaml,
161+
# we don't try to build or run programs.
162+
ifeq (,$(HAS_OCAML))
163+
NORUN := 1
164+
NOBUILD := 1
165+
endif
166+
158167
# clean
159168
SUBDIRS_CLEAN += $(SUBDIRS)
160169
clean: $(addsuffix .__clean, $(SUBDIRS_CLEAN))

ocaml/fstar-lib/FStarC_Compiler_Util.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,3 +1172,8 @@ let array_index (l:'a FStar_ImmutableArray_Base.t) (i:Z.t) = FStar_ImmutableArra
11721172

11731173
let putenv k v = Unix.putenv k v
11741174
let execvp c args = Unix.execvp c (Array.of_list args)
1175+
1176+
let exn_is_enoent (e:exn) : bool =
1177+
match e with
1178+
| Unix.Unix_error (Unix.ENOENT, _, _) -> true
1179+
| _ -> false

ocaml/fstar-lib/generated/FStarC_OCaml.ml

Lines changed: 5 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ocaml/fstar-lib/generated/FStarC_SMTEncoding_Z3.ml

Lines changed: 80 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/basic/FStarC.Compiler.Util.fsti

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,5 @@ val array_index (s:FStar.ImmutableArray.Base.t 'a) (i:FStarC.BigInt.t) : 'a
400400

401401
val putenv : string -> string -> unit
402402
val execvp : string -> list string -> unit // will return only on error
403+
404+
val exn_is_enoent (e:exn) : bool

src/fstar/FStarC.OCaml.fst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ let shellescape (s:string) : string =
3030

3131
let new_ocamlpath () : string =
3232
let ocamldir = Find.locate_ocaml () in
33+
let sep = match Platform.system with
34+
| Platform.Windows -> ";"
35+
| Platform.Posix -> ":"
36+
in
3337
let old_ocamlpath = Util.dflt "" (Util.expand_environment_variable "OCAMLPATH") in
34-
let new_ocamlpath = ocamldir ^ ":" ^ old_ocamlpath in
38+
let new_ocamlpath = ocamldir ^ sep ^ old_ocamlpath in
3539
new_ocamlpath
3640

3741
let exec_in_ocamlenv #a (cmd : string) (args : list string) : a =
3842
let new_ocamlpath = new_ocamlpath () in
39-
if Platform.system = Platform.Windows then (
40-
Errors.raise_error0 Errors.Fatal_OptionsNotCompatible [
41-
Errors.text "--ocamlenv is not supported on Windows (yet?)"
42-
]
43-
);
4443
(* Update OCAMLPATH and run (exec) the command *)
4544
Util.putenv "OCAMLPATH" new_ocamlpath;
4645
Util.execvp cmd (cmd :: args);

src/smtencoding/FStarC.SMTEncoding.Z3.fst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ let z3_exe : unit -> string =
7070
find_or (Options.z3_version()) (fun version ->
7171
let path =
7272
let z3_v = Platform.exe ("z3-" ^ version) in
73+
let local_z3 = Platform.exe (FStarC.Find.fstar_bin_directory ^ "/" ^ "z3-fstar-" ^ version) in
7374
let smto = Options.smt () in
75+
7476
if Some? smto then Some?.v smto
77+
else if BU.file_exists local_z3 then local_z3
7578
else if inpath z3_v then z3_v
7679
else Platform.exe "z3"
7780
in
@@ -187,6 +190,14 @@ let warn_handler (suf:Errors.error_message) (s:string) : unit =
187190
blank 2 ^^ align (dquotes (arbitrary_string s));
188191
] @ suf)
189192

193+
let install_suggestion : Pprint.document =
194+
let open FStarC.Errors.Msg in
195+
let open FStarC.Pprint in
196+
prefix 4 1 (text "Please download the correct version of Z3 from")
197+
(url z3url) ^/^
198+
group (text "and install it into your $PATH as" ^/^ squotes
199+
(doc_of_string (Platform.exe ("z3-" ^ Options.z3_version ()))) ^^ dot)
200+
190201
(* Talk to the process to see if it's the correct version of Z3
191202
(i.e. the one in the optionstate). Also check that it indeed is Z3. By
192203
default, each of these generates an error, but they can be downgraded
@@ -221,10 +232,7 @@ let check_z3version (p:proc) : unit =
221232
Errors.log_issue0 Errors.Warning_SolverMismatch [
222233
text (BU.format3 "Unexpected Z3 version for '%s': expected '%s', got '%s'."
223234
(proc_prog p) ver_conf ver_found);
224-
prefix 4 1 (text "Please download the correct version of Z3 from")
225-
(url z3url) ^/^
226-
group (text "and install it into your $PATH as" ^/^ squotes
227-
(doc_of_string (Platform.exe ("z3-" ^ Options.z3_version ()))) ^^ dot);
235+
install_suggestion;
228236
];
229237
Errors.stop_if_err(); (* stop now if this was a hard error *)
230238
_already_warned_version_mismatch := true
@@ -236,6 +244,16 @@ let new_z3proc (id:string) (cmd_and_args : string & list string) : BU.proc =
236244
try
237245
BU.start_process id (fst cmd_and_args) (snd cmd_and_args) (fun s -> s = "Done!")
238246
with
247+
| e when BU.exn_is_enoent e ->
248+
let open FStarC.Pprint in
249+
let open FStarC.Errors.Msg in
250+
Errors.raise_error0 Errors.Error_Z3InvocationError [
251+
text "Z3 solver not found.";
252+
prefix 2 1 (text "Required version:")
253+
(text (Options.z3_version ()));
254+
install_suggestion;
255+
]
256+
239257
| e ->
240258
let open FStarC.Pprint in
241259
let open FStarC.Errors.Msg in
File renamed without changes.

0 commit comments

Comments
 (0)