Skip to content

Commit

Permalink
Merge pull request #794 from ocsigen/config
Browse files Browse the repository at this point in the history
Use Eliom without configuration file (static link)
  • Loading branch information
balat authored Sep 2, 2024
2 parents 41d997c + 56d77b8 commit 4b1eab5
Show file tree
Hide file tree
Showing 87 changed files with 1,691 additions and 313 deletions.
2 changes: 1 addition & 1 deletion doc/index.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

<<a_api subproject="client" text="Client" | intro >>

<<a_api subproject="ocamlbuild" text="The ocamlbuild plugin" | intro >>
<<|a_api subproject="ocamlbuild" text="The ocamlbuild plugin" | intro >>
5 changes: 0 additions & 5 deletions doc/ocamlbuild.indexdoc

This file was deleted.

6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(lang dune 3.6)

(name eliom)
(version 10.4.1)
(version 11.0.0)
(maintainers [email protected])
(authors [email protected])
(license "LGPL-2.1-only WITH OCaml-LGPL-linking-exception")
Expand Down Expand Up @@ -34,11 +34,11 @@ The client-side code is compiled to JS using Ocsigen Js_of_ocaml or to Wasm usin
lwt_log
(lwt_ppx (>= 1.2.3))
(tyxml (and (>= 4.6.0) (< 4.7.0)))
(ocsigenserver (and (>= 5.1.0) (< 6.0.0)))
(ocsigenserver (and (>= 6.0.0) (< 7.0.0)))
(ipaddr (>= 2.1))
(reactiveData (>= 0.2.1))
base-bytes
(ocsipersist (and (>= 1.0) (< 2.0)))
(ocsipersist (and (>= 2.0) (< 3.0)))
ppx_optcomp))

(generate_opam_files)
6 changes: 3 additions & 3 deletions eliom.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "10.4.1"
version: "11.0.0"
synopsis: "Advanced client/server Web and mobile framework"
description: """
Eliom is a framework for implementing Web sites and client/server Web and mobile applications.
Expand Down Expand Up @@ -32,11 +32,11 @@ depends: [
"lwt_log"
"lwt_ppx" {>= "1.2.3"}
"tyxml" {>= "4.6.0" & < "4.7.0"}
"ocsigenserver" {>= "5.1.0" & < "6.0.0"}
"ocsigenserver" {>= "6.0.0" & < "7.0.0"}
"ipaddr" {>= "2.1"}
"reactiveData" {>= "0.2.1"}
"base-bytes"
"ocsipersist" {>= "1.0" & < "2.0"}
"ocsipersist" {>= "2.0" & < "3.0"}
"ppx_optcomp"
"odoc" {with-doc}
]
Expand Down
6 changes: 4 additions & 2 deletions pkg/distillery/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(data_only_dirs templates)
(install
(section lib)
(files (glob_files templates/client-server.basic/**)
(glob_files templates/basic.ppx/**)))
(files
(glob_files templates/app.exe/**)
(glob_files templates/app.lib/**)
(glob_files templates/basic.ppx/**)))
13 changes: 13 additions & 0 deletions pkg/distillery/templates/app.exe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Local server configuration
local

# Eliom
.depend
_client
_deps
_server

static/css/project_name.css.map

# Dune
_build
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ include Makefile.options

# Eliom default makefile
# Makefile.PROJECT_NAME is also included in this makefile
include Makefile.eliom
include Makefile.app
122 changes: 122 additions & 0 deletions pkg/distillery/templates/app.exe/Makefile.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
##----------------------------------------------------------------------
## DISCLAIMER
##
## This file contains the rules to make an Eliom project. The project is
## configured through the variables in the file Makefile.options.
##----------------------------------------------------------------------

##----------------------------------------------------------------------
## Internals

## Required binaries
OCSIGENSERVER := ocsigenserver
OCSIGENSERVER.OPT := ocsigenserver.opt

ifneq ($(DEBUG),yes)
DUNE_OPTIONS = --profile release
endif

##----------------------------------------------------------------------

##----------------------------------------------------------------------
## General

.PHONY: all css byte opt

DIST_DIRS := $(ETCDIR) $(DATADIR) $(LIBDIR) $(LOGDIR) \
$(FILESDIR)/avatars/tmp $(ELIOMSTATICDIR) \
$(shell dirname $(CMDPIPE))
JS_PREFIX := $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME)

all:: css byte opt staticfiles

##----------------------------------------------------------------------

##----------------------------------------------------------------------
## Testing

DIST_FILES = $(ELIOMSTATICDIR)/$(PROJECT_NAME).js $(LIBDIR)/$(PROJECT_NAME).cma

.PHONY: test.byte test.opt staticfiles

test.byte:: byte | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
dune exec ./$(PROJECT_NAME)_main.bc
test.opt:: opt | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
dune exec ./$(PROJECT_NAME)_main.exe

test.static.byte: test.byte

test.static.opt: test.opt

$(addprefix $(TEST_PREFIX), $(DIST_DIRS)):
mkdir -p $@

staticfiles:
cp -rf $(LOCAL_STATIC_CSS) $(TEST_PREFIX)$(ELIOMSTATICDIR)

##----------------------------------------------------------------------
## Installing & Running

.PHONY: install install.static install.lib run
install: all install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE)))
dune install
install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(STATICDIR) $(PREFIX)$(ELIOMSTATICDIR)
cp -r $(LOCAL_STATIC_CSS) $(PREFIX)$(FILESDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(FILESDIR)

.PHONY:
print-install-files:
@echo $(PREFIX)$(LIBDIR)
@echo $(PREFIX)$(ELIOMSTATICDIR)
@echo $(PREFIX)$(ETCDIR)

$(addprefix $(PREFIX),$(ETCDIR) $(LIBDIR)):
install -d $@
$(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(ELIOMSTATICDIR) $(shell dirname $(CMDPIPE))):
install $(addprefix -o ,$(WWWUSER)) -d $@

##----------------------------------------------------------------------

##----------------------------------------------------------------------
## Compilation

.PHONY: gen-dune config-files

config-files: | $(TEST_PREFIX)$(ELIOMSTATICDIR) $(TEST_PREFIX)$(LIBDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.js $(JS_PREFIX)_$$HASH.js && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(JS_PREFIX).js
cp -f _build/default/$(PROJECT_NAME).cm* $(TEST_PREFIX)$(LIBDIR)/

all::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) @install @$(PROJECT_NAME)

js::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) client/$(PROJECT_NAME).bc.js

byte:: js
$(ENV_PSQL) dune build $(DUNE_OPTIONS) $(PROJECT_NAME)_main.bc
make config-files PROJECT_NAME=$(PROJECT_NAME)

opt:: js
$(ENV_PSQL) dune build $(DUNE_OPTIONS) $(PROJECT_NAME)_main.exe
make config-files PROJECT_NAME=$(PROJECT_NAME)

run:
$(PREFIX)bin/$(PROJECT_NAME)


##----------------------------------------------------------------------

##----------------------------------------------------------------------
## Clean up

.PHONY: clean

clean::
dune clean
77 changes: 77 additions & 0 deletions pkg/distillery/templates/app.exe/Makefile.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#----------------------------------------------------------------------
# SETTINGS FOR THE ELIOM PROJECT %%%PROJECT_NAME%%%
#----------------------------------------------------------------------
# Required binaries
OPAM := opam

PROJECT_NAME := %%%PROJECT_NAME%%%

##----------------------------------------------------------------------

##----------------------------------------------------------------------
## The following part contains the settings for the compilation process like the
## server/client OPAM packages and the server/client files.

# OCamlfind packages for the server (for modules which defines services)
SERVER_ELIOM_PACKAGES :=

# OCamlfind packages for the server
SERVER_PACKAGES :=

##----------------------------------------------------------------------

##----------------------------------------------------------------------
## The following part contains the configuration for the ocsigenserver.

# Port for running the server (make run)
PORT := 8080

# Port for testing (make test.*)
TEST_PORT := 8080

# Root of installation (must end with /)
# PREFIX := /usr/local/
PREFIX := ${OPAM_SWITCH_PREFIX}/

# Local folder for make test.* (must end with /)
TEST_PREFIX := local/

## The installation tree (relative to $(PREFIX) when installing/running or
## $(TEST_PREFIX) when testing).

# Configuration file $(PROJECT_NAME).conf
ETCDIR := etc/${PROJECT_NAME}

# Project's library $(PROJECT_NAME).cma (cmxs)
LIBDIR := lib/${PROJECT_NAME}

# Command pipe, eg. $ echo restart > $(INSTALL_PREFIX)$(CMDPIPE)
CMDPIPE := var/run/${PROJECT_NAME}-cmd

# Ocsigenserver's logging files
LOGDIR := var/log/${PROJECT_NAME}

# Ocsigenserver's persistent data files
DATADIR := var/data/${PROJECT_NAME}

# Project's static files
FILESDIR := var/www/${PROJECT_NAME}

# Project's JavaScript file directory
ELIOMSTATICDIR := var/www/${PROJECT_NAME}

LOCAL_STATIC := static
LOCAL_STATIC_CSS := $(LOCAL_STATIC)/css
CSS_PREFIX := $(LOCAL_STATIC_CSS)/${PROJECT_NAME}
##----------------------------------------------------------------------


##----------------------------------------------------------------------
## The following part contains the settings for debugging

# Debug application (yes/no): Debugging info in compilation,
# JavaScript, ocsigenserver
DEBUG := yes

##----------------------------------------------------------------------

42 changes: 42 additions & 0 deletions pkg/distillery/templates/app.exe/PROJECT_NAME.eliom
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(* This file was generated by Eliom-distillery.
Feel free to use it, modify it, and redistribute it as you wish. *)

let%server application_name = "%%%PROJECT_NAME%%%"
let%client application_name = Eliom_client.get_application_name ()

let%server () =
Ocsipersist_settings.set_db_file "local/var/data/%%%PROJECT_NAME%%%/%%%PROJECT_NAME%%%_db";

(* Create a module for the application. See
https://ocsigen.org/eliom/manual/clientserver-applications for more
information. *)
module%shared App = Eliom_registration.App (struct
let application_name = application_name
let global_data_path = Some ["__global_data__"]
end)

(* As the headers (stylesheets, etc) won't change, we ask Eliom not to
update the <head> of the page when changing page. (This also avoids
blinking when changing page in iOS). *)
let%client _ = Eliom_client.persist_document_head ()

let%server main_service =
Eliom_service.create ~path:(Eliom_service.Path [])
~meth:(Eliom_service.Get Eliom_parameter.unit) ()

let%client main_service = ~%main_service

let%shared () =
App.register ~service:main_service (fun () () ->
Lwt.return
Eliom_content.Html.F.(
html
(head
(title (txt "%%%PROJECT_NAME%%%"))
[ css_link
~uri:
(make_uri
~service:(Eliom_service.static_dir ())
["css"; "%%%PROJECT_NAME%%%.css"])
() ])
(body [h1 [txt "Welcome to Eliom!"]])))
9 changes: 9 additions & 0 deletions pkg/distillery/templates/app.exe/PROJECT_NAME.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
opam-version: "2.0"
name: "%%%PROJECT_NAME%%%"
version: "0.1"
synopsis: "%%%PROJECT_NAME%%%"

depends: [
"eliom" {>= "11.0.0" & < "12.0.0"}
"ocsipersist-sqlite-config" {>= "2.0" & < "3.0"}
]
18 changes: 18 additions & 0 deletions pkg/distillery/templates/app.exe/PROJECT_NAME_main.eliom
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(** This is the main file if you are using static linking without config file.
*)

module%shared %%%MODULE_NAME%%% = %%%MODULE_NAME%%%

let%server _ =
Ocsigen_server.start
~ports:[`All, 8080]
~veryverbose:()
~debugmode:true
~logdir:"local/var/log/%%%PROJECT_NAME%%%"
~datadir:"local/var/data/%%%PROJECT_NAME%%%"
~uploaddir:(Some "/tmp")
~usedefaulthostname:true
~command_pipe:"local/var/run/%%%PROJECT_NAME%%%-cmd"
~default_charset:(Some "utf-8")
[ Ocsigen_server.host
[Staticmod.run ~dir:"local/var/www/%%%PROJECT_NAME%%%" (); Eliom.run ()] ]
Loading

0 comments on commit 4b1eab5

Please sign in to comment.