forked from gonzus/JavaScript-V8-XS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.PL
197 lines (163 loc) · 6.01 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
use strict;
use warnings;
use v5.28;
use ExtUtils::MakeMaker;
use File::Fetch;
use POSIX();
use Digest::SHA;
use Archive::Tar;
use File::Path qw(make_path);
use File::Basename qw(dirname basename);
use File::Copy::Recursive qw(rmove);
my ($sysname, $machine) = (POSIX::uname)[0, -1];
$sysname = lc($sysname);
my $NODEJS_VERSION = $ENV{NODEJS_VERSION} // '20.12.1.0';
my $RUBYGEMS = $ENV{RUBYGEMS} // "https://rubygems.org/downloads";
my $NODEJS_URL = "${RUBYGEMS}/libv8-node-${NODEJS_VERSION}-${machine}-${sysname}.gem";
my $NODEJS_INTEGRITIES = {
"20.12.1.0" => {
darwin => {
arm64 => "bae2867eff6c26245cd8e4c73122adba93391b2a14210e8719613afa83e437cd",
x86_64 => "3520d312c334f6bcd8051c8c5ff3432c3430c0fd857d5a547c68975be1c2f671",
},
linux => {
aarch64 => "6604cb511723d438150377ce77b957138157358fb618e713ec438fa8f3c013cf",
x86_64 => "8d58e74037a3cf45145579289cc099c2dbd6a02a77b5a899426a63cb2c8d64e7",
}
},
"16.20.0.0" => {
darwin => {
arm64 => "2f7cf8ef0647c4fa8f17d1197fa50ef55fae88c26a77ff721848dc02fd5f6b2e",
x86_64 => "68f02186c66e49f337f938e3819536404a571becf77234a758958f603fee014a",
},
linux => {
aarch64 => "c863521c1c84033db7b7377ad1810b902d228505e043f26aa3922ab4695b49a7",
x86_64 => "27c7cc9a733e727ad1a98aeadee4ebf4a240aa907d265200c485b1286edb71f3",
}
},
};
my $NODEJS_INTEGRITY = $ENV{NODEJS_INTEGRITY} // $NODEJS_INTEGRITIES->{$NODEJS_VERSION}->{$sysname}->{$machine};
my $V8_BASE_DIR = $ENV{V8_BASE_DIR} // "libv8/${NODEJS_VERSION}/${sysname}/${machine}";
my $V8_INCLUDE_DIR = $ENV{V8_INCLUDE_DIR} // join('/', $V8_BASE_DIR, 'vendor', 'v8', 'include');
my $V8_LIB_DIR = $ENV{V8_LIB_DIR} // join('/', $V8_BASE_DIR, 'vendor', 'v8', "${machine}-${sysname}", "libv8", "obj");
if ( ! -d $V8_BASE_DIR ) {
say STDERR "downloading: $NODEJS_URL";
use Data::Dumper;
my $fetcher = File::Fetch->new(uri => $NODEJS_URL);
my $file = $fetcher->fetch() or die $fetcher->error;
if ($NODEJS_INTEGRITY) {
my $sha = Digest::SHA->new(256);
$sha->addfile($file);
my $sha_hex = $sha->hexdigest;
die "Integrity check failed: expected $NODEJS_INTEGRITY, got $sha_hex" if $sha_hex ne $NODEJS_INTEGRITY;
}
my $tar = Archive::Tar->new;
$tar->read($file);
$tar->extract_file("data.tar.gz", "libv8-${NODEJS_VERSION}-${sysname}-${machine}.tar.gz") or die "Failed to extract data.tar.gz";
$tar = Archive::Tar->new;
$tar->read("libv8-${NODEJS_VERSION}-${sysname}-${machine}.tar.gz");
my @files = $tar->list_files();
@files = grep { m!^vendor/! } @files;
for my $file (@files) {
my $dirname = dirname($file);
make_path("${V8_BASE_DIR}.tmp/${dirname}");
my $basename = basename($file);
$tar->extract_file($file, "${V8_BASE_DIR}.tmp/${file}") or die "Failed to extract $file";
}
unlink("libv8-${NODEJS_VERSION}-${sysname}-${machine}.tar.gz");
unlink($file);
rmove("${V8_BASE_DIR}.tmp", $V8_BASE_DIR);
}
my @V8_CC_OPTS;
my @V8_CC_DEFS;
my @V8_CC_WRNS;
my @V8_CC_INCD;
my @V8_LD_LIBD;
push @V8_CC_INCD, $V8_INCLUDE_DIR;
push @V8_LD_LIBD, $V8_LIB_DIR;
push @V8_CC_OPTS, qw< -O2 -std=c++17 >;
push @V8_CC_WRNS, qw< all extra no-unused-parameter >;
# this is not provided any more by v8
my $V8_DATA_DIR = $ENV{V8_DATA_DIR} // join('/', $V8_BASE_DIR, 'data');
push @V8_CC_DEFS, "V8_DATA_DIR='${V8_DATA_DIR}'";
my $V8_LIB_FLAGS = "";
if ($^O eq 'linux') {
push @V8_CC_DEFS, qw< PERL_JAVASCRIPT_V8_XS_LINUX >;
$V8_LIB_FLAGS = "-lstdc++";
}
$V8_LIB_FLAGS=$ENV{V8_LIB_FLAGS} // $V8_LIB_FLAGS;
if ($^O eq 'darwin') {
push @V8_CC_DEFS, qw< PERL_JAVASCRIPT_V8_XS_DARWIN >;
}
my $CC = $ENV{CC} // 'c++';
my $LD = $ENV{LD} // 'c++';
my $CC_OPTS = join(' ',
(@V8_CC_OPTS),
(map { "-D$_" } @V8_CC_DEFS),
(map { "-W$_" } @V8_CC_WRNS),
(map { "-I$_" } @V8_CC_INCD),
);
my $NON_LAZY = $ENV{PERL_DL_NONLAZY} // 1;
{
package ExtUtils::MM_Unix; # so that "SUPER" works right
sub test_via_harness {
my($self, $perl, $tests) = @_;
return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=${NON_LAZY} $perl", $tests);
}
sub test_via_script {
my($self, $perl, $script) = @_;
return $self->SUPER::test_via_script("PERL_DL_NONLAZY=${NON_LAZY} $perl", $script);
}
}
WriteMakefile(
NAME => 'JavaScript::V8::XS',
VERSION_FROM => 'lib/JavaScript/V8/XS.pm',
ABSTRACT_FROM => 'lib/JavaScript/V8/XS.pm',
LICENSE => 'mit',
MIN_PERL_VERSION => 5.028000,
PREREQ_PM => {
'Text::Trim' => 0,
'XSLoader' => 0,
'ExtUtils::XSpp' => '0.11',
'File::Fetch' => 0,
'Digest::SHA' => 0,
'Archive::Tar' => 0,
'File::Path' => 0,
'File::Basename' => 0,
'File::Copy::Recursive' => 0,
},
TEST_REQUIRES => {
'Data::Dumper' => 0,
'JSON::PP' => 0,
'Path::Tiny' => 0,
'Scalar::Util' => 0,
'Test::More' => 0,
'Test::Output' => 0,
'Test::Exception' => 0,
'Text::Trim' => 0,
'Time::HiRes' => 0,
},
AUTHOR => [
'Gonzalo Diethelm ([email protected])',
],
# compiler settings
CC => "$CC $CC_OPTS",
DEFINE => '',
depend => { 'v8-perl.c' => 'JavaScript-V8-XS-Context.xsp' },
# linker settings
OBJECT => '$(O_FILES) ' . "${V8_LIB_DIR}/libv8_monolith.a $V8_LIB_FLAGS",
# precompiler settings
XSOPT => '-C++ -hiertype',
TYPEMAPS => ['perlobject.map'],
# repo settings
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => '[email protected]:gonzus/JavaScript-V8-XS',
web => 'https://github.com/gonzus/JavaScript-V8-XS',
},
},
},
);