Skip to content

Commit ed545f2

Browse files
authored
Merge pull request #3642 from mtzguido/cygwin
Improving Cygwin support
2 parents 9ce9937 + 2676380 commit ed545f2

6 files changed

Lines changed: 49 additions & 24 deletions

File tree

src/basic/FStarC.Platform.fsti

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ type sys =
88
val system : sys
99
val exe : string -> string
1010

11-
(* true if the fstar compiler is compiled from sources extracted to ocaml, false otherwise *)
12-
val is_fstar_compiler_using_ocaml : bool
11+
(* true when we are running in Cygwin. Note: system will return 'Windows' in this case *)
12+
val is_cygwin : bool

src/fstar/FStarC.Main.fst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ let go_normal () =
166166

167167
(* --print: Emit files in canonical source syntax *)
168168
| Success when Options.print () || Options.print_in_place () ->
169-
if not Platform.is_fstar_compiler_using_ocaml then
170-
failwith "You seem to be using the F#-generated version of the compiler ; \o
171-
reindenting is not known to work yet with this version";
172169
let printing_mode =
173170
if Options.print ()
174171
then Prettyprint.FromTempToStdout

src/ml/bare/FStarC_Compiler_Util.ml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ let kill_process (p: proc) =
188188
attempt (fun () -> Unix.close (Unix.descr_of_in_channel p.inc));
189189
attempt (fun () -> Unix.close (Unix.descr_of_in_channel p.errc));
190190
attempt (fun () -> Unix.close (Unix.descr_of_out_channel p.outc));
191+
(* Try to kill, but the process may already be gone. On Unix we
192+
get ESRCH. On Windows, we apparently get EACCES (permission denied). *)
191193
(try Unix.kill p.pid Sys.sigkill
192-
with Unix.Unix_error (Unix.ESRCH, _, _) -> ());
194+
with Unix.Unix_error (Unix.ESRCH, _, _) -> ()
195+
| Unix.Unix_error (Unix.EACCES, _, _) when FStarC_Platform.system = FStarC_Platform.Windows -> ()
196+
);
197+
193198
(* Avoid zombie processes (Unix.close_process does the same thing. *)
194199
waitpid_ignore_signals p.pid;
195200
(* print_string ("Killed process " ^ p.id ^ "\n" ^ (stack_dump())); *)
@@ -341,29 +346,39 @@ let ask_process
341346
kill_process p; raise e
342347

343348
let get_file_extension (fn:string) : string = snd (BatString.rsplit fn ".")
349+
350+
(* NOTE: Working around https://github.com/ocaml-batteries-team/batteries-included/issues/1136 *)
351+
let is_absolute_windows (path_str : string) : bool =
352+
if FStarC_Platform.system = FStarC_Platform.Windows then
353+
match BatString.to_list path_str with
354+
| '\\' :: _ -> true
355+
| letter :: ':' :: '\\' :: _ -> BatChar.is_letter letter
356+
| _ -> false
357+
else
358+
false
359+
344360
let is_path_absolute path_str =
345361
let open Batteries.Incubator in
346362
let open BatPathGen.OfString in
347-
let path_str' = of_string path_str in
348-
is_absolute path_str'
363+
let path = of_string path_str in
364+
is_absolute path || is_absolute_windows path_str
365+
349366
let join_paths path_str0 path_str1 =
350367
let open Batteries.Incubator in
351368
let open BatPathGen.OfString in
352369
let open BatPathGen.OfString.Operators in
353370
to_string ((of_string path_str0) //@ (of_string path_str1))
354371

355372
let normalize_file_path (path_str:string) =
356-
let open Batteries.Incubator in
357-
let open BatPathGen.OfString in
358-
let open BatPathGen.OfString.Operators in
359-
to_string
360-
(normalize_in_tree
361-
(let path = of_string path_str in
362-
if is_absolute path then
363-
path
364-
else
365-
let pwd = of_string (BatSys.getcwd ()) in
366-
pwd //@ path))
373+
if is_path_absolute path_str then
374+
path_str
375+
else
376+
let open Batteries.Incubator in
377+
let open BatPathGen.OfString in
378+
let open BatPathGen.OfString.Operators in
379+
let path = of_string path_str in
380+
let cwd = of_string (BatSys.getcwd ()) in
381+
to_string (normalize_in_tree (cwd //@ path))
367382

368383
type stream_reader = BatIO.input
369384
let open_stdin () = BatIO.stdin

src/ml/bare/FStarC_Platform.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ let exe name =
1414
else
1515
name^".exe"
1616

17-
let is_fstar_compiler_using_ocaml = true
17+
let is_cygwin = Sys.cygwin

tests/dune_hello/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ FSTAR_EXE ?= fstar.exe
44

55
.PHONY: all
66
all: run
7+
ifneq ($(OS),Windows_NT) # See comment in ../simple_hello/Makefile
8+
all: run.bc
9+
endif
710

811
Hello.ml: Hello.fst
912
$(FSTAR_EXE) --codegen OCaml Hello.fst --extract Hello --z3version 4.13.3
@@ -15,6 +18,8 @@ bin/hello.exe: Hello.ml
1518
.PHONY: run
1619
run: bin/hello.exe
1720
./bin/hello.exe | grep "Hi!"
21+
22+
run.bc: bin/hello.exe
1823
# Find a way to install this? dune install skips the bytecode
1924
$(FSTAR_EXE) --ocamlenv dune exec ./hello.bc | grep "Hi!"
2025

tests/simple_hello/Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
# just take fstar.exe from the PATH.
77
FSTAR_EXE ?= fstar.exe
88

9-
all: Hello.test
9+
all: Hello.exe.test
1010

11-
Hello.test: Hello.exe Hello.byte
12-
./Hello.exe | grep "Hello F\*!"
13-
./Hello.byte | grep "Hello F\*!"
11+
# In a Cygwin build, somehow this dll is not the search path (copying it
12+
# to this directory does make the test work). Just skip it for now.
13+
# $ ./Hello.byte
14+
# Fatal error: cannot load shared library dllzarith
15+
# Reason: No such file or directory
16+
ifneq ($(OS),Windows_NT)
17+
all: Hello.byte.test
18+
endif
19+
20+
Hello.%.test: Hello.%
21+
./$< | grep "Hello F\*!"
1422

1523
%.ml: %.fst
1624
$(FSTAR_EXE) --codegen OCaml $< --extract $* --z3version 4.13.3

0 commit comments

Comments
 (0)