Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 project('adblockpluscore', license: ['GPL3']) | 1 project('adblockpluscore', license: ['GPL3'], meson_version: '>0.40.0') |
Wladimir Palant
2017/10/11 10:00:47
Meson 0.39.1 (what you currently get on Ubuntu) co
hub
2017/10/11 18:23:16
Done.
| |
2 | 2 |
3 emcc = find_program('emcc') | 3 # locate emscripten-config |
4 nodejs = find_program('node') | 4 python = import('python3').find_python() |
Wladimir Palant
2017/10/11 10:00:47
I tried reading Emscripten configuration and the f
hub
2017/10/11 18:23:17
Done.
| |
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) | |
5 | 12 |
6 JS_LIBRARY = files('compiled/library.js') | 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')) | |
7 BINDINGS_GENERATOR = 'bindings.cpp.js' | 30 BINDINGS_GENERATOR = 'bindings.cpp.js' |
8 BINDINGS_OUTPUT = 'bindings.js' | 31 BINDINGS_OUTPUT = 'bindings.js' |
9 COMPILER_OUTPUT = 'compiled.js' | 32 COMPILER_OUTPUT = 'compiled.js' |
10 # params for emcc compilation | 33 # params for emcc compilation |
11 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', | 34 ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', |
12 '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions', | 35 '--emit-symbol-map', '-Wall', '-Werror', |
13 '-fno-rtti', '--js-library', JS_LIBRARY] | 36 '-fno-rtti' ] |
37 # additional params just for core | |
38 CORE_PARAMS = [ '-fno-exceptions' ] | |
39 | |
14 DEFINES = [] | 40 DEFINES = [] |
15 GENERATION_PARAMS = [ | 41 GENERATION_PARAMS = [ |
16 ['SHELL_FILE', '"' + meson.source_root() + '/compiled/shell.js"'], | 42 ['SHELL_FILE', '"' + |
17 ['ASM_JS', '2'], # "almost asm" | 43 join_paths(meson.source_root(), 'compiled', 'shell.js') + |
18 ['TOTAL_MEMORY', 16*1024*1024], | 44 '"'], |
19 ['TOTAL_STACK', 1*1024*1024], | 45 ['ASM_JS', '2'], # "almost asm" |
20 ['ALLOW_MEMORY_GROWTH', 1], | 46 ['TOTAL_MEMORY', 16*1024*1024], |
21 ['NO_EXIT_RUNTIME', 1], | 47 ['TOTAL_STACK', 1*1024*1024], |
22 ['NO_DYNAMIC_EXECUTION', 1], | 48 ['ALLOW_MEMORY_GROWTH', 1], |
23 ['NO_FILESYSTEM', 1], | 49 ['NO_EXIT_RUNTIME', 1], |
24 ['INVOKE_RUN', 0], | 50 ['NO_DYNAMIC_EXECUTION', 1], |
25 ['TEXTDECODER', 0], | 51 ['NO_FILESYSTEM', 1], |
26 ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] | 52 ['INVOKE_RUN', 0], |
53 ['TEXTDECODER', 0], | |
54 ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] | |
27 ] | 55 ] |
28 | 56 |
29 bindings_sources = files( | |
30 'compiled/bindings/generator.cpp', | |
31 'compiled/bindings/main.cpp', | |
32 ) | |
33 sources = files( | |
34 'compiled/bindings/runtime_utils.cpp', | |
35 'compiled/filter/ActiveFilter.cpp', | |
36 'compiled/filter/BlockingFilter.cpp', | |
37 'compiled/filter/CommentFilter.cpp', | |
38 'compiled/filter/ElemHideBase.cpp', | |
39 'compiled/filter/ElemHideEmulationFilter.cpp', | |
40 'compiled/filter/ElemHideException.cpp', | |
41 'compiled/filter/ElemHideFilter.cpp', | |
42 'compiled/filter/Filter.cpp', | |
43 'compiled/filter/InvalidFilter.cpp', | |
44 'compiled/filter/RegExpFilter.cpp', | |
45 'compiled/filter/WhitelistFilter.cpp', | |
46 'compiled/storage/FilterStorage.cpp', | |
47 'compiled/subscription/DownloadableSubscription.cpp', | |
48 'compiled/subscription/Subscription.cpp', | |
49 'compiled/subscription/UserDefinedSubscription.cpp', | |
50 'compiled/traceInit.cpp' | |
51 ) | |
52 | 57 |
53 bindings_generator = custom_target('bindings-generator', | 58 shared_sources = [ |
54 input: bindings_sources + sources, | 59 'compiled/bindings/runtime_utils.cpp', |
55 output: BINDINGS_GENERATOR, | 60 'compiled/filter/ActiveFilter.cpp', |
56 command: [emcc, '-o', '@OUTPUT@', | 61 'compiled/filter/BlockingFilter.cpp', |
57 '-std=c++1z', '--js-library', JS_LIBRARY, | 62 'compiled/filter/CommentFilter.cpp', |
58 '--js-library', | 63 'compiled/filter/ElemHideBase.cpp', |
59 files('compiled/bindings/library.js'), | 64 'compiled/filter/ElemHideEmulationFilter.cpp', |
60 '@INPUT@']) | 65 'compiled/filter/ElemHideException.cpp', |
61 bindings_output = custom_target('bindings-output', | 66 'compiled/filter/ElemHideFilter.cpp', |
62 input: bindings_generator, | 67 'compiled/filter/Filter.cpp', |
63 output: BINDINGS_OUTPUT, | 68 'compiled/filter/InvalidFilter.cpp', |
64 capture: true, | 69 'compiled/filter/RegExpFilter.cpp', |
65 command: [nodejs, '@INPUT@']) | 70 'compiled/filter/WhitelistFilter.cpp', |
66 | 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 ] | |
67 | 85 |
68 defines_args = [] | 86 defines_args = [] |
69 foreach define : DEFINES | 87 foreach define : DEFINES |
70 defines_args += '-D' + define | 88 defines_args += '-D' + define |
71 endforeach | 89 endforeach |
72 | 90 |
73 generation_args = [] | 91 generation_args = [] |
74 foreach param : GENERATION_PARAMS | 92 foreach param : GENERATION_PARAMS |
75 generation_args += '-s' | 93 generation_args += '-s' |
76 generation_args += param[0] + '=' + '@0@'.format(param[1]) | 94 generation_args += param[0] + '=' + '@0@'.format(param[1]) |
Wladimir Palant
2017/10/11 10:00:47
Nit: You should really unify leading whitespace in
hub
2017/10/11 18:23:16
Done.
| |
77 endforeach | 95 endforeach |
78 | 96 |
79 optional_args = [] | 97 optional_args = [] |
80 debug = get_option('buildtype') | 98 buildtype = get_option('buildtype') |
81 if debug.startswith('debug') | 99 if buildtype.startswith('debug') |
100 optional_args += '-DDEBUG' | |
82 optional_args += '-g3' | 101 optional_args += '-g3' |
83 endif | 102 endif |
84 tracing = get_option('tracing') | 103 tracing = get_option('tracing') |
85 if tracing | 104 if tracing |
86 optional_args += '--tracing' | 105 optional_args += '--tracing' |
87 endif | 106 endif |
88 | 107 |
89 output_file = meson.source_root() + '/lib/' + COMPILER_OUTPUT | 108 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS |
90 compiler_output = custom_target('compiled.js', | 109 |
91 build_by_default: true, | 110 # build objects. |
92 input: sources, | 111 core_objects = [] |
93 output: COMPILER_OUTPUT, | 112 bindings_objects = [] |
Wladimir Palant
2017/10/11 10:00:47
I'd consider that a temporary hack. It's probably
hub
2017/10/11 18:23:17
Acknowledged.
| |
94 command: [emcc, '-o', output_file, '-std=c++1z', | 113 shared_objects = [] |
Wladimir Palant
2017/10/11 10:00:47
-std=c++1z parameter is unnecessary here, it is al
hub
2017/10/11 18:23:16
Done.
| |
95 '--post-js', bindings_output, '@INPUT@'] + | 114 foreach group : ['core', 'bindings', 'shared'] |
96 defines_args + generation_args + optional_args + | 115 objects = [] |
97 ADDITIONAL_PARAMS) | 116 foreach source_file : get_variable(group + '_sources') |
Wladimir Palant
2017/10/11 10:00:47
Object files should really be generated as separat
hub
2017/10/11 18:23:16
I wanted to use the c++ targets, but meson doesn't
Wladimir Palant
2017/10/11 21:01:23
That's too bad. It would have been much nicer if w
| |
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) | |
LEFT | RIGHT |