Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Setting the build directory for a module using Inline::C

by cavac (Parson)
on Apr 04, 2022 at 12:54 UTC ( [id://11142664]=perlquestion: print w/replies, xml ) Need Help??

cavac has asked for the wisdom of the Perl Monks concerning the following question:

This might be a stupid question, but i have a small issue with JavaScript::Duktape which uses Inline::C.

I want to set the build directory "_Inline" to some other path, so i don't have build directories littered all over the place on my development system. The docs for Inline.pm say to set the PERL_INLINE_DIRECTORY environment variable. I assumed i could just set it in a BEGIN block before use of the Duktape module. But i can't get it to work.

BEGIN { #mkdir '/tmp/pagecamel_helpers_javascript_inline'; $ENV{PERL_INLINE_DIRECTORY} = '/tmp/pagecamel_helpers_javascript_i +nline'; use JavaScript::Duktape; };

I thought this would just set the environment variable, load JavaScript::Duktape (with the variable still intact) which in turn does all the Inline::C magic. Am i doing something incredible stupid here?

Disclaimer: I know that using /tmp is insecure. This will get a proper logic where to place the directory securely. I'm just using /tmp because it simplifies the proof of concept.

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Replies are listed 'Best First'.
Re: Setting the build directory for a module using Inline::C
by Corion (Patriarch) on Apr 04, 2022 at 13:01 UTC

    You need to move your use JavaScript::Duktape line outside of the BEGIN block, then it should work:

    BEGIN { #mkdir '/tmp/pagecamel_helpers_javascript_inline'; $ENV{PERL_INLINE_DIRECTORY} = '/tmp/pagecamel_helpers_javascript_i +nline'; }; use JavaScript::Duktape;

    The BEGIN { ... } block is first parsed, and during parsing, all use statements are executed when encountering them. This still executes the loading of the module too early for your directory to work.

    Ideally, JavaScript::Duktape would move away from using Inline::C and instead distribute and use the XS file created by Inline::C, but that's something for a different time.

      Ah, yes. I thought i tried that. But that might have been after commenting out the mkdir statement. The solution seems to be:

      BEGIN { mkdir '/tmp/pagecamel_helpers_javascript_inline'; $ENV{PERL_INLINE_DIRECTORY} = '/tmp/pagecamel_helpers_javascript_i +nline'; }; use JavaScript::Duktape;

      Thanks Corion!

      As for JavaScript::DukTape: Yeah ideally this should compile at install-time. I'm currently trying out Inline::Module, to see it that would work with Duktape. If it does, i'll contact the original author and talk to them on how to proceed (send patches, take over module maintenance, whatever).

      perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
        I want to set the build directory "_Inline" to some other path

        I usually do this by setting the Inline config option "DIRECTORY" to the desired location.
        This requires that the specified directory already exists.
        It would also involve amending the code inside JavaScript:::DukTape ... I'm not sure if that's what you want.
        use warnings; use Inline C => Config => # C:/inline_build must already exist DIRECTORY => 'C:/inline_build', ; use Inline C =><<'EOC'; void foo() { printf("Hello World\n"); } EOC foo();
        Cheers,
        Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found