Index: README.md
===================================================================
--- a/README.md
+++ b/README.md
@@ -26,16 +26,20 @@
### Running Emscripten
After installing and configuring Emscripten you can setup the build
with the following commands:
meson build
+To build natively use:
+
+ meson -Dnative=true build
+
By default it will create a debug build. Pass `--buildtype release` to
create a release build.
Then to build just do:
ninja -C build
This will regenerate the build files as needed.
Index: compiled/Utils.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/Utils.cpp
@@ -0,0 +1,23 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see .
+ */
+
+#include "Utils.h"
+
+std::wstring StdWStringFromString(const String& str)
+{
+ return std::wstring(str.data(), str.data() + str.length());
+}
Index: compiled/Utils.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/Utils.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see .
+ */
+
+#pragma once
+
+#include
+
+#include "String.h"
+
+std::wstring StdWStringFromString(const String& str);
Index: compiled/library.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/library.cpp
@@ -0,0 +1,76 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see .
+ */
+
+#include
+#include
+#include
+
+#include "String.h"
+#include "Utils.h"
+#include "debug.h"
+#include "library.h"
+
+
+char16_t CharToLower(char16_t charCode)
+{
+ return std::towlower(charCode);
+}
+
+
+void JSNotifyFilterChange(FilterNotifier::Topic topic, Filter& filter,
+ Subscription* subscription, unsigned int position)
+{
+}
+
+void JSNotifySubscriptionChange(FilterNotifier::Topic topic,
+ Subscription& subscription)
+{
+}
+
+namespace {
+ std::vector> regexPool;
+ std::mutex regexPoolMutex;
+}
+
+int GenerateRegExp(const String& regexp, bool matchCase)
+{
+ std::lock_guard guard(regexPoolMutex);
+ auto index = regexPool.size();
+ auto flags = std::regex_constants::ECMAScript;
+ if (!matchCase)
+ flags |= std::regex_constants::icase;
+ regexPool.emplace_back(new std::wregex(StdWStringFromString(regexp), flags));
+ return index;
+}
+
+void DeleteRegExp(int id)
+{
+ std::lock_guard guard(regexPoolMutex);
+ if (id < regexPool.size())
+ regexPool[id].reset();
+}
+
+bool TestRegExp(int id, const String& str)
+{
+ std::lock_guard guard(regexPoolMutex);
+ if ((id < regexPool.size()) && regexPool[id])
+ return std::regex_match(StdWStringFromString(str), *regexPool[id]);
+
+ assert2(id < regexPool.size() && regexPool[id], "Invalid RegExp index.");
+ return false;
+}
+
Index: meson.build
===================================================================
--- a/meson.build
+++ b/meson.build
@@ -1,44 +1,59 @@
-project('adblockpluscore', license: ['GPL3'], meson_version: '>0.40.0')
+project('adblockpluscore', 'cpp', license: ['GPL3'], meson_version: '>0.40.0')
-# locate emscripten-config
-python = import('python3').find_python()
-emscripten_config = get_option('emscripten-config')
-command = run_command(python, '-c', 'import os.path, sys;print(os.path.expanduser(sys.argv[1]))', emscripten_config)
-if command.returncode() != 0
- error(command.stderr().strip())
+native = get_option('native')
+if native
+ target_type='native'
+else
+ target_type='js'
endif
-emscripten_config = command.stdout().strip()
-message('Emscripten config file: ' + emscripten_config)
-# locate emcc
-command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());print(EMSCRIPTEN_ROOT)', emscripten_config)
-if command.returncode() != 0
- error(command.stderr().strip())
+if target_type == 'js'
+ # locate emscripten-config
+ python = import('python3').find_python()
+ emscripten_config = get_option('emscripten-config')
+ command = run_command(python, '-c', 'import os.path, sys;print(os.path.expanduser(sys.argv[1]))', emscripten_config)
+ if command.returncode() != 0
+ error(command.stderr().strip())
+ endif
+ emscripten_config = command.stdout().strip()
+ message('Emscripten config file: ' + emscripten_config)
+
+ # locate emcc
+ command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());print(EMSCRIPTEN_ROOT)', emscripten_config)
+ if command.returncode() != 0
+ error(command.stderr().strip())
+ endif
+ emcc = join_paths(command.stdout().strip(), 'emcc')
+ emcc = find_program(emcc)
+
+ # locate node
+ command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());print(NODE_JS)', emscripten_config)
+ if command.returncode() != 0
+ error(command.stderr().strip())
+ endif
+ nodejs = find_program(command.stdout().strip(), 'node', 'nodejs')
endif
-emcc = join_paths(command.stdout().strip(), 'emcc')
-emcc = find_program(emcc)
-
-# locate node
-command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());print(NODE_JS)', emscripten_config)
-if command.returncode() != 0
- error(command.stderr().strip())
-endif
-nodejs = find_program(command.stdout().strip(), 'node', 'nodejs')
JS_LIBRARY = files(join_paths('compiled', 'library.js'))
BINDINGS_JS_LIBRARY = files(join_paths('compiled', 'bindings', 'library.js'))
BINDINGS_GENERATOR = 'bindings.cpp.js'
BINDINGS_OUTPUT = 'bindings.js'
COMPILER_OUTPUT = 'compiled.js'
# params for emcc compilation
-ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0',
- '--emit-symbol-map', '-Wall', '-Werror',
+ADDITIONAL_PARAMS = [ '-O3', '-std=c++1z', '-Wall', '-Werror',
'-fno-rtti' ]
+if target_type == 'js'
+# CXXFLAGS specific to emcc
+ ADDITIONAL_PARAMS += [ '-m32', '--memory-init-file', '0',
+ '--emit-symbol-map' ]
+else
+ ADDITIONAL_PARAMS += [ '-fsanitize=address' ]
+endif
# additional params just for core
CORE_PARAMS = [ '-fno-exceptions' ]
DEFINES = []
GENERATION_PARAMS = [
['SHELL_FILE', '"' +
join_paths(meson.source_root(), 'compiled', 'shell.js') +
'"'],
@@ -81,16 +96,21 @@
core_sources = [
'compiled/traceInit.cpp',
]
# sources for the bindings generator
bindings_sources = [
'compiled/bindings/generator.cpp',
'compiled/bindings/main.cpp',
]
+# native sources
+native_sources = [
+ 'compiled/library.cpp',
+ 'compiled/Utils.cpp',
+]
defines_args = []
foreach define : DEFINES
defines_args += '-D' + define
endforeach
generation_args = []
foreach param : GENERATION_PARAMS
@@ -98,74 +118,86 @@
generation_args += param[0] + '=' + '@0@'.format(param[1])
endforeach
optional_args = []
buildtype = get_option('buildtype')
if buildtype.startswith('debug')
optional_args += '-DDEBUG'
optional_args += '-g3'
+ if target_type == 'native'
+ ADDITIONAL_PARAMS += [ '-fsanitize=address' ]
+ LINK_PARAMS = [ '-fsanitize=address' ]
+ endif
endif
tracing = get_option('tracing')
if tracing
optional_args += '--tracing'
endif
compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS
-# build objects.
-core_objects = []
-bindings_objects = []
-shared_objects = []
-foreach group : ['core', 'bindings', 'shared']
- objects = []
- foreach source_file : get_variable(group + '_sources')
- output_file = source_file.underscorify() + '.o'
- command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@',
- '@INPUT@' ] + compiler_args
- if group != 'bindings'
- command += CORE_PARAMS + optional_args
- endif
- objects += custom_target(output_file,
- input: files(source_file),
- output: output_file,
- depfile: output_file + '.deps',
- command: command)
+if target_type == 'js'
+ # build objects.
+ core_objects = []
+ bindings_objects = []
+ shared_objects = []
+ foreach group : ['core', 'bindings', 'shared']
+ objects = []
+ foreach source_file : get_variable(group + '_sources')
+ output_file = source_file.underscorify() + '.o'
+ command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@',
+ '@INPUT@' ] + compiler_args
+ if group != 'bindings'
+ command += CORE_PARAMS + optional_args
+ endif
+ objects += custom_target(output_file,
+ input: files(source_file),
+ output: output_file,
+ depfile: output_file + '.deps',
+ command: command)
+ endforeach
+ # Ideally, we would call set_variable() here but that doesn't work
+ # with arrays (see
+ # https://github.com/mesonbuild/meson/issues/1481). So we have to
+ # do this shifting dance instead.
+ core_objects = bindings_objects
+ bindings_objects = shared_objects
+ shared_objects = objects
endforeach
- # Ideally, we would call set_variable() here but that doesn't work with arrays
- # (see https://github.com/mesonbuild/meson/issues/1481). So we have to do this
- # shifting dance instead.
- core_objects = bindings_objects
- bindings_objects = shared_objects
- shared_objects = objects
-endforeach
-# link the binding generator
-bindings_generator = custom_target(BINDINGS_GENERATOR,
- input: bindings_objects + shared_objects,
- output: BINDINGS_GENERATOR,
- depend_files: [ JS_LIBRARY, BINDINGS_JS_LIBRARY ],
- command: [
- emcc, '-o', '@OUTPUT@',
- '--js-library', JS_LIBRARY,
- '--js-library', BINDINGS_JS_LIBRARY,
- '@INPUT@'
- ])
-# run the binding generator
-bindings_output = custom_target(BINDINGS_OUTPUT,
- input: bindings_generator,
- output: BINDINGS_OUTPUT,
- capture: true,
- command: [nodejs, '@INPUT@'])
+ # link the binding generator
+ bindings_generator = custom_target(BINDINGS_GENERATOR,
+ input: bindings_objects + shared_objects,
+ output: BINDINGS_GENERATOR,
+ depend_files: [ JS_LIBRARY, BINDINGS_JS_LIBRARY ],
+ command: [
+ emcc, '-o', '@OUTPUT@',
+ '--js-library', JS_LIBRARY,
+ '--js-library', BINDINGS_JS_LIBRARY,
+ '@INPUT@'
+ ])
+ # run the binding generator
+ bindings_output = custom_target(BINDINGS_OUTPUT,
+ input: bindings_generator,
+ output: BINDINGS_OUTPUT,
+ capture: true,
+ command: [nodejs, '@INPUT@'])
+ # link the core
+ output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT)
+ compiler_output = custom_target(COMPILER_OUTPUT,
+ build_by_default: true,
+ input: core_objects + shared_objects,
+ output: COMPILER_OUTPUT,
+ depend_files: [ JS_LIBRARY ],
+ command: [
+ emcc, '-o', output_file,
+ '--post-js', bindings_output,
+ '--js-library', JS_LIBRARY,
+ '@INPUT@'
+ ] + compiler_args + optional_args)
+else
+ adblockpluscore = library('adblockpluscore', shared_sources,
+ native_sources,
+ cpp_args: ADDITIONAL_PARAMS + CORE_PARAMS,
+ link_args: LINK_PARAMS)
+endif
-# link the core
-output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT)
-compiler_output = custom_target(COMPILER_OUTPUT,
- build_by_default: true,
- input: core_objects + shared_objects,
- output: COMPILER_OUTPUT,
- depend_files: [ JS_LIBRARY ],
- command: [
- emcc, '-o', output_file,
- '--post-js', bindings_output,
- '--js-library', JS_LIBRARY,
- '@INPUT@'
- ] + compiler_args + optional_args)
Index: meson_options.txt
===================================================================
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,2 +1,3 @@
option('tracing', type: 'boolean', value: false)
+option('native', type: 'boolean', value: false)
option('emscripten-config', type: 'string', value: '~/.emscripten')