Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to use Inline::C for production code

by sfink (Deacon)
on Mar 30, 2004 at 07:41 UTC ( [id://340881]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: In praise of h2xs: A tool you gotta have
in thread In praise of h2xs: A tool you gotta have

I use Inline::C for some production code, and had to work around the issues you described. My solution was to create some infrastructure for precompiling the XS generated by Inline::C when requested. So when developing, I run using Inline::C, and get automatic recompiles when I change the C code. To release, I run make precompiled, which is a target I defined to force compilation of all of the Inline::C code and copy it over to the installation location. At runtime, the module chooses based on an environment variable whether to use Inline::C or the prebuilt stuff (on a production machine, you don't need to install the Inline module at all.)

In more detail:

Each of my Inline-using scripts looks like:

package Whatever; BEGIN { do ($ENV{DEVEL_MODE} ? 'MyMagicInline' : 'MyMagicDirect') or die $@ } ...perl code... __DATA__ __CPP__ ...C++ code... (ok I lied; I'm using Inline::CPP, not Inline::C)

$ENV{DEVEL_MODE} is set automagically by something else, but don't worry about that. Just always have it set while you're developing.

MyMagicInline contains something like:

use Inline with => 'MyScriptInline'; BEGIN { $inline_code_file = abs_path($INC{__PACKAGE__ . ".pm"}); } sub find_code { local $_ = shift; s/^.*?__CPP__\n//s; return $_; } use Inline(CPP => $inline_code_file, FILTERS => \&find_code); Inline->init;
The MyScriptInline file contains a single subroutine named Inline that returns a hash ref of Inline settings (eg { INC => '-I/my/path' }). (This is how Inline implements its with magic.)

RxMagicDirect contains only

require DynaLoader; { my ($pkg) = caller(0); push @{$pkg . "::ISA"}, "DynaLoader"; bootstrap $pkg; }
Ok, so that's just a sketch of what's going on; there are details about where the files are found and the precompilation target that runs everything under Inline and then copies the generated *.so files to the appropriate lib/ directory, but the end result is that I can install onto a production machine and not have to install Inline there.

I'm sure this isn't the cleanest way to do this. I never really bothered to go back and clean it up after I got it to work, but it seems to work quite well for what I need.

Replies are listed 'Best First'.
Re: How to use Inline::C for production code
by rstarr (Initiate) on Aug 06, 2005 at 02:50 UTC
    I know this is an old thread, but I have exactly the same problem. In my case I am trying to use PAR/pp to package up my stuff and field it. I tried adding the _Inline directory hoping that this would make everyone happy, and keep the recompile from occurring, but it didn't work. The approach above sounds promising, but I cannot get it to work. Perhaps a working culled down example doing something simple like "hello world" in Inline::C? I wish work offered me the time to dig into the guts of Inline::C and figure this out myself, but it doesn't. Any help much appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://340881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found