Skip to content

Commit ad53548

Browse files
committed
Updated for build with Emscripten 1.38.28
Unfortunately, this for now also includes building without "-s ASSERTIONS=2".
1 parent 6be9365 commit ad53548

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

build/build.pl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,16 @@ =head1 Author, Copyright, and License
9292
# Emscripten's fork() (and system()) stubs return EAGAIN, meaning "Resource temporarily unavailable".
9393
# So perl will wait 5 seconds and try again, which is not helpful to us, since Emscripten doesn't support those functions at all.
9494
# This patch fixes that on the Emscripten side, so the stubs return ENOTSUP.
95+
# first, we need to take a guess which version of the patch to apply.
96+
my $libraryjs = file($ENV{EMSCRIPTEN}, 'src', 'library.js')->slurp;
97+
my $patchf;
98+
if ( $libraryjs=~/\b\QERRNO_CODES.EAGAIN\E\b/ )
99+
{ $patchf = 'emscripten_1.38.10_eagain.patch' }
100+
elsif ( $libraryjs=~/\b\QcDefine('EAGAIN')\E/ )
101+
{ $patchf = 'emscripten_1.38.28_eagain.patch' }
102+
else { die "Could not figure out which library.js patch to use" }
95103
#TODO Later: we should probably verify the Emscripten version too, and in the future we may need different patches for different versions
96-
if ( try_patch_file( file($FindBin::Bin,'emscripten_1.38.10_eagain.patch') ) ) {
104+
if ( try_patch_file( file($FindBin::Bin,$patchf) ) ) {
97105
say STDERR "# Emscripten was newly patched, forcing a rebuild";
98106
# not sure if the following is needed, but playing it safe:
99107
run 'emcc', '--clear-cache'; # force Emscripten to rebuild libs (takes a bit of time)

build/emperl_config.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ export EMPERL_OUTPUTDIR="$BASEDIR/work/outputperl"
2929
# Note to self: In build.pl, we take advantage of the fact that on Perls >=v5.10.0, "$^V" is the same as the tag name.
3030
export EMPERL_PERLVER="v5.28.0"
3131
export EMPERL_PREFIX="/opt/perl"
32+
# Note: strace shows this is how file_packager.py is called: ["/usr/bin/python", "/home/haukex/emsdk/emscripten/1.38.28/tools/file_packager.py", "emperl.data", "--from-emcc", "--export-name=Module", "--preload", "/home/haukex/code/webperl/work/outputperl/opt/perl@/opt/perl", "--no-heap-copy"]
3233
export EMPERL_PRELOAD_FILE="$EMPERL_OUTPUTDIR$EMPERL_PREFIX@$EMPERL_PREFIX"
3334
export EMPERL_OPTIMIZ="-O2"
34-
export EMPERL_LINK_FLAGS="--pre-js common_preamble.js -s EXPORTED_FUNCTIONS=['_main','_emperl_end_perl','_Perl_call_sv','_Perl_call_pv','_Perl_call_method','_Perl_call_argv','_Perl_eval_pv','_Perl_eval_sv','_webperl_eval_perl'] -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap']"
35+
# Note: We explicitly disable ERROR_ON_UNDEFINED_SYMBOLS because it was enabled by default in Emscripten 1.38.13.
36+
#TODO Later: Why does --no-heap-copy not get rid of the "in memory growth we are forced to copy it again" assertion warning? (https://github.com/emscripten-core/emscripten/commit/ec764ace634f13bab5ae932912da53fe93ee1b69)
37+
export EMPERL_LINK_FLAGS="--pre-js common_preamble.js --no-heap-copy -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s EXPORTED_FUNCTIONS=['_main','_emperl_end_perl','_Perl_call_sv','_Perl_call_pv','_Perl_call_method','_Perl_call_argv','_Perl_eval_pv','_Perl_eval_sv','_webperl_eval_perl'] -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap']"
38+
39+
export EMPERL_DEBUG_FLAGS=""
40+
#export EMPERL_DEBUG_FLAGS="-s ASSERTIONS=2 -s STACK_OVERFLOW_CHECK=2"
3541
# Note: not including "-s SAFE_HEAP=1" in the debug flags because we're building to WebAssembly, which doesn't require alignment
3642
#TODO Later: Can some of the SAFE_HEAP functionality (null pointer access I think?) be replaced by the WASM error traps?
3743
# http://kripken.github.io/emscripten-site/docs/compiling/WebAssembly.html#binaryen-codegen-options
38-
export EMPERL_DEBUG_FLAGS="-s ASSERTIONS=2 -s STACK_OVERFLOW_CHECK=2"
3944

4045
# Location and branch of the perl git repository that contains the emperl branch
4146
export EMPERL_PERL_REPO="https://github.com/haukex/emperl5.git"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- library.js.orig 2019-03-02 16:08:24.404047130 +0100
2+
+++ library.js 2019-03-02 16:19:30.588047130 +0100
3+
@@ -291,7 +291,7 @@
4+
// pid_t fork(void);
5+
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fork.html
6+
// We don't support multiple processes.
7+
- ___setErrNo({{{ cDefine('EAGAIN') }}});
8+
+ ___setErrNo({{{ cDefine('ENOTSUP') }}});
9+
return -1;
10+
},
11+
vfork: 'fork',
12+
@@ -817,7 +817,7 @@
13+
// int system(const char *command);
14+
// http://pubs.opengroup.org/onlinepubs/000095399/functions/system.html
15+
// Can't call external programs.
16+
- ___setErrNo({{{ cDefine('EAGAIN') }}});
17+
+ ___setErrNo({{{ cDefine('ENOTSUP') }}});
18+
return -1;
19+
},
20+

0 commit comments

Comments
 (0)