@@ -45,8 +45,7 @@ module P = Process
4545 * understood as a cyclic dependency on our own [Output] module. *)
4646
4747(* * These three variables filled in by [detect_fstar] *)
48- let fstar = ref " "
49- let fstar_home = ref " "
48+ let fstar = Options. fstar
5049let fstar_lib = ref " "
5150let fstar_rev = ref " <unknown>"
5251let fstar_options = ref []
@@ -202,63 +201,50 @@ let detect_karamel_if () =
202201let expand_prefixes s =
203202 if KString. starts_with s " FSTAR_LIB" then
204203 ! fstar_lib ^^ KString. chop s " FSTAR_LIB"
205- else if KString. starts_with s " FSTAR_HOME" then
206- ! fstar_home ^^ KString. chop s " FSTAR_HOME"
207204 else
208205 s
209206
210- (* Fills in fstar{,_home ,_options} *)
207+ (* Fills in fstar{,_lib ,_options}. Does NOT read any environment variables. *)
211208let detect_fstar () =
212209 detect_karamel_if () ;
213210
214211 if not ! Options. silent then
215212 KPrint. bprintf " %s⚙ KaRaMeL will drive F*.%s Here's what we found:\n " Ansi. blue Ansi. reset;
216213
217- begin try
218- let r = Sys. getenv " FSTAR_HOME" in
219- if not ! Options. silent then
220- KPrint. bprintf " read FSTAR_HOME via the environment\n " ;
221- fstar_home := r;
222- fstar := r ^^ " bin" ^^ " fstar.exe"
223- with Not_found -> try
224- fstar := read_one_line " which" [| " fstar.exe" |];
225- fstar_home := d (d ! fstar);
226- if not ! Options. silent then
227- KPrint. bprintf " FSTAR_HOME is %s (via fstar.exe in PATH)\n " ! fstar_home
228- with _ ->
229- fatal_error " Did not find fstar.exe in PATH and FSTAR_HOME is not set"
214+ (* Try to resolve fstar to an absolute path. This is just so the
215+ full path appears in logs. *)
216+ if not (KString. starts_with ! fstar " /" ) then begin
217+ try fstar := read_one_line " which" [| ! fstar |]
218+ with _ -> ()
230219 end ;
231220
232- let fstar_ulib = ! fstar_home ^^ " ulib " in
233- if not ( Sys. file_exists fstar_ulib && Sys. is_directory fstar_ulib) ; then begin
234- if not ! Options. silent then
235- KPrint. bprintf " F* library not found in ulib; falling back to lib/fstar \n " ;
236- fstar_lib := ! fstar_home ^^ " lib " ^^ " fstar "
237- end else begin
238- fstar_lib := fstar_ulib
221+ if not ! Options. silent then
222+ KPrint. bprintf " Using fstar.exe = %s \n " ! fstar;
223+
224+ (* Ask F* for the location of its library *)
225+ begin try fstar_lib := read_one_line ! fstar [| " --locate_lib " |]
226+ with | _ ->
227+ fatal_error " Could not locate F* library: %s --locate_lib failed " ! fstar
239228 end ;
229+ if not ! Options. silent then
230+ KPrint. bprintf " F* library root: %s\n " ! fstar_lib;
240231
241232 if success " which" [| " cygpath" |] then begin
242233 fstar := read_one_line " cygpath" [| " -m" ; ! fstar |];
243234 if not ! Options. silent then
244235 KPrint. bprintf " %sfstar converted to windows path:%s %s\n " Ansi. underline Ansi. reset ! fstar;
245- fstar_home := read_one_line " cygpath" [| " -m" ; ! fstar_home |];
246- if not ! Options. silent then
247- KPrint. bprintf " %sfstar home converted to windows path:%s %s\n " Ansi. underline Ansi. reset ! fstar_home;
248236 fstar_lib := read_one_line " cygpath" [| " -m" ; ! fstar_lib |];
249237 if not ! Options. silent then
250238 KPrint. bprintf " %sfstar lib converted to windows path:%s %s\n " Ansi. underline Ansi. reset ! fstar_lib
251239 end ;
252240
253- if try Sys. is_directory (! fstar_home ^^ " .git" ) with Sys_error _ -> false then begin
254- let cwd = Sys. getcwd () in
255- Sys. chdir ! fstar_home;
256- let branch = read_one_line " git" [| " rev-parse" ; " --abbrev-ref" ; " HEAD" |] in
257- fstar_rev := String. sub (read_one_line " git" [| " rev-parse" ; " HEAD" |]) 0 8 ;
258- let color = if branch = " master" then Ansi. green else Ansi. orange in
241+ (* Record F* version, as output by the executable. *)
242+ begin try
243+ let lines = Process. read_stdout ! fstar [| " --version" |] in
244+ fstar_rev := String. trim (String. concat " " lines);
259245 if not ! Options. silent then
260- KPrint. bprintf " fstar is on %sbranch %s %s\n " color branch Ansi. reset;
261- Sys. chdir cwd
246+ KPrint. bprintf " %sfstar version:%s %s\n " Ansi. underline Ansi. reset ! fstar_rev
247+ with | _ -> ()
262248 end ;
263249
264250 let fstar_includes = List. map expand_prefixes ! Options. includes in
@@ -268,7 +254,16 @@ let detect_fstar () =
268254 ] @ List. flatten (List. rev_map (fun d -> [" --include" ; d]) fstar_includes);
269255 (* This is a superset of the needed modules... some will be dropped very early
270256 * on in Karamel.ml *)
271- fstar_options := (! fstar_lib ^^ " FStar.UInt128.fst" ) :: ! fstar_options;
257+
258+ (* Locate and pass FStar.UInt128 *)
259+ let fstar_locate_file f =
260+ try read_one_line ! fstar [| " --locate_file" ; f |]
261+ with
262+ | _ ->
263+ Warn. fatal_error " Could not locate file %s, is F* properly installed?" f
264+ in
265+ fstar_options := fstar_locate_file " FStar.UInt128.fst" :: ! fstar_options;
266+
272267 fstar_options := (! runtime_dir ^^ " WasmSupport.fst" ) :: ! fstar_options;
273268 if not ! Options. silent then
274269 KPrint. bprintf " %sfstar is:%s %s %s\n " Ansi. underline Ansi. reset ! fstar (String. concat " " ! fstar_options);
0 commit comments