arcapos / luapgsql

Lua binding for PostgreSQL
112 stars 24 forks source link

Fine tuning rockspec #7

Closed daurnimator closed 8 years ago

daurnimator commented 9 years ago

Hi Marc,

The current rockspec available up on luarocks doesn't work for me. I spent some time trying to get it down to the minimum required:

package = "luapgsql"
version = "scm-3"
source = {
   url = "git://github.com/mbalmer/luapgsql";
}
description = {
   summary = "A Lua Binding for PostgreSQL";
   homepage = "http://github.com/mbalmer/luapgsql";
   license = "3-clause BSD";
}
dependencies = {
   "lua >= 5.1, < 5.3";
}
external_dependencies = {
   POSTGRESQL = {
      header = "postgres_fe.h";
   };
   PQ = {
      header = "libpq-fe.h";
      library = "pq";
   };
   platforms = {
      linux = {
         -- for strlcpy
         LIBBSD = {
            header = "bsd/bsd.h";
            library = "bsd";
         };
      };
   };
}
build = {
   type = "builtin";
   modules = {
      pgsql = {
         sources = "luapgsql.c";
         incdirs = { "$(POSTGRESQL_INCDIR)" };
         libdirs = { "$(POSTGRESQL_LIBDIR)" };
         libraries = { "pq" };
      };
   };
   platforms = {
      linux = {
         modules = {
            pgsql = {
               incdirs = { [2] = "$(LIBBSD_INCDIR)"; };
               libdirs = { [2] = "$(LIBBSD_LIBDIR)"; };
               libraries = { [2] = "bsd"; };
               defines = { "_GNU_SOURCE" }; -- for asprintf
            };
         };
      };
   };
}

The header = "postgres_fe.h"; should be correct, as that is the actual #include in the code: https://github.com/mbalmer/luapgsql/blob/master/luapgsql.c#L36

This works on my arch linux system, with the postgres server installed. You can see an example invocation here:

$ sudo luarocks install luapgsql-scm-3.rockspec POSTGRESQL_INCDIR=/usr/include/postgresql/server
Using luapgsql-scm-3.rockspec... switching to 'build' mode
Cloning into 'luapgsql'...
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 13 (delta 0), reused 7 (delta 0)
Receiving objects: 100% (13/13), 99.58 KiB | 0 bytes/s, done.
Checking connectivity... done.
gcc -O2 -fPIC -I/usr/include -c luapgsql.c -o luapgsql.o -D_GNU_SOURCE -I/usr/include/postgresql/server -I/usr/include
gcc -shared -o pgsql.so -L/usr/lib luapgsql.o -L/usr/local/lib -L/usr/lib -Wl,-rpath,/usr/local/lib: -Wl,-rpath,/usr/lib: -lpq -lbsd
Updating manifest for /usr/lib/luarocks/rocks-5.2
luapgsql scm-3 is now built and installed in /usr (license: 3-clause BSD)

I was wondering which of the bsd bits need to remain:

libbsd still needs to be included because of strlcpy.

mbalmer commented 9 years ago

Am 02.01.2015 um 21:48 schrieb daurnimator notifications@github.com:

Hi Marc,

The current rockspec available up on luarocks doesn't work for me. I spent some time trying to get it down to the minimum required:

Sweet. Should I add it to the repo on github?

package = "luapgsql"

version = "scm-3"

source

{ url = "git://github.com/mbalmer/luapgsql"

}

description

{ summary = "A Lua Binding for PostgreSQL" , homepage = "http://github.com/mbalmer/luapgsql" , license = "3-clause BSD"

}

dependencies

{

"lua >= 5.1, < 5.3"

}

external_dependencies

{

POSTGRESQL

{ header = "postgres_fe.h" ; library = "pq" ; }; }

build

{ type = "builtin" ,

modules

{

pgsql

{ incdirs = { "$(POSTGRESQL_INCDIR)" }, libdirs = { "$(POSTGRESQL_LIBDIR)" }, sources = "luapgsql.c"

  }

} }

The header = "postgres_fe.h"; should be correct, as that is the actual #include in the code: https://github.com/mbalmer/luapgsql/blob/master/luapgsql.c#L36

This works on my arch linux system, with the postgres server installed. You can see an example invocation here:

$ sudo luarocks install luapgsql-scm-3.rockspec POSTGRESQL_INCDIR=/usr/include/postgresql/server Using luapgsql-scm-3.rockspec... switching to 'build' mode Cloning into 'luapgsql'... remote: Counting objects: 13, done. remote: Compressing objects: 100% (11/11), done. remote: Total 13 (delta 0), reused 7 (delta 0) Receiving objects: 100% (13/13), 99.58 KiB | 0 bytes/s, done. Checking connectivity... done. gcc -O2 -fPIC -I/usr/include -c luapgsql.c -o luapgsql.o -I/usr/include/postgresql/server gcc -shared -o pgsql.so -L/usr/lib luapgsql.o -L/usr/lib -Wl,-rpath,/usr/lib: Updating manifest for /usr/lib/luarocks/rocks-5.2 luapgsql scm-3 is now built and installed in /usr (license: 3-clause BSD)

I was wondering which of the bsd bits need to remain:

• does libpq need to be linked as -lpostgres?

No.

• why was postgres.h required?

postgres.h is not included, I am not sure it was in previous versions.

— Reply to this email directly or view it on GitHub.

daurnimator commented 9 years ago

Sweet. Should I add it to the repo on github?

If it works for you, yes! I have a sample space of one so far. In addition to commiting the rockspec to the repository, you should sign up at https://rocks.moonscript.org and upload it.

• does libpq need to be linked as -lpostgres?

No.

Great.

• why was postgres.h required?

postgres.h is not included, I am not sure it was in previous versions.

It was marked as a required header in the previous rockspec. I removed it in my version above.

mbalmer commented 9 years ago

Thanks, added it.

daurnimator commented 9 years ago

thanks for commiting it :) please remember to upload at https://rocks.moonscript.org/upload

daurnimator commented 9 years ago

With 92893375c629f0bf583510f6f5ff98a5193a97ed libbsd bits can now be removed.

I also realised we can add a documentation section.

daurnimator commented 9 years ago

Thanks for removing the libbsd lines :)

Now that 1.4.0 is tagged you can create a non-scm rockspec.

{
    url = "http://github.com/mbalmer/luapgsql/archive/1.4.0.zip";
    md5 = "0531ad9bbb36f577f42a506aae7ae71b";
    dir = "luapgsql-1.4.0";
}

Once this is done it'd be nice if you could pack a source rock and even upload some binary rocks (so users won't need to compile). Let me know if you need help with these.

kiug commented 9 years ago

Can I build this library under Windows?

2015-01-21 21:22 GMT+01:00 daurnimator notifications@github.com:

Thanks for removing the libbsd lines :)

Now that 1.4.0 is tagged you can create a non-scm rockspec.

  • copy the file to "luapgsql-1.4.0-0.rockspec"
  • change the version field to "1.4.0-0"
  • change the "source" table to something like:

{ url = "https://github.com/mbalmer/luapgsql/archive/1.4.0.zip"; md5 = "0531ad9bbb36f577f42a506aae7ae71b"; dir = "luapgsql-1.4.0"; }

Once this is done it'd be nice if you could pack a source rock and even upload some binary rocks (so users won't need to compile). Let me know if you need help with these.

— Reply to this email directly or view it on GitHub https://github.com/mbalmer/luapgsql/issues/7#issuecomment-70914143.

Karol Drożak

mbalmer commented 9 years ago

Am 22.01.15 um 13:22 schrieb Karol Drozak:

Can I build this library under Windows?

I have no idea.

Have you tried it?

kiug commented 9 years ago

Yes, but it fail.

2015-01-22 22:16 GMT+01:00 Marc Balmer notifications@github.com:

Am 22.01.15 um 13:22 schrieb Karol Drozak:

Can I build this library under Windows?

I have no idea.

Have you tried it?

— Reply to this email directly or view it on GitHub https://github.com/mbalmer/luapgsql/issues/7#issuecomment-71100431.

Karol Drożak

mbalmer commented 9 years ago

Am 23.01.15 um 09:40 schrieb Karol Drozak:

Yes, but it fail.

Ok, I see.

kiug commented 9 years ago

2015-01-23 9:42 GMT+01:00 Marc Balmer notifications@github.com:

Am 23.01.15 um 09:40 schrieb Karol Drozak:

Yes, but it fail.

Ok, I see.

I have tried one more time and it work. But i have no idea how to automate build process. I have used bash from the Git and MinGW. If You want, look at fork repository https://github.com/kiug/luapgsql

Build process:

wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.bz2 tar xjvf postgresql-9.4.1.tar.bz2 cd postgresql-9.4.1 ./configure --without-zlib make cd .. wget http://www.lua.org/ftp/lua-5.1.5.tar.gz cd lua-5.1.5 make cd ..

git clone https://github.com/mbalmer/luapgsql.git cd luapgsql

asprintf downloaded from: http://asprintf.insanecoding.org/asprintf-1.0.zip

gcc -O2 -c -o vasprintf-c99.o vasprintf-c99.c gcc -O2 -c -o asprintf.o asprintf.c gcc -O2 -I../postgresql-9.4.1/src/interfaces/libpq -I../lua-5.1.5/src -I../postgresql-9.4.1/src/include -DEXEC_BACKEND -I../postgresql-9.4.1/src/include/port/win32 -c -o luapgsql.o luapgsql.c gcc -shared luapgsql.o asprintf.o vasprintf-c99.o ../lua-5.1.5/lua51.dll

../postgresql-9.4.1/src/interfaces/libpq/libpq.dll -o pgsql.dll

— Reply to this email directly or view it on GitHub https://github.com/mbalmer/luapgsql/issues/7#issuecomment-71163132.

Karol Drożak

daurnimator commented 9 years ago

@kiug I managed to compile luapgsql on windows using luarocks; the asprintf dependency was the only tricky thing... hopefully it can be removed when #9 is addressed. I uploaded the binary rock over at http://rocks.moonscript.org/manifests/daurnimator/luapgsql-1.4.1-0.win32-x86.rock , but it seems to not be valid :disappointed: https://github.com/keplerproject/luarocks/issues/308

For the record, I:

markuman commented 9 years ago

why < 5.3 ? It seems to work without any problems with lua 5.3 and postgres 9.4

    $ lua
    Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
    > pgsql = require 'pgsql'
    > conn = pgsql.connectdb('dbname=markus user=markus')
    > res = conn:exec('select * from test01')
    > res:getvalue(1,1)
    1
    > res:getvalue(1,2)
    bla
    > 
daurnimator commented 9 years ago

The current HEAD works with 5.3, but the latest release (1.4.2) does not.

mbalmer commented 8 years ago

I will make a new release as soon as we fixed the current issues (potential memory leaks and such).