Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(couchjs): add support for SpiderMonkey 91esr #3842

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Ubuntu build CI

on:
workflow_dispatch:

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: update
run: sudo apt-get update
- name: install
run: sudo apt-get --no-install-recommends -y install autoconf2.13 build-essential pkg-config libcurl4-openssl-dev erlang-dev rebar elixir

- name: couch checkout
uses: actions/checkout@v2
with:
path: couch

- name: ICU checkout
uses: actions/checkout@v2
with:
repository: unicode-org/icu
path: icubuild

- name: ICU4C with gcc
env:
PREFIX: /usr/local
run: |
cd icubuild
mkdir build;
cd build;
../icu4c/source/runConfigureICU --enable-debug --disable-release Linux/gcc --prefix=$PREFIX --enable-tracing;
make -j2;
make -j2 check;
( cd ../icu4c/source/test/depstest && ./depstest.py ../../../../build/ );
sudo make install;

- name: Cache packages
uses: actions/cache@v2
id: wgetcache
with:
key: wgetcache
path: |
firefox-91.3.0esr.source.tar.xz
foundationdb-clients_6.3.22-1_amd64.deb
foundationdb-server_6.3.22-1_amd64.deb

- name: wget moz
if: steps.wgetcache.outputs.cache-hit != 'true'
run: wget -q https://www.foundationdb.org/downloads/6.3.22/ubuntu/installers/foundationdb-server_6.3.22-1_amd64.deb https://www.foundationdb.org/downloads/6.3.22/ubuntu/installers/foundationdb-clients_6.3.22-1_amd64.deb https://download.cdn.mozilla.net/pub/firefox/releases/91.3.0esr/source/firefox-91.3.0esr.source.tar.xz

- name: build spidermonkeycheckout
run: |
tar xf firefox-91.3.0esr.source.tar.xz
export PKG_CONFIG_PATH=${{github.workspace}}/icu/lib/pkgconfig:$PKG_CONFIG_PATH
export AC_MACRODIR=${{github.workspace}}/firefox-91.3.0/build/autoconf/
cd firefox-91.3.0
export PYTHON=python3
export M4=m4
export AWK=awk
export CFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib"
cd js/src
sh ../../build/autoconf/autoconf.sh --localdir=$PWD configure.in > configure
chmod +x configure
mkdir ${{github.workspace}}/build_OPT.OBJ
cd ${{github.workspace}}/build_OPT.OBJ
${{github.workspace}}/firefox-91.3.0/js/src/configure --prefix=/usr/local --disable-ctypes --disable-jit --disable-jemalloc --enable-optimize --enable-hardening --with-intl-api --build-backends=RecursiveMake --with-system-icu --disable-debug --enable-gczeal
make
sudo make install

- name: install
run: sudo apt-get --no-install-recommends -y install ./foundationdb-clients_6.3.22-1_amd64.deb ./foundationdb-server_6.3.22-1_amd64.deb

- name: configure
run: |
cd couch
sed -i -e "s@DRV_CFLAGS -DPIC@DRV_CFLAGS -I/usr/local/include -DPIC@" src/couch/rebar.config.script
sed -i -e "s@DRV_LDFLAGS -lm@DRV_LDFLAGS -L/usr/local/lib -lm@" src/couch/rebar.config.script
sh ./configure --spidermonkey-version=91 --disable-docs
- name: Compile
run: |
cd couch
make release
- name: Run tests
run: |
cd couch
make check
41 changes: 25 additions & 16 deletions src/couch/priv/couch_js/86/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ quit(JSContext* cx, unsigned int argc, JS::Value* vp)
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

int exit_code = args[0].toInt32();;
JS_DestroyContext(cx);
JS_ShutDown();
exit(exit_code);
}

Expand Down Expand Up @@ -254,20 +256,7 @@ static JSSecurityCallbacks security_callbacks = {
nullptr
};


int
main(int argc, const char* argv[])
{
JSContext* cx = NULL;
int i;

couch_args* args = couch_parse_args(argc, argv);

JS_Init();
cx = JS_NewContext(args->stack_size);
if(cx == NULL)
return 1;

int runWithContext(JSContext* cx, couch_args* args) {
JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_BASELINE_ENABLE, 0);
JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_ION_ENABLE, 0);

Expand All @@ -293,7 +282,7 @@ main(int argc, const char* argv[])
if(couch_load_funcs(cx, global, global_functions) != true)
return 1;

for(i = 0 ; args->scripts[i] ; i++) {
for(int i = 0 ; args->scripts[i] ; i++) {
const char* filename = args->scripts[i];

// Compile and run
Expand Down Expand Up @@ -336,6 +325,26 @@ main(int argc, const char* argv[])
// Give the GC a chance to run.
JS_MaybeGC(cx);
}

return 0;
}

int
main(int argc, const char* argv[])
{
JSContext* cx = NULL;
int ret;

couch_args* args = couch_parse_args(argc, argv);

JS_Init();
cx = JS_NewContext(args->stack_size);
if(cx == NULL) {
JS_ShutDown();
return 1;
}
ret = runWithContext(cx, args);
JS_DestroyContext(cx);
JS_ShutDown();

return ret;
}
2 changes: 1 addition & 1 deletion src/couch/priv/couch_js/86/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void
couch_oom(JSContext* cx, void* data)
{
fprintf(stderr, "out of memory\n");
exit(1);
_Exit(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change something that ought to be backported to our wrappers for older versions of SpiderMonkey, or is it motivated by something specific in ESR91?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a little of both something that changed and a bug that existed.. Technically it was never correct to do a proper exit() without cleaning up the js context which we can't do in the middle of being called from the js context (and having a shortage of memory its risky to assume we can get a chance to exit later), but it was only in recent versions that mozilla added destructors that notice they are being called with a still active context.

Since it was a bug I saw no problem with keeping it combined and fixing 86 and 78 in the process, but none of the earlier versions should ever get patches again so it probably doesn't need to be backported to the earlier wrappers.

}


Expand Down
12 changes: 11 additions & 1 deletion src/couch/rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ SMVsn = case lists:keyfind(spidermonkey_version, 1, CouchConfig) of
"78";
{_, "86"} ->
"86";
{_, "91"} ->
"91";
undefined ->
"1.8.5";
{_, Unsupported} ->
Expand All @@ -89,6 +91,8 @@ ConfigH = [
CouchJSConfig = case SMVsn of
"78" ->
"priv/couch_js/86/config.h";
"91" ->
"priv/couch_js/86/config.h";
_ ->
"priv/couch_js/" ++ SMVsn ++ "/config.h"
end.
Expand Down Expand Up @@ -148,6 +152,11 @@ end.
{
"-DXP_UNIX -I/usr/include/mozjs-86 -I/usr/local/include/mozjs-86 -I/opt/homebrew/include/mozjs-86/ -std=c++17 -Wno-invalid-offsetof",
"-L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-86 -lm"
};
{unix, _} when SMVsn == "91" ->
{
"-DXP_UNIX -I/usr/include/mozjs-91 -I/usr/local/include/mozjs-91 -I/opt/homebrew/include/mozjs-91/ -std=c++17 -Wno-invalid-offsetof",
"-L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-91 -lm"
}
end.

Expand All @@ -156,7 +165,8 @@ CouchJSSrc = case SMVsn of
"60" -> ["priv/couch_js/60/*.cpp"];
"68" -> ["priv/couch_js/68/*.cpp"];
"78" -> ["priv/couch_js/86/*.cpp"];
"86" -> ["priv/couch_js/86/*.cpp"]
"86" -> ["priv/couch_js/86/*.cpp"];
"91" -> ["priv/couch_js/86/*.cpp"]
end.

CouchJSEnv = case SMVsn of
Expand Down