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

Introduce --ocamlenv #3565

Merged
merged 7 commits into from
Oct 14, 2024
Merged

Introduce --ocamlenv #3565

merged 7 commits into from
Oct 14, 2024

Conversation

mtzguido
Copy link
Member

This options allows to easily extend a shell with an OCAMLPATH suitable
for building F* OCaml programs, and also to simply run a build command easily
by prepending fstar.exe --ocamlenv to it.

Example below.

module Hello
open FStar.IO
let _ = print_string "Hello F*!\n"
$ fstar.exe --ocamlenv
OCAMLPATH='/home/guido/r/fstar/master/lib:'; export OCAMLPATH;

$ fstar.exe --ocamlenv ocamlfind ocamlopt -linkpkg -package fstar.lib Hello.ml
findlib: [WARNING] Interface ratio.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, home/guido/.opam/4.14.1/lib/ocaml
findlib: [WARNING] Interface num.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, home/guido/.opam/4.14.1/lib/ocaml
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/ocaml/compiler-libs, home/guido/.opam/4.14.1/lib/ocaml
findlib: [WARNING] Interface big_int.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, home/guido/.opam/4.14.1/lib/ocaml
findlib: [WARNING] Interface nat.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, home/guido/.opam/4.14.1/lib/ocaml
findlib: [WARNING] Interface arith_status.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, home/guido/.opam/4.14.1/lib/ocaml
ocamlfind: [WARNING] Package `threads': Linking problems may arise because of the missing -thread or -vmthread switch
$ ./a.out
Hello F*!

Obviously the command required is not as simple as it could be, but this
is already an improvement since it provides a standard way of locating
the needed OCAMLPATHs.

This options allows to easily extend a shell with an OCAMLPATH suitable
for building F* OCaml programs, and also to simply run a build command easily
by prepending `fstar.exe --ocamlenv` to it.

Example below.

Hello.fst:
	module Hello
	open FStar.IO
	let _ = print_string "Hello F*!\n"

	$ fstar.exe --ocamlenv
	OCAMLPATH='/home/guido/r/fstar/master/lib:'; export OCAMLPATH;

	$ fstar.exe --ocamlenv ocamlfind ocamlopt -linkpkg -package fstar.lib Hello.ml
	findlib: [WARNING] Interface ratio.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, /home/guido/.opam/4.14.1/lib/ocaml
	findlib: [WARNING] Interface num.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, /home/guido/.opam/4.14.1/lib/ocaml
	findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/ocaml/compiler-libs, /home/guido/.opam/4.14.1/lib/ocaml
	findlib: [WARNING] Interface big_int.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, /home/guido/.opam/4.14.1/lib/ocaml
	findlib: [WARNING] Interface nat.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, /home/guido/.opam/4.14.1/lib/ocaml
	findlib: [WARNING] Interface arith_status.cmi occurs in several directories: /home/guido/.opam/4.14.1/lib/num, /home/guido/.opam/4.14.1/lib/ocaml
	ocamlfind: [WARNING] Package `threads': Linking problems may arise because of the missing -thread or -vmthread switch
	$ ./a.out
	Hello F*!

Obviously the command required is not as simple as it could be, but this
is already an improvement since it provides a standard way of locating
the needed OCAMLPATHs.
let shellescape (s:string) : string =
String.list_of_string s |>
List.map (function
| '\\' -> "\\\\" // backslashes can be escaped by themselves
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this works:

❯ echo '\\'
\\

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah thanks! I misremembered, backslashes don't need escaping in single quotes.

@mtzguido mtzguido merged commit da7184a into FStarLang:master Oct 14, 2024
2 checks passed
@mtzguido mtzguido deleted the ocamlenv branch October 14, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants