| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 project('adblockpluscore', 'cpp', license: ['GPL3']) | |
| 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_GENERATOR = 'bindings.cpp.js' | |
| 30 BINDINGS_OUTPUT = 'bindings.js' | |
| 31 COMPILER_OUTPUT = 'compiled.js' | |
| 32 # params for emcc compilation | |
| 33 ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', | |
| 34 '--emit-symbol-map', '-Wall', '-Werror', | |
| 35 '-fno-rtti', '--js-library', JS_LIBRARY ] | |
| 36 # additional params just for core | |
| 37 CORE_PARAMS = [ '-fno-exceptions' ] | |
| 38 | |
| 39 DEFINES = [] | |
| 40 GENERATION_PARAMS = [ | |
| 41 ['SHELL_FILE', '"' + | |
| 42 join_paths(meson.source_root(), 'compiled', 'shell.js') + | |
| 43 '"'], | |
| 44 ['ASM_JS', '2'], # "almost asm" | |
| 45 ['TOTAL_MEMORY', 16*1024*1024], | |
| 46 ['TOTAL_STACK', 1*1024*1024], | |
| 47 ['ALLOW_MEMORY_GROWTH', 1], | |
| 48 ['NO_EXIT_RUNTIME', 1], | |
| 49 ['NO_DYNAMIC_EXECUTION', 1], | |
| 50 ['NO_FILESYSTEM', 1], | |
| 51 ['INVOKE_RUN', 0], | |
| 52 ['TEXTDECODER', 0], | |
| 53 ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] | |
| 54 ] | |
| 55 | |
| 56 | |
| 57 shared_sources = [ | |
| 58 'compiled/bindings/runtime_utils.cpp', | |
| 59 'compiled/filter/ActiveFilter.cpp', | |
| 60 'compiled/filter/BlockingFilter.cpp', | |
| 61 'compiled/filter/CommentFilter.cpp', | |
| 62 'compiled/filter/ElemHideBase.cpp', | |
| 63 'compiled/filter/ElemHideEmulationFilter.cpp', | |
| 64 'compiled/filter/ElemHideException.cpp', | |
| 65 'compiled/filter/ElemHideFilter.cpp', | |
| 66 'compiled/filter/Filter.cpp', | |
| 67 'compiled/filter/InvalidFilter.cpp', | |
| 68 'compiled/filter/RegExpFilter.cpp', | |
| 69 'compiled/filter/WhitelistFilter.cpp', | |
| 70 'compiled/storage/FilterStorage.cpp', | |
| 71 'compiled/subscription/DownloadableSubscription.cpp', | |
| 72 'compiled/subscription/Subscription.cpp', | |
| 73 'compiled/subscription/UserDefinedSubscription.cpp', | |
| 74 ] | |
| 75 # sources specific to core | |
| 76 core_sources = [ 'compiled/traceInit.cpp' ] | |
|
Wladimir Palant
2017/10/13 09:45:40
Nit: I'd list the file name here on a separate lin
hub
2017/10/13 18:16:52
Done.
| |
| 77 # sources for the bindings generator | |
| 78 bindings_sources = [ | |
| 79 'compiled/bindings/generator.cpp', | |
| 80 'compiled/bindings/main.cpp', | |
| 81 ] | |
| 82 | |
| 83 defines_args = [] | |
| 84 foreach define : DEFINES | |
| 85 defines_args += '-D' + define | |
| 86 endforeach | |
| 87 | |
| 88 generation_args = [] | |
| 89 foreach param : GENERATION_PARAMS | |
| 90 generation_args += '-s' | |
| 91 generation_args += param[0] + '=' + '@0@'.format(param[1]) | |
| 92 endforeach | |
| 93 | |
| 94 optional_args = [] | |
| 95 debug = get_option('buildtype') | |
|
Wladimir Palant
2017/10/13 09:45:39
Nit: This variable should be named buildtype or mo
hub
2017/10/13 18:16:52
Done.
| |
| 96 if debug.startswith('debug') | |
| 97 optional_args += '-g3' | |
| 98 endif | |
| 99 tracing = get_option('tracing') | |
| 100 if tracing | |
| 101 optional_args += '--tracing' | |
| 102 endif | |
| 103 | |
| 104 compiler_args = defines_args + generation_args + optional_args + ADDITIONAL_PARA MS | |
| 105 | |
| 106 # build objects. | |
| 107 core_objects = [] | |
| 108 bindings_objects = [] | |
| 109 shared_objects = [] | |
| 110 foreach group : ['core', 'bindings', 'shared'] | |
| 111 objects = [] | |
| 112 foreach source_file : get_variable(group + '_sources') | |
| 113 output_file = source_file.underscorify() + '.o' | |
| 114 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', | |
| 115 '@INPUT@' ] + compiler_args | |
| 116 if group != 'bindings' | |
| 117 command += CORE_PARAMS | |
|
Wladimir Palant
2017/10/13 09:45:39
I think we should add optional args only here and
| |
| 118 endif | |
| 119 objects += custom_target(output_file, | |
| 120 input: files(source_file), | |
| 121 output: output_file, | |
| 122 depfile: output_file + '.deps', | |
| 123 command: command) | |
| 124 endforeach | |
| 125 # Ideally, we would call set_variable() here but that doesn't work with arrays | |
| 126 # (see https://github.com/mesonbuild/meson/issues/1481). So we have to do this | |
| 127 # shifting dance instead. | |
| 128 core_objects = bindings_objects | |
| 129 bindings_objects = shared_objects | |
| 130 shared_objects = objects | |
| 131 endforeach | |
| 132 | |
| 133 # link the binding generator | |
| 134 bindings_generator = custom_target('bindings-generator', | |
| 135 input: bindings_objects + shared_objects, | |
| 136 output: BINDINGS_GENERATOR, | |
| 137 command: [ | |
| 138 emcc, '-o', '@OUTPUT@', | |
| 139 '--js-library', | |
| 140 JS_LIBRARY, | |
| 141 '--js-library', | |
| 142 files('compiled/bindings/library.js'), | |
|
Wladimir Palant
2017/10/13 09:45:39
Does this detect compiled/bindings/library.js as a
hub
2017/10/13 18:16:52
I wasn't sure, but it actually does. I checked.
| |
| 143 '@INPUT@' | |
| 144 ]) | |
| 145 # run the binding generator | |
| 146 bindings_output = custom_target('bindings-output', | |
|
Wladimir Palant
2017/10/13 09:45:39
Nit: Use BINDINGS_OUTPUT for target name?
hub
2017/10/13 18:16:52
Done.
| |
| 147 input: bindings_generator, | |
| 148 output: BINDINGS_OUTPUT, | |
| 149 capture: true, | |
| 150 command: [nodejs, '@INPUT@']) | |
| 151 | |
| 152 # link the core | |
| 153 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) | |
| 154 compiler_output = custom_target('compiled.js', | |
|
Wladimir Palant
2017/10/13 09:45:40
Nit: Use COMPILER_OUTPUT for target name?
hub
2017/10/13 18:16:52
Done.
| |
| 155 build_by_default: true, | |
| 156 input: core_objects + shared_objects, | |
| 157 output: COMPILER_OUTPUT, | |
| 158 command: [ | |
| 159 emcc, '-o', output_file, | |
| 160 '--post-js', bindings_output, | |
| 161 '@INPUT@' | |
| 162 ] + compiler_args) | |
| OLD | NEW |