ibc / em-udns

An async DNS resolver for EventMachine based on the udns C library
http://ibc.github.com/em-udns/
GNU Lesser General Public License v2.1
37 stars 12 forks source link

Integrate udns sources into em-udns #1

Closed ibc closed 13 years ago

ibc commented 13 years ago

For now em-udns relies on udns C library installed in the system (see have_library("udns") in ext/extconf.rb and #include <udns.h> in ext/em-udns.c).

However udns is not mantained in Linux distributions. Last version in Debian/Ubuntu is 0.0.9 while current udns version is 0.1.0 (fixing some bugs).

Also, udns tarball doesn't include "make install", but just "make", and it generates a static linudns.a and not a dynamic libdudsn.so.

The author of udns said me this in udns maillist:

You can try running `make sharedlib' in the udns source directory --this will produce a series of .lo files, just like it produces a bunch of .o files for static library. You grab these .lo files and produce a static library from them -- libudns.a, like this:

rm -f libudns.a
ar r libudns.a *.lo
This is not perfect, but will work for your case. Regular static library will not - because you're producing shared object from it, and regular static library is meant to be used to produce a simple executable. Another alternative is to re-implement the makefile using the same build system as uses - this is trivial, you just need to take a list of files from udns Makefile.

So we need udns sources to be included within the em-udns gem, so gem install em-udns would compile udns, and em-udns would compiled against it. The first solution given above (using make sharedlib and ar r libudns.a *.lo) does work, but I don't know how to integrate it within a gem. Or maybe it's better just to modify the Makefile of udns and integrate it in some way.

mperham commented 13 years ago

I hacked together a tarball compile of phash for my phashion gem. See the ext directory here:

http://github.com/mperham/phashion

ibc commented 13 years ago

Thanks a lot mperham, I've implemented more or less the same as you in extconf.rb and it works very well (the gem is already published).

Thanks a lot :)

tmm1 commented 13 years ago

I was having issues building on OSX. Fixed at tmm1/em-udns@c0c1967f63bd7fb02e93301903b743d987cd2af5

ibc commented 13 years ago

Hi Aman, the problem in your extconf.rb is that it fails under Linux 64 bits:

Building native extensions.  This could take a while...
ERROR:  Error installing em-udns-0.1.2.gem:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
  -- tar zxvf /usr/lib/ruby/gems/1.9.1/gems/em-udns-0.1.2/ext/udns-0.1.tar.gz
  -- ./configure
  -- make libudns.a
checking for main() in -ludns... yes
creating Makefile

make
gcc -I. -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I.   -fPIC -fno-strict-aliasing -g -g -O2 -fPIC  -o em-udns.o -c em-udns.c
gcc -shared -o em_udns_ext.so em-udns.o -L. -L/usr/lib -L.  -rdynamic -Wl,-export-dynamic   -lruby-1.9.1 -ludns  -lpthread -lrt -ldl -lcrypt -lm   -lc
/usr/bin/ld: ./libudns.a(udns_resolver.o): relocation R_X86_64_32 against `dns_defctx' can not be used when making a shared object; recompile with -fPIC
./libudns.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [em_udns_ext.so] Error 1

This is the reason the author of udns suggests doing this (what I've implemented in my extconf.rb):

make sharedlib
ar r libudns.a *.lo

So, any suggestion to make it work in both worlds? :)

ibc commented 13 years ago

A friend of mine has tryed to install em-udns on OSX and it gets this error when extconf.rb runs "make sharedlib":

gcc -shared -Wl,--soname,libudns.so.0 -o libudns.so.0 udns_dn.lo udns_dntosp.lo udns_parse.lo udns_resolver.lo udns_init.lo udns_misc.lo udns_XtoX.lo udns_rr_a.lo udns_rr_ptr.lo udns_rr_mx.lo udns_rr_txt.lo udns_bl.lo udns_rr_srv.lo udns_rr_naptr.lo udns_codes.lo udns_jran.lo
ld: unknown option: --soname
collect2: ld returned 1 exit status
make: *** [libudns.so.0] Error 1

It seems a problem of ld in OSX (related to --soname option). Found this.

ibc commented 13 years ago

Ok, Makefile.in in udns-0.1 contains this:

sharedlib: $(SOLIBV)

$(SOLIBV): $(SOBJS)
        $(CC) -shared -Wl,--soname,$(SOLIBV) -o $@ $(SOBJS)

So make sharedlib fails under some versions of OSX. I've reported it in udns maillist: http://www.corpit.ru/pipermail/udns/2011q1/000120.html

stuffmc commented 13 years ago

Anything new on this make sharedlib problem under OSX?

ibc commented 13 years ago

Hi, unfortunately I don't use OSX, neither I know anybody (OSX user) interested in fixing this issue. Please check this reply from udns author: http://www.corpit.ru/pipermail/udns/2011q1/000123.html

The best solution here would be udns to be available for different architectures (a deb package for Debian, RMP for RedHat/Centos, something for OSX and so on), so it would provide libudns and libudns-dev packages. In this way, including the full udns sources in em-udns Gem would not be required, neither the current hack in extconf.rb.

Are you able to modify udns Makefile so it correctly compiles "make sharedlib" under OSX? any suggestion? Indeed I would like to improve it, but IMHO it entirely depends on udns library.

ibc commented 13 years ago

Hi stuffmc, commit in https://github.com/ibc/em-udns/commit/16d4c126931413601bfcbe02a9827d1e08c5c2cb should fix compilation under MacOSX 32 and 64 bits. It now creates a dynamic lib.

Could you please install the new em-udns Gem version 0.2.5 in which the commit is included?

ibc commented 13 years ago

Tested under Mac OSX 64 bits, so it works.

lantins commented 13 years ago

Confirmed working here!

lantins@macpro:~/devel/oss/em-udns ruby-1.9.2-p290$ uname -a Darwin macpro.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386

ibc commented 13 years ago

Thanks for confirming it.