Skip to content

Commit

Permalink
Build separate libraries for VSGI implementations
Browse files Browse the repository at this point in the history
Organize sources in multiple folders to simplify the build and reduce
dependencies.

 - isolate the use of 'fcgi.h' for 'vsgi-fastcgi'
 - isolate the use of 'gio-unix-2.0' for 'vsgi-cgi'
 - provide a pkg-config file for each implementation

Each VSGI implementation is built as a 'TypeModule' and define the
'plugin_init' symbol to load its 'Server' implementation. This will be
used along with the loader described in #130.

Rename 'Soup' for 'HTTP' to avoid a *dirty* namespace conflict.

Extract the test implementation of VSGI under the name of 'VSGI.Mock'.
  • Loading branch information
arteymix committed Jan 11, 2016
1 parent a8f9ae1 commit 0f5ad51
Show file tree
Hide file tree
Showing 81 changed files with 390 additions and 217 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ Valum is a web micro-framework entirely written in the

```vala
using Valum;
using VSGI.Soup;
using VSGI.HTTP;
var app = new Router ();
Expand Down
3 changes: 1 addition & 2 deletions data/vsgi.pc.in
Expand Up @@ -7,7 +7,6 @@ Name: VSGI
Description: Interface and implementations for various web server technologies
URL: https://github.com/valum-framework/valum
Version: @VERSION@
Requires: glib-2.0 gio-2.0 gthread-2.0 libsoup-2.4
Requires: glib-2.0 gio-2.0 libsoup-2.4
Libs: -L${libdir} -lvsgi
Libs.private: -L${libdir} -lfcgi
Cflags: -I${includedir}/vsgi
6 changes: 3 additions & 3 deletions docs/application.rst
Expand Up @@ -14,7 +14,7 @@ a ``using`` statement as they all respect a common interface.
.. code:: vala
using Valum;
using VSGI.Soup; // or VSGI.FastCGI
using VSGI.HTTP; // or VSGI.FastCGI
Many implementations are provided and documented in :doc:`vsgi/server/index`.

Expand Down Expand Up @@ -55,8 +55,8 @@ Serving the application
-----------------------

This part is pretty straightforward: you create a server that will serve your
application at port ``3003`` and since ``using VSGI.Soup`` was specified,
``Server`` refers to :doc:`vsgi/server/soup`.
application at port ``3003`` and since ``using VSGI.HTTP`` was specified,
``Server`` refers to :doc:`vsgi/server/http`.

.. code:: vala
Expand Down
8 changes: 0 additions & 8 deletions docs/extras/index.rst

This file was deleted.

30 changes: 7 additions & 23 deletions docs/getting-started.rst
Expand Up @@ -27,7 +27,7 @@ the latest changes in the framework.
.. code:: vala
using Valum;
using VSGI.Soup;
using VSGI.HTTP;
var app = new Router ();
Expand All @@ -48,22 +48,6 @@ pretty much what you think is the best for your needs.
build/
src/
app.vala
vapi/
ctpl.vala
fcgi.vala

VAPI bindings
-------------

`CTPL`_ and `FastCGI`_ are not providing Vala bindings, so you need to copy
them in your project ``vapi`` folder. They are included in Valum's
`vapi folder`_ and you can also find more VAPIs in `nemequ/vala-extra-vapis`_
GitHub repository.

.. _CTPL: http://ctpl.tuxfamily.org
.. _FastCGI: http://www.fastcgi.com/drupal/
.. _vapi folder: https://github.com/antono/valum/tree/master/vapi
.. _nemequ/vala-extra-vapis: https://github.com/nemequ/vala-extra-vapis

Building manually
-----------------
Expand All @@ -74,13 +58,13 @@ locations, so this wont be necessary.

.. code-block:: bash
valac --pkg valum --vapidir=vapi
valac --pkg=valum --pkg=vsgi-http --vapidir=vapi
-X -I/usr/local/include/valum -X -lvalum # compiler options
src/app.vala
-o build/app
# if installed in default location /usr
valac --pkg valum --vapidir=vapi src/app.vala -o build/app
valac --pkg=valum --pkg=vsgi-http --vapidir=vapi src/app.vala -o build/app
Building with waf
-----------------
Expand All @@ -101,15 +85,15 @@ at the root of your project.
def configure(cfg):
cfg.load('compiler_c vala')
cfg.check_cfg(package='valum', uselib_store='VALUM', args='--libs --cflags')
cfg.check_cfg(package='vsgi-http', uselib_store='VSGI_HTTP', args='--libs --cflags')
def build(bld):
bld.load('vala')
bld.program(
packages = ['valum'],
packages = ['valum', 'vsgi-http'],
target = 'app',
source = 'src/app.vala',
use = 'VALUM'
vapi_dirs = ['vapi'])
use = 'VALUM VSGI_HTTP')
You should now be able to build by issuing the following commands:

Expand All @@ -124,7 +108,7 @@ Running the example
VSGI produces process-based applications that are either self-hosted or able to
communicate with a HTTP server according to a standardized protocol.

The :doc:`vsgi/server/soup` implementation is self-hosting, so you just have to
The :doc:`vsgi/http/soup` implementation is self-hosting, so you just have to
run it and point your browser at http://127.0.0.1:3003 to see the result.

.. code-block:: bash
Expand Down
2 changes: 2 additions & 0 deletions docs/recipes/index.rst
Expand Up @@ -6,6 +6,8 @@ their potential integration with Valum.

.. toctree::

configuration
json
persistence
static-resource
scripting
2 changes: 1 addition & 1 deletion docs/recipes/persistence.rst
Expand Up @@ -30,7 +30,7 @@ maintained in nemequ/vala-extra-vapis GitHub repository.
.. code:: vala
using Valum;
using VSGI.Soup;
using VSGI.HTTP;
var app = new Router ();
var memcached = new Memcached.Context ();
Expand Down
4 changes: 2 additions & 2 deletions docs/recipes/scripting.rst
Expand Up @@ -20,7 +20,7 @@ Lua
.. code:: vala
using Valum;
using VSGI.Soup;
using VSGI.HTTP;
using Lua;
var app = new Router ();
Expand All @@ -41,7 +41,7 @@ Lua
writer.put_string (lua.do_file ("scripts/hello.lua"));
});
new Soup (app).run ();
new Server ("org.valum.example.Lua", app).run ();
The sample Lua script contains:

Expand Down
2 changes: 1 addition & 1 deletion docs/vsgi/connection.rst
Expand Up @@ -22,7 +22,7 @@ require the status to be part of the response headers.

.. code::
using VSGI.Soup;
using VSGI.HTTP;
new Server ("org.vsgi.App", (req, res) => {
var message = req.connection.output_stream;
Expand Down
2 changes: 1 addition & 1 deletion docs/vsgi/index.rst
Expand Up @@ -30,7 +30,7 @@ a :doc:`request` and a :doc:`response`.

.. code:: vala
using VSGI.Soup;
using VSGI.HTTP;
new Server ("org.vsgi.App", (req, res) => {
// process the request and produce the response...
Expand Down
8 changes: 4 additions & 4 deletions docs/vsgi/server/soup.rst → docs/vsgi/server/http.rst
@@ -1,5 +1,5 @@
libsoup-2.4 built-in server
============================
HTTP
====

libsoup-2.4 provides a `built-in HTTP server`_ that you can use to test your
application or spawn workers in production.
Expand All @@ -9,9 +9,9 @@ application or spawn workers in production.
.. code:: vala
using Valum;
using VSGI.Soup;
using VSGI.HTTP;
new Server ("org.vsgi.Soup", () => {
new Server ("org.vsgi.HTTP", () => {
res.status = Soup.Status.OK;
res.body.write_all ("Hello world!".data, null);
}).run ({"app", "--port", "3003"});
Expand Down
2 changes: 1 addition & 1 deletion docs/vsgi/server/index.rst
Expand Up @@ -8,7 +8,7 @@ host environment.
.. toctree::
:caption: Table of Contents

soup
http
cgi
fastcgi
scgi
Expand Down
2 changes: 1 addition & 1 deletion examples/api-interaction/app.vala
Expand Up @@ -16,7 +16,7 @@
*/

using Valum;
using VSGI.Soup;
using VSGI.HTTP;

var app = new Router ();

Expand Down
1 change: 0 additions & 1 deletion examples/api-interaction/wscript
Expand Up @@ -9,5 +9,4 @@ def build(bld):
target = 'app',
source = 'app.vala',
use = 'valum JSON CTPL',
vapi_dirs = '../../vapi',
install_path = None)
2 changes: 1 addition & 1 deletion examples/app/app.vala
Expand Up @@ -17,7 +17,7 @@

using Valum;
using Valum.ServerSentEvents;
using VSGI.Soup;
using VSGI.HTTP;

var app = new Router ();

Expand Down
1 change: 0 additions & 1 deletion examples/app/wscript
Expand Up @@ -12,5 +12,4 @@ def build(bld):
target = 'app',
source = ['app.vala', 'view.vala', 'app.gresource.xml'],
use = 'valum CTPL GEE',
vapi_dirs = '../../vapi',
install_path = None)
1 change: 0 additions & 1 deletion examples/cgi/wscript
Expand Up @@ -8,5 +8,4 @@ def build(bld):
target = 'cgi-bin/app.cgi',
use = 'valum',
source = ['app.vala'],
vapi_dirs = '../../vapi',
install_path = None)
1 change: 0 additions & 1 deletion examples/fastcgi/wscript
Expand Up @@ -8,6 +8,5 @@ def build(bld):
target = 'fastcgi',
use = 'valum',
source = ['app.vala'],
vapi_dirs = '../../vapi',
install_path = None)

2 changes: 1 addition & 1 deletion examples/genie/app.gs
Expand Up @@ -4,7 +4,7 @@ init

app.get ("", home)

new VSGI.Soup.Server ("org.valum.example.Genie", app.handle).run ({"app", "--all"})
new VSGI.HTTP.Server ("org.valum.example.Genie", app.handle).run ({"app", "--all"})

def home (req : VSGI.Request, res : VSGI.Response) raises IOError
res.body.write_all ("Hello world!".data, null)
1 change: 0 additions & 1 deletion examples/genie/wscript
Expand Up @@ -8,5 +8,4 @@ def build(bld):
target = 'app',
source = 'app.gs',
use = 'valum',
vapi_dirs = '../../vapi',
install_path = None)
2 changes: 1 addition & 1 deletion examples/json/app.vala
Expand Up @@ -16,7 +16,7 @@
*/

using Valum;
using VSGI.Soup;
using VSGI.HTTP;

var app = new Router ();

Expand Down
1 change: 0 additions & 1 deletion examples/json/wscript
Expand Up @@ -9,5 +9,4 @@ def build(bld):
target = 'app',
use = 'valum JSON',
source = 'app.vala',
vapi_dirs = '../../vapi',
install_path = None)
2 changes: 1 addition & 1 deletion examples/lua/app.vala
Expand Up @@ -17,7 +17,7 @@

using Lua;
using Valum;
using VSGI.Soup;
using VSGI.HTTP;

var app = new Router ();
var vm = new LuaVM ();
Expand Down
12 changes: 12 additions & 0 deletions examples/lua/wscript
@@ -0,0 +1,12 @@
#!/usr/bin/env python

def configure(cfg):
cfg.check_cfg(package='luajit', uselib_store='LUA', args='--cflags --libs')

def build(bld):
bld.program(
packages = 'lua',
target = 'app',
source = 'app.vala',
use = 'valum LUA',
install_path = None)
10 changes: 0 additions & 10 deletions examples/lua/wscript_build

This file was deleted.

3 changes: 0 additions & 3 deletions examples/lua/wscript_configure

This file was deleted.

2 changes: 1 addition & 1 deletion examples/markdown/app.vala
@@ -1,6 +1,6 @@
using Markdown;
using Valum;
using VSGI.Soup;
using VSGI.HTTP;

var app = new Router ();

Expand Down
2 changes: 1 addition & 1 deletion examples/markdown/wscript
Expand Up @@ -9,5 +9,5 @@ def build(bld):
target = 'app',
source = 'app.vala',
use = 'valum MARKDOWN',
vapi_dirs = ['vapi', '../../vapi'],
vapi_dirs = 'vapi',
install_path = None)
2 changes: 1 addition & 1 deletion examples/memcached/app.vala
Expand Up @@ -16,7 +16,7 @@
*/

using Valum;
using VSGI.Soup;
using VSGI.HTTP;

var app = new Router ();
var memcached = new Memcached.Context.from_configuration ("--SERVER=localhost".data);
Expand Down
2 changes: 1 addition & 1 deletion examples/memcached/wscript
Expand Up @@ -9,5 +9,5 @@ def build(bld):
target = 'app',
source = 'app.vala',
use = 'valum MEMCACHED',
vapi_dirs = ['vapi', '../../vapi'],
vapi_dirs = 'vapi',
install_path = None)
3 changes: 1 addition & 2 deletions examples/scgi/wscript
Expand Up @@ -7,6 +7,5 @@ def build(bld):
bld.program(
target = 'app',
use = 'valum',
source = ['app.vala'],
vapi_dirs = '../../vapi',
source = 'app.vala',
install_path = None)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions src/valum/wscript
@@ -0,0 +1,16 @@
#!/usr/bin/env python

def configure(cfg):
pass

def build(bld):
from waflib import Context
bld.load('vala')
bld.shlib(
target = 'valum',
gir = 'Valum-{}'.format(Context.g_module.API_VERSION),
source = bld.path.ant_glob('*.vala'),
use = 'vsgi',
header_path = '${INCLUDEDIR}/valum',
install_path = '${LIBDIR}')

11 changes: 11 additions & 0 deletions src/vsgi-cgi/vsgi-cgi.pc.in
@@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: VSGI.CGI
Description: CGI implementation for VSGI
URL: https://github.com/valum-framework/valum
Version: @VERSION@
Libs: -L${libdir} -lvsgi-cgi
Cflags: -I${includedir}/vsgi
2 changes: 1 addition & 1 deletion src/vsgi-cgi.vala → src/vsgi-cgi/vsgi-cgi.vala
Expand Up @@ -142,7 +142,7 @@ namespace VSGI.CGI {
protected override uint8[]? build_head () {
var head = new StringBuilder ();

head.append_printf ("Status: %u %s\r\n", status, global::Soup.Status.get_phrase (status));
head.append_printf ("Status: %u %s\r\n", status, Status.get_phrase (status));

this.headers.foreach ((k, v) => {
head.append_printf ("%s: %s\r\n", k, v);
Expand Down

0 comments on commit 0f5ad51

Please sign in to comment.