janestreet / bonsai

A library for building dynamic webapps, using Js_of_ocaml
MIT License
367 stars 39 forks source link

can't get started #12

Closed mudrz closed 3 years ago

mudrz commented 3 years ago

hey, what is the simplest way to try out bonsai? it seems that the examples are using an unreleased version and do not work

dune build
File "src/bin/dune", line 4, characters 12-22:
4 |  (libraries bonsai_web)
                ^^^^^^^^^^
Error: Library "bonsai_web" not found.
Hint: try:
  dune external-lib-deps --missing @@default
make: *** [build] Error 1
dune external-lib-deps --missing @@default
Error: The following libraries are missing in the default context:
- bonsai_web
Hint: try:
  opam install bonsai_web
opam install bonsai_web
[ERROR] No package named bonsai_web found.

I finally tried to rename bonsai_web to bonsai.web, but the very first line results in a type error

let (_ : _ Start.Handle.t) =
  Start.start Start.Result_spec.just_the_view ~bind_to_element_with_id:"app" component
;;
[ocamllsp] [E] This expression has type
  initial_input:'a -> ('a, 'b, 'c, 'd) Bonsai_web.Start.Handle.t
but an expression was expected of type
  ('e, 'f, 'g, 'h) Bonsai_web.Start.Handle.t =
    ('e, 'f, 'g, 'h) Bonsai_web__Start.Handle.t

thanks

TyOverby commented 3 years ago

It looks like you're building the examples with the version of the bonsai library on Opam. If you're downloading the examples off of github, then you need to use the github version of the Bonsai libray.

And if you're using the version of Bonsai off of github, you need to do the same with all of its transitive dependencies. You can find the instructions on how to do that here:

https://github.com/janestreet/opam-repository

mudrz commented 3 years ago

thanks @TyOverby , I added the janestreet repository, but core does not build (ocaml 4.11.1)

[ERROR] The compilation of core failed at "/.opam/opam-init/hooks/sandbox.sh build dune build -p
        core -j 7".
-> installed async_js.v0.15~preview.124.16+217
-> installed incr_dom.v0.15~preview.124.16+217

#=== ERROR while compiling core.v0.15~preview.124.16+217 ======================#
# context     2.0.8 | macos/x86_64 | ocaml-base-compiler.4.11.1 | https://ocaml.janestreet.com/opam-repository
# path        ~/projects/bonsai_test/_opam/.opam-switch/build/core.v0.15~preview.124.16+217
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p core -j 7
# exit-code   1
# env-file    ~/.opam/log/core-8944-1fefce.env
# output-file ~/.opam/log/core-8944-1fefce.out
### output ###
# #warning "_POSIX_PRIORITY_SCHEDULING not present; sched_setscheduler undefined"
# [...]
# 4 warnings generated.
#           cc src/unix_time_stubs.o (exit 1)
# (cd _build/default/src && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -D_FILE_OFFSET_BITS=64 -D_REENTRANT -O2 -fno-strict-aliasing -fwrapv -D_LARGEFILE64_SOURCE -g -I /projects/bonsai_test/_opam/lib/ocaml -I /projects/bonsai_test/_opam/lib/base -I /projects/bonsai_test/_opam/lib/base/base_internalhash_types -I /projects/bonsai_test/_opam/lib/base/caml -I /User[...]
# unix_time_stubs.c:57:13: error: implicit declaration of function 'clock_getcpuclockid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
#   int ret = clock_getcpuclockid(pid, &clock);
#             ^
# unix_time_stubs.c:57:13: note: did you mean 'caml_clock_getcpuclockid'?
# unix_time_stubs.c:52:16: note: 'caml_clock_getcpuclockid' declared here
# CAMLprim value caml_clock_getcpuclockid(value v_pid) {
#                ^
# 1 error generated.

do I need a particular version of ocaml? and are there any example links/tutorials for the stable/released bonsai version?

TyOverby commented 3 years ago

do I need a particular version of ocaml?

I don't believe that there should be an problem with 4.11.1, but maybe the fact that you're building on OSX is an issue? Maybe you could re-open over in the https://github.com/janestreet/core repo.

and are there any example links/tutorials for the stable/released bonsai version?

No, but honestly, there aren't really many tutorials for the unreleased bonsai versions either.

mudrz commented 3 years ago

thanks TyOverby, created an issue in the core repository https://github.com/janestreet/core/issues/144

there aren't really many tutorials for the unreleased bonsai versions either.

I think the examples would suffice as a starting point; (PS: if getting a wider adoption is a goal for the library - covering simple common scenarios is really helpful, I've used comparatively worse libraries, just because of better docs)

TyOverby commented 3 years ago

If you're interested in using the older, stable release, you can find the examples bundled into the tarball on the opam page

https://opam.ocaml.org/packages/bonsai/

However, if you aren't in a rush, the next stable-release of Bonsai should be out within the next few months.

TyOverby commented 3 years ago

I've built a "bonsai example" repo here that has much simpler build instructions (read the .devcontainer/DOCKERFILE image in that repo)