ocsigen / eliom

Multi-tier framework for programming web and mobile applications in OCaml.
http://eliom.org
Other
305 stars 54 forks source link

Oasis + Eliom --> Problem to link Javascript #100

Open hhugo opened 10 years ago

hhugo commented 10 years ago

I'm trying to create a template of a website whose compilation is based on Oasis. With the help of some doc and the Cumulus github page (thank you it's really usefull) I made a first version which can display a page. The problem is that the javascript code isn't launch. In fact I don't even know how to say "please add this library to the JS file" in the oasis file.

If you want to test on the same code as me, is the code I use : https://github.com/tobiasBora/eliom_template_oasis_03.

To run it :

  • [Optional] oasis setup
  • ./configure
  • make
  • make run

(This script should copy the js file in the (local) static dir, the problem doesn't come from here.)

And after just open http://localhost:8080/. The basic page is opened, but if you click on "Hello" you are supposed to see an alert message... Which never happened. I have the error Failure(Client closure 872924384 not found (is the module linked on the client?))

As you can see the library isn't linked to the client.

Could you please explain me how I could link the client part of a library to the JS file with Oasis ?

hhugo commented 10 years ago

@balat, another exemple of the issue. we need documentation on this.

hhugo commented 10 years ago

cc @tobiasBora

hhugo commented 10 years ago

1 - One way to fix this is to have a client lib, and link with it. 2 - Another way is to pack all the client files and generate the bytecode from it. (*.mlpack -> *.cmo -> *.byte )

First solution here https://github.com/hhugo/eliom_template_oasis_03/commit/8702adaafc78aabf935cf25cb773a7bc4b7246ac

tobiasBora commented 10 years ago

Thank you so much for your help it works great !

I have just a few questions: 1) In BuildDepends you use "monproj.client", and I'm not sure to understand what is the meaning of ".client". Is it because the module "monproj" has a submodule named client (automatiquely constructed by eliom) or is it something completly different ?

2) When you configured the path in _oasis you added everywhere a subfolder "client" or "server", but the file .eliom isn't in these subfolder but in their parents. How can ocamlbuild find the eliom file and split it in client/server if we never say where it is ? Is it smart enough to say "if there is a "client" folder, the eliom file should be in the parent folder" ?

3) What is the method used by Cumulus to link client modules ? Because I can't see a specific input in _oasis for client libraries, and I don't see any mlpack file.

4) Do you have an example website where the mlpack method is used ? I tried to create the file -> src/monproj.mlpack client/monproj main/client/an_eliom_file

but it doesn't work.

Thank you !

hhugo commented 10 years ago

1- monproj.client refers to the findlib package defined by

FindlibName: client
FindlibParent: monproj

2 - ocamlbuild_eliom plugin tell ocamlbuild that if there is no file matching */client/blah.ml, it can be copied from the parent directory */blah.eliom (with the right syntaxes). You actually give location information with Ocamlbuild_eliom.Make(....)

3 - @jpdeplaix

4 - I'll give it a try

hhugo commented 10 years ago

@tobiasBora: example using pack https://github.com/hhugo/eliom_template_oasis_03/commit/1b444b325b2d82f1bb3ae17011c4816a873d90db

tobiasBora commented 10 years ago

1) Uhm ok thank you

2) Ok that's clearer now.

4) Thank you so much ! Your version works great, and mlpack is really clearer. There is however a little problem: all the packages are picked in the same folder src/ from the mlpack file src/monproj.mlpack. I though that I understood the functionment

(I see mlpack like a "search game": we ask to compile monproj.ml <--- (=which is build from) monproj.mlpack <--- eliomfile.ml <--- ../eliomfile.eliom...)

so I tried to apply the same thing with subfolders and I wanted this "map" in order to keep libraries in differents folders (in this example "hello" is my library): src/client/monproj.ml <-- src/client/monproj.mlpack <-- src/hello/client/hello.mlpack ... so I created a new mlpack file in src/hello/ (I want the whole code of my library to be in the hello subfolder) linked in the initial repo. However when it compiles I have an error like

Solver failed:
  Ocamlbuild knows of no rules that apply to a target named src/monproj.eliom.

You can find my test code right here in a new branch "pack" : https://github.com/tobiasBora/eliom_template_oasis_03/tree/pack/

If you know what is wrong or have any other idea to separate several libraries in several folders (one folder for each library), I'm very interested !

Thank you in advance,

Tobias.

tobiasBora commented 10 years ago

Any idea ?

hhugo commented 10 years ago

I think ocamlbuild doesn't like to deal with .. path. If you want many libs (in different directory), DECLARE may libs !!

library "A_client"
  Path: path_A/client
  Modules: MA1,MA2

library "B_client"
  Path: path_B/client
  Modules: MB1,MB2

Executable "main"
  Path: main/client
  MainIs: main.ml
  BuildDepends: B_client,A_client

and add linkall option to main/client/main.byte by adding the following in the _tags file :

<main/client/main.byte>: linkall
hhugo commented 10 years ago

@tobiasBora, Is this resolved ?

tobiasBora commented 10 years ago

Thank you for your help !

I'm sorry for the time I made to answer, but I tried your way during a few hours and I didn't manage to make it working, and after I have been having some exams so I didn't have much time to continue to work on this issue.

I tried again today to solve it and I manage to create a basic working code with the first version (the one without any pack file), one problem I have had was that I had forgotten to add in the conf file of ocsigenserver the new libs (I understand little by little how it works ^^).

However I can't manage to make the "pack" version working. I tried to put a basic mlpack file in src/ which points on several libs, the server part is ok, but there isn't any JS file created for the client part.

shonfeder commented 7 years ago

I'm hitting a similar problem, and am preparing to dive in to this rabbit to figure out what precisely is going on and how I can work out the kinks. I'm just giving this a slight bump, since it is still open, but also pretty stale, so I wonder if there hasn't been some significant improvement on this front...