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 #3852

Merged
merged 6 commits into from
Mar 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
include version.mk

SHELL=cmd.exe
REBAR=bin\rebar.cmd
ERLFMT=bin\erlfmt
REBAR?=$(CURDIR)\bin\rebar.cmd
PYTHON=python.exe
ERLFMT?=$(CURDIR)\bin\erlfmt.cmd
MAKE=make -f Makefile.win
# REBAR?=$(shell where rebar.cmd)

Expand Down Expand Up @@ -77,7 +78,7 @@ DESTDIR=

# Rebar options
apps=
skip_deps=folsom,meck,mochiweb,triq,proper,snappy,bcrypt,hyper
skip_deps=folsom,meck,mochiweb,triq,proper,snappy,bcrypt,hyper,ibrowse,local
suites=
tests=

Expand Down Expand Up @@ -157,44 +158,46 @@ eunit: couch
exunit: export BUILDDIR = $(shell echo %cd%)
exunit: export MIX_ENV=test
exunit: export ERL_LIBS = $(shell echo %cd%)\src
exunit: export ERL_AFLAGS = -config $(shell echo %cd%)/rel/files/eunit.config
exunit: export ERL_AFLAGS = $(shell echo "-config rel/files/eunit.config")
exunit: export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(shell echo %cd%)/bin/couchjs $(shell echo %cd%)/share/server/main.js
exunit: couch elixir-init setup-eunit elixir-check-formatted elixir-credo
@mix test --cover --trace $(EXUNIT_OPTS)

setup-eunit: export BUILDDIR = $(shell pwd)
setup-eunit: export ERL_AFLAGS = "-config $(shell echo %cd%)/rel/files/eunit.config")
setup-eunit: export ERL_AFLAGS = $(shell echo "-config rel/files/eunit.config")
setup-eunit:
@$(REBAR) setup_eunit 2> nul

just-eunit: export BUILDDIR = $(shell pwd)
just-eunit: export ERL_AFLAGS = "-config $(shell echo %cd%)/rel/files/eunit.config")
just-eunit: export ERL_AFLAGS = $(shell echo "-config rel/files/eunit.config")
just-eunit:
@$(REBAR) -r eunit $(EUNIT_OPTS)

erlfmt-check: export ERLFMT_PATH := $(ERLFMT)
erlfmt-check:
ERLFMT_PATH=bin\erlfmt python3 dev\format_check.py
@$(PYTHON) dev\format_check.py

erlfmt-format: export ERLFMT_PATH := $(ERLFMT)
erlfmt-format:
ERLFMT_PATH=bin\erlfmt python3 dev\format_all.py
@$(PYTHON) dev\format_all.py

.venv/bin/black:
@python.exe -m venv .venv
@$(PYTHON) -m venv .venv
@.venv\Scripts\pip3.exe install black || copy /b .venv\Scripts\black.exe +,,

# Python code formatter - only runs if we're on Python 3.6 or greater
python-black: .venv/bin/black
@python.exe -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
echo 'Python formatter not supported on Python < 3.6; check results on a newer platform'
@python.exe -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
.venv\Scripts\black.exe --check \
--exclude="build/|buck-out/|dist/|_build/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|src/erlfmt|src/rebar/pr2relnotes.py|src/fauxton" \
build-aux dev\run dev\format_*.py src\mango\test src\docs\src\conf.py src\docs\ext .

python-black-update: .venv/bin/black
@python.exe -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
echo 'Python formatter not supported on Python < 3.6; check results on a newer platform'
@python.exe -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
.venv\Scripts\black.exe \
--exclude="build/|buck-out/|dist/|_build/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|src/erlfmt|src/rebar/pr2relnotes.py|src/fauxton" \
build-aux dev\run dev\format_*.py src\mango\test src\docs\src\conf.py src\docs\ext .
Expand Down
40 changes: 39 additions & 1 deletion configure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ $ConfigERL = @"
"@
$ConfigERL | Out-File "$rootdir\config.erl" -encoding ascii

if (((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null) -or
((Get-Command "rebar3.cmd" -ErrorAction SilentlyContinue) -eq $null) -or
((Get-Command "erlfmt.cmd" -ErrorAction SilentlyContinue) -eq $null)) {
$env:Path += ";$rootdir\bin"
}

# check for rebar; if not found, build it and add it to our path
if ((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null)
{
Expand All @@ -198,7 +204,39 @@ if ((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null)
cp $rootdir\src\rebar\rebar $rootdir\bin\rebar
cp $rootdir\src\rebar\rebar.cmd $rootdir\bin\rebar.cmd
make -C $rootdir\src\rebar clean
$env:Path += ";$rootdir\bin"
}

# check for rebar3; if not found, build it and add it to our path
if ((Get-Command "rebar3.cmd" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Verbose "==> rebar3.cmd not found; bootstrapping..."
if (-Not (Test-Path "src\rebar3"))
{
git clone --depth 1 https://github.com/erlang/rebar3.git $rootdir\src\rebar3
}
cd src\rebar3
.\bootstrap.ps1
cp $rootdir\src\rebar3\rebar3 $rootdir\bin\rebar3
cp $rootdir\src\rebar3\rebar3.cmd $rootdir\bin\rebar3.cmd
cp $rootdir\src\rebar3\rebar3.ps1 $rootdir\bin\rebar3.ps1
make -C $rootdir\src\rebar3 clean
cd ..\..
}

# check for erlfmt; if not found, build it and add it to our path
if ((Get-Command "erlfmt.cmd" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Verbose "==> erlfmt.cmd not found; bootstrapping..."
if (-Not (Test-Path "src\erlfmt"))
{
git clone --depth 1 https://github.com/WhatsApp/erlfmt.git $rootdir\src\erlfmt
}
cd src\erlfmt
rebar3 as release escriptize
cp $rootdir\src\erlfmt\_build\release\bin\erlfmt $rootdir\bin\erlfmt
cp $rootdir\src\erlfmt\_build\release\bin\erlfmt.cmd $rootdir\bin\erlfmt.cmd
make -C $rootdir\src\erlfmt clean
cd ..\..
}

# only update dependencies, when we are not in a release tarball
Expand Down
51 changes: 26 additions & 25 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,22 +282,14 @@ 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
JS::CompileOptions options(cx);
options.setFileAndLine(filename, 1);
JS::RootedScript script(cx);
FILE* fp;

fp = fopen(args->scripts[i], "r");
if(fp == NULL) {
fprintf(stderr, "Failed to read file: %s\n", filename);
return 3;
}
script = JS::CompileUtf8File(cx, options, fp);
fclose(fp);
script = JS::CompileUtf8Path(cx, options, filename);
if (!script) {
JS::RootedValue exc(cx);
if(!JS_GetPendingException(cx, &exc)) {
Expand Down Expand Up @@ -336,6 +317,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);
}


Expand Down
19 changes: 17 additions & 2 deletions 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,16 @@ 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" ->
{
"$CFLAGS -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",
"$LDFLAGS -L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-91 -lm"
};
{win32, _} when SMVsn == "91" ->
{
"/std:c++17 /DXP_WIN",
"$LDFLAGS mozjs-91.lib"
}
end.

Expand All @@ -156,7 +170,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 All @@ -179,7 +194,7 @@ IcuDarwinEnv = [{"CFLAGS", "-DXP_UNIX -I/usr/local/opt/icu4c/include -I/opt/home
IcuBsdEnv = [{"CFLAGS", "-DXP_UNIX -I/usr/local/include"},
{"LDFLAGS", "-L/usr/local/lib"}].
IcuWinEnv = [{"CFLAGS", "$DRV_CFLAGS /DXP_WIN"},
{"LDFLAGS", "icuin.lib icudt.lib icuuc.lib"}].
{"LDFLAGS", "$LDFLAGS icuin.lib icudt.lib icuuc.lib"}].

ComparePath = "priv/couch_ejson_compare.so".
CompareSrc = ["priv/couch_ejson_compare/*.c"].
Expand Down