OLD | NEW |
(Empty) | |
| 1 project('adblockpluscore', license: ['GPL3'], meson_version: '0.43.0') |
| 2 |
| 3 # locate emscripten-config |
| 4 python = import('python3').find_python() |
| 5 emscripten_config = get_option('emscripten-config') |
| 6 command = run_command(python, '-c', 'import os.path, sys;print(os.path.expanduse
r(sys.argv[1]))', emscripten_config) |
| 7 if command.returncode() != 0 |
| 8 error(command.stderr().strip()) |
| 9 endif |
| 10 emscripten_config = command.stdout().strip() |
| 11 message('Emscripten config file: ' + emscripten_config) |
| 12 |
| 13 # locate emcc |
| 14 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
rint(EMSCRIPTEN_ROOT)', emscripten_config) |
| 15 if command.returncode() != 0 |
| 16 error(command.stderr().strip()) |
| 17 endif |
| 18 emcc = join_paths(command.stdout().strip(), 'emcc') |
| 19 emcc = find_program(emcc) |
| 20 |
| 21 # locate node |
| 22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
rint(NODE_JS)', emscripten_config) |
| 23 if command.returncode() != 0 |
| 24 error(command.stderr().strip()) |
| 25 endif |
| 26 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') |
| 27 |
| 28 JS_LIBRARY = files(join_paths('compiled', 'library.js')) |
| 29 BINDINGS_JS_LIBRARY = files(join_paths('compiled', 'bindings', 'library.js')) |
| 30 BINDINGS_GENERATOR = 'bindings.cpp.js' |
| 31 BINDINGS_OUTPUT = 'bindings.js' |
| 32 COMPILER_OUTPUT = 'compiled.js' |
| 33 # params for emcc compilation |
| 34 ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', |
| 35 '--emit-symbol-map', '-Wall', '-Werror', |
| 36 '-fno-rtti' ] |
| 37 # additional params just for core |
| 38 CORE_PARAMS = [ '-fno-exceptions' ] |
| 39 |
| 40 DEFINES = [] |
| 41 GENERATION_PARAMS = [ |
| 42 ['SHELL_FILE', '"' + |
| 43 join_paths(meson.source_root(), 'compiled', 'shell.js') + |
| 44 '"'], |
| 45 ['ASM_JS', '2'], # "almost asm" |
| 46 ['TOTAL_MEMORY', 16*1024*1024], |
| 47 ['TOTAL_STACK', 1*1024*1024], |
| 48 ['ALLOW_MEMORY_GROWTH', 1], |
| 49 ['NO_EXIT_RUNTIME', 1], |
| 50 ['NO_DYNAMIC_EXECUTION', 1], |
| 51 ['NO_FILESYSTEM', 1], |
| 52 ['INVOKE_RUN', 0], |
| 53 ['TEXTDECODER', 0], |
| 54 ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] |
| 55 ] |
| 56 |
| 57 |
| 58 shared_sources = [ |
| 59 'compiled/bindings/runtime_utils.cpp', |
| 60 'compiled/filter/ActiveFilter.cpp', |
| 61 'compiled/filter/BlockingFilter.cpp', |
| 62 'compiled/filter/CommentFilter.cpp', |
| 63 'compiled/filter/ElemHideBase.cpp', |
| 64 'compiled/filter/ElemHideEmulationFilter.cpp', |
| 65 'compiled/filter/ElemHideException.cpp', |
| 66 'compiled/filter/ElemHideFilter.cpp', |
| 67 'compiled/filter/Filter.cpp', |
| 68 'compiled/filter/InvalidFilter.cpp', |
| 69 'compiled/filter/RegExpFilter.cpp', |
| 70 'compiled/filter/WhitelistFilter.cpp', |
| 71 'compiled/storage/FilterStorage.cpp', |
| 72 'compiled/subscription/DownloadableSubscription.cpp', |
| 73 'compiled/subscription/Subscription.cpp', |
| 74 'compiled/subscription/UserDefinedSubscription.cpp', |
| 75 ] |
| 76 # sources specific to core |
| 77 core_sources = [ |
| 78 'compiled/traceInit.cpp', |
| 79 ] |
| 80 # sources for the bindings generator |
| 81 bindings_sources = [ |
| 82 'compiled/bindings/generator.cpp', |
| 83 'compiled/bindings/main.cpp', |
| 84 ] |
| 85 |
| 86 defines_args = [] |
| 87 foreach define : DEFINES |
| 88 defines_args += '-D' + define |
| 89 endforeach |
| 90 |
| 91 generation_args = [] |
| 92 foreach param : GENERATION_PARAMS |
| 93 generation_args += '-s' |
| 94 generation_args += param[0] + '=' + '@0@'.format(param[1]) |
| 95 endforeach |
| 96 |
| 97 optional_args = [] |
| 98 buildtype = get_option('buildtype') |
| 99 if buildtype.startswith('debug') |
| 100 optional_args += '-DDEBUG' |
| 101 optional_args += '-g3' |
| 102 endif |
| 103 tracing = get_option('tracing') |
| 104 if tracing |
| 105 optional_args += '--tracing' |
| 106 endif |
| 107 |
| 108 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS |
| 109 |
| 110 # build objects. |
| 111 core_objects = [] |
| 112 bindings_objects = [] |
| 113 shared_objects = [] |
| 114 foreach group : ['core', 'bindings', 'shared'] |
| 115 objects = [] |
| 116 foreach source_file : get_variable(group + '_sources') |
| 117 output_file = source_file.underscorify() + '.o' |
| 118 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', |
| 119 '@INPUT@' ] + compiler_args |
| 120 if group != 'bindings' |
| 121 command += CORE_PARAMS + optional_args |
| 122 endif |
| 123 objects += custom_target(output_file, |
| 124 input: files(source_file), |
| 125 output: output_file, |
| 126 depfile: output_file + '.deps', |
| 127 command: command) |
| 128 endforeach |
| 129 # Ideally, we would call set_variable() here but that doesn't work with arrays |
| 130 # (see https://github.com/mesonbuild/meson/issues/1481). So we have to do this |
| 131 # shifting dance instead. |
| 132 core_objects = bindings_objects |
| 133 bindings_objects = shared_objects |
| 134 shared_objects = objects |
| 135 endforeach |
| 136 |
| 137 # link the binding generator |
| 138 bindings_generator = custom_target(BINDINGS_GENERATOR, |
| 139 input: bindings_objects + shared_objects, |
| 140 output: BINDINGS_GENERATOR, |
| 141 depend_files: [ JS_LIBRARY, BINDINGS_JS_LIBRA
RY ], |
| 142 command: [ |
| 143 emcc, '-o', '@OUTPUT@', |
| 144 '--js-library', JS_LIBRARY, |
| 145 '--js-library', BINDINGS_JS_LIBRARY, |
| 146 '@INPUT@' |
| 147 ]) |
| 148 # run the binding generator |
| 149 bindings_output = custom_target(BINDINGS_OUTPUT, |
| 150 input: bindings_generator, |
| 151 output: BINDINGS_OUTPUT, |
| 152 capture: true, |
| 153 command: [nodejs, '@INPUT@']) |
| 154 |
| 155 # link the core |
| 156 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) |
| 157 compiler_output = custom_target(COMPILER_OUTPUT, |
| 158 build_by_default: true, |
| 159 input: core_objects + shared_objects, |
| 160 output: COMPILER_OUTPUT, |
| 161 depend_files: [ JS_LIBRARY ], |
| 162 command: [ |
| 163 emcc, '-o', output_file, |
| 164 '--post-js', bindings_output, |
| 165 '--js-library', JS_LIBRARY, |
| 166 '@INPUT@' |
| 167 ] + compiler_args + optional_args) |
OLD | NEW |