leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.06k stars 25 forks source link

Rust not mentioned in documentation + `make deps build` fails #40

Closed nicobao closed 3 years ago

nicobao commented 3 years ago

Describe the bug

The documentation does not inform users that cargo and rust dependencies are needed to build ocaml-tree-sitter when running make deps build.

Even when rust version 1.49.0 is installed, the following error occurs:

nicolas@localhost:~/nicobao/caramel$ make deps build
opam install dune menhir ocaml-compiler-libs cmdliner ppx_sexp_conv sexplib ocamlformat bisect_ppx
[NOTE] Package bisect_ppx is already installed (current version is 2.5.0).
[NOTE] Package ocamlformat is already installed (current version is 0.15.0).
[NOTE] Package sexplib is already installed (current version is v0.14.0).
[NOTE] Package ppx_sexp_conv is already installed (current version is v0.14.1).
[NOTE] Package cmdliner is already installed (current version is 1.0.4).
[NOTE] Package ocaml-compiler-libs is already installed (current version is v0.12.3).
[NOTE] Package menhir is already installed (current version is 20201216).
[NOTE] Package dune is already installed (current version is 2.7.1).
dune build @all -j8
         gcc ocaml-tree-sitter/tests/sexp_parser.o (exit 1)
(cd _build/default/ocaml-tree-sitter/tests && /usr/lib64/ccache/gcc -O2 -fno-strict-aliasing -fwrapv -fPIC -D_FILE_OFFSET_BITS=64 -D_REENTRANT -O2 -fno-strict-aliasing -fwrapv -fPIC -g -I /home/nicolas/.opam/default/lib/ocaml -I ../src -o sexp_parser.o -c sexp_parser.c)
sexp_parser.c:1:10: fatal error: tree_sitter/parser.h: No such file or directory
    1 | #include <tree_sitter/parser.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
       bootc src/stdlib/beam/beam.{cma,cmi},src/stdlib/beam/binary.{cma,cmi},src/stdlib/beam/calendar.{cma,cmi},src/stdlib/beam/caramel_runtime.{cma,cmi},src/stdlib/beam/erlang.{cma,cmi},src/stdlib/beam/ets.{cma,cmi},src/stdlib/beam/io.{cma,cmi},src/stdlib/beam/lists.{cma,cmi},src/stdlib/beam/maps.{cma,cmi},src/stdlib/beam/process.{cma,cmi,erl},src/stdlib/beam/timer.{cma,cmi}
Compiling maps.erl  OK
Compiling ets.erl   OK
Compiling erlang.erl    OK
Compiling calendar.erl  OK
Compiling binary.erl    OK
Compiling io.erl    OK
Compiling process.erl   OK
       cargo ocaml-tree-sitter/src/dllocaml_tree_sitter.so,ocaml-tree-sitter/src/libocaml_tree_sitter.a (exit 101)
(cd _build/default/ocaml-tree-sitter/src && /home/nicolas/.cargo/bin/cargo build --target-dir ../../target)
    Updating crates.io index
    Updating git repository `https://github.com/AbstractMachinesLab/tree-sitter-sexp`
   Compiling cc v1.0.66
   Compiling memchr v2.3.4
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.58
   Compiling lazy_static v1.4.0
   Compiling regex-syntax v0.6.22
   Compiling anyhow v1.0.37
   Compiling ocaml-sys v0.19.0
   Compiling cty v0.2.1
   Compiling thread_local v1.1.0
   Compiling aho-corasick v0.7.15
   Compiling quote v1.0.8
   Compiling tree-sitter v0.17.1
   Compiling tree-sitter v0.17.1 (/home/nicolas/nicobao/tree-sitter/lib)
   Compiling tree-sitter-sexp v0.1.0 (https://github.com/AbstractMachinesLab/tree-sitter-sexp?branch=main#b46b9f78)
   Compiling regex v1.4.3
   Compiling synstructure v0.12.4
   Compiling ocaml-derive v0.19.0
   Compiling ocaml v0.19.0
   Compiling ocaml-tree-sitter v0.1.0 (/home/nicolas/nicobao/caramel/_build/default/ocaml-tree-sitter)
error[E0603]: module `ffi` is private
   --> src/lib.rs:147:53
    |
147 |     let raw_lang = raw_ptr.0 as *const tree_sitter::ffi::TSLanguage;
    |                                                     ^^^ private module
    |
note: the module `ffi` is defined here
   --> /home/nicolas/nicobao/tree-sitter/lib/binding_rust/lib.rs:1:1
    |
1   | mod ffi;
    | ^^^^^^^^

error[E0603]: tuple struct constructor `Language` is private
   --> src/lib.rs:148:29
    |
148 |     let lang = tree_sitter::Language(raw_lang);
    |                             ^^^^^^^^ private tuple struct constructor
    | 
   ::: /home/nicolas/nicobao/tree-sitter/lib/binding_rust/lib.rs:34:21
    |
34  | pub struct Language(*const ffi::TSLanguage);
    |                     ---------------------- a constructor is private if any of the fields is private
    |
note: the tuple struct constructor `Language` is defined here
   --> /home/nicolas/nicobao/tree-sitter/lib/binding_rust/lib.rs:34:1
    |
34  | pub struct Language(*const ffi::TSLanguage);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

To Reproduce

  1. Install the rust toolchain : https://www.rust-lang.org/tools/install
  2. Run make deps build in the root directory of the repository

Expected behavior

The build should succeed.

Desktop (please complete the following information):

Additional information

Content of ocaml-tree-sitter/Cargo.toml was modified:

[package]
name = "ocaml-tree-sitter"
version = "0.1.0"
authors = ["Leandro Ostera <leandro@ostera.io>"]
edition = "2018"

[lib]
crate-type = ["staticlib", "cdylib"]

[dependencies]
anyhow = "*"
ocaml = "*"
tree-sitter =  { path = "/home/nicolas/nicobao/tree-sitter/lib" }
tree-sitter-sexp = { git = "https://github.com/AbstractMachinesLab/tree-sitter-sexp", branch = "main" }

The tree-sitter dependency corresponds to my local fork of tree-sitter. If i use "*" instead of { path = "/home/nicolas/nicobao/tree-sitter/lib" }, I get the same error.

leostera commented 3 years ago

I've inverted the dependency on ocaml-tree-sitter so the erlang module doesn't actually depend on it for parsing, and instead just provides the tree types.

This means we don't need Rust and Cargo anymore for building Caramel 😃

We're still using the Menhir parser for now, but in the future we'll get rid of that as well so the erlang library is just a collection of types, a printer, and some utilities to work with these.