I want to compile the C library in JavaScript::Embedded at install time, not every time it is used.

Ok ... apply this patch (or make the specified changes by hand) to Embedded.pm.
Update: Patch corrected to remove errant whitespace. (Thanks LanX.)
--- Embedded.pm_orig 2022-07-14 21:12:05 +1000 +++ Embedded.pm 2022-07-14 12:01:26 +1000 @@ -4,6 +4,14 @@ use Carp; use Data::Dumper; use Scalar::Util qw( weaken ); + +use Config; +BEGIN { + # Create Inline's build directory: + mkdir "$Config{installsitelib}/_Inline" + unless -d "$Config{installsitelib}/_Inline"; +}; + our $VERSION = '2.7.1'; my $GlobalRef = {}; @@ -315,6 +323,9 @@ } use Inline C => config => + build_noisy => 1, + clean_after_build => 0, + directory => "$Config{installsitelib}/_Inline", typemaps => _get_path('typemap'), INC => '-I' . _get_path('../C') . ' -I' . _get_path('../C/l +ib'); # myextlib => $Duklib,
I've assumed that $Config{installsitelib} always exists, and is writable.
I think those are fairly safe assumptions.
The thing is that, in order to avoid the re-compilation issue, you need to assign a specific directory as Inline's build directory.

Setting of the "build_noisy" and unsetting of the "clean_after_build" config options is not really needed - they just make things a little clearer. (IMO, "build_noisy" should be set by default.)
Unsetting the "clean_after_build" option allows us to go into the build directory and view the XS and C files that Inline::C generated. Otherwise, those files are deleted when the build has been completed.

If, having built the module, you go into the $Config{installsitelib}/_Inline/build/JavaScript/Embedded directory and locate the XS file (in the "Vm_a662" subdirectory on my build) generated from duk_perl.c you'll see that the standard perl headers (EXTERN.h, perl.h and XSUB.h) have been included twice.
Also, Inline::C does not handle PERL_NO_GET_CONTEXT and might also not handle NO_XSLOCKS (I don't know).
Both PERL_NO_GET_CONTEXT and NO_XSLOCKS need to be declared before the standard perl headers - and that clearly is not happening.
None of this is causing any breakage, but I recommend that you apply the following changes to duk_perl.c for clarity:
--- duk_perl.c_orig 2022-07-14 12:38:44 +1000 +++ duk_perl.c 2022-07-14 12:40:08 +1000 @@ -1,9 +1,4 @@ -#define NO_XSLOCKS -#define PERL_NO_GET_CONTEXT -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" #include "ppport.h" #include <time.h> #include <stdlib.h>
If you really want to effectively define PERL_NO_GET_CONTEXT, then we'll need to say goodbye to Inline::C and switch to XS.
For that, I would be using my own InlineX::C2XS (which uses Inline::C) to generate the XS file(s).

Are you happy enough with just those changes to Embedded.pm and duk_perl.c ? ... or do we need to go further ?

Cheers,
Rob

In reply to Re: Need help using Inline::Module with JavaScript::Embedded by syphilis
in thread Need help using Inline::Module with JavaScript::Embedded by cavac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.