Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 project('adblockpluscore', 'cpp', license: ['GPL3']) | 1 project('adblockpluscore', license: ['GPL3'], meson_version: '>0.40.0') |
Wladimir Palant
2017/10/11 21:01:23
I suspect that the build will now fail if no C++ c
sergei
2017/10/16 15:27:11
Yes, it fails if it cannot find any C++ compiler,
| |
2 | 2 |
3 # locate emscripten-config | 3 # locate emscripten-config |
4 python = import('python3').find_python() | 4 python = import('python3').find_python() |
5 emscripten_config = get_option('emscripten-config') | 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) | 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 | 7 if command.returncode() != 0 |
8 error(command.stderr().strip()) | 8 error(command.stderr().strip()) |
9 endif | 9 endif |
10 emscripten_config = command.stdout().strip() | 10 emscripten_config = command.stdout().strip() |
11 message('Emscripten config file: ' + emscripten_config) | 11 message('Emscripten config file: ' + emscripten_config) |
12 | 12 |
13 # locate emcc | 13 # locate emcc |
14 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p rint(EMSCRIPTEN_ROOT)', emscripten_config) | 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 | 15 if command.returncode() != 0 |
16 error(command.stderr().strip()) | 16 error(command.stderr().strip()) |
17 endif | 17 endif |
18 emcc = join_paths(command.stdout().strip(), 'emcc') | 18 emcc = join_paths(command.stdout().strip(), 'emcc') |
19 emcc = find_program(emcc) | 19 emcc = find_program(emcc) |
20 | 20 |
21 # locate node | 21 # locate node |
22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p rint(NODE_JS)', emscripten_config) | 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 | 23 if command.returncode() != 0 |
24 error(command.stderr().strip()) | 24 error(command.stderr().strip()) |
25 endif | 25 endif |
26 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') | 26 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') |
27 | 27 |
28 JS_LIBRARY = files(join_paths('compiled', 'library.js')) | 28 JS_LIBRARY = files(join_paths('compiled', 'library.js')) |
29 BINDINGS_JS_LIBRARY = files(join_paths('compiled', 'bindings', 'library.js')) | |
29 BINDINGS_GENERATOR = 'bindings.cpp.js' | 30 BINDINGS_GENERATOR = 'bindings.cpp.js' |
30 BINDINGS_OUTPUT = 'bindings.js' | 31 BINDINGS_OUTPUT = 'bindings.js' |
31 COMPILER_OUTPUT = 'compiled.js' | 32 COMPILER_OUTPUT = 'compiled.js' |
32 # params for emcc compilation | 33 # params for emcc compilation |
33 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', | 34 ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', |
34 '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions', | 35 '--emit-symbol-map', '-Wall', '-Werror', |
35 '-fno-rtti', '--js-library', JS_LIBRARY] | 36 '-fno-rtti' ] |
37 # additional params just for core | |
38 CORE_PARAMS = [ '-fno-exceptions' ] | |
39 | |
36 DEFINES = [] | 40 DEFINES = [] |
37 GENERATION_PARAMS = [ | 41 GENERATION_PARAMS = [ |
38 ['SHELL_FILE', '"' + | 42 ['SHELL_FILE', '"' + |
39 join_paths(meson.source_root(), 'compiled', 'shell.js') + | 43 join_paths(meson.source_root(), 'compiled', 'shell.js') + |
40 '"'], | 44 '"'], |
41 ['ASM_JS', '2'], # "almost asm" | 45 ['ASM_JS', '2'], # "almost asm" |
42 ['TOTAL_MEMORY', 16*1024*1024], | 46 ['TOTAL_MEMORY', 16*1024*1024], |
43 ['TOTAL_STACK', 1*1024*1024], | 47 ['TOTAL_STACK', 1*1024*1024], |
44 ['ALLOW_MEMORY_GROWTH', 1], | 48 ['ALLOW_MEMORY_GROWTH', 1], |
45 ['NO_EXIT_RUNTIME', 1], | 49 ['NO_EXIT_RUNTIME', 1], |
46 ['NO_DYNAMIC_EXECUTION', 1], | 50 ['NO_DYNAMIC_EXECUTION', 1], |
47 ['NO_FILESYSTEM', 1], | 51 ['NO_FILESYSTEM', 1], |
48 ['INVOKE_RUN', 0], | 52 ['INVOKE_RUN', 0], |
49 ['TEXTDECODER', 0], | 53 ['TEXTDECODER', 0], |
50 ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] | 54 ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] |
51 ] | 55 ] |
52 | 56 |
53 # We want these to be strings. | 57 |
54 core_sources = [ 'compiled/traceInit.cpp' ] | 58 shared_sources = [ |
55 sources = [ | |
56 'compiled/bindings/runtime_utils.cpp', | 59 'compiled/bindings/runtime_utils.cpp', |
57 'compiled/filter/ActiveFilter.cpp', | 60 'compiled/filter/ActiveFilter.cpp', |
58 'compiled/filter/BlockingFilter.cpp', | 61 'compiled/filter/BlockingFilter.cpp', |
59 'compiled/filter/CommentFilter.cpp', | 62 'compiled/filter/CommentFilter.cpp', |
60 'compiled/filter/ElemHideBase.cpp', | 63 'compiled/filter/ElemHideBase.cpp', |
61 'compiled/filter/ElemHideEmulationFilter.cpp', | 64 'compiled/filter/ElemHideEmulationFilter.cpp', |
62 'compiled/filter/ElemHideException.cpp', | 65 'compiled/filter/ElemHideException.cpp', |
63 'compiled/filter/ElemHideFilter.cpp', | 66 'compiled/filter/ElemHideFilter.cpp', |
64 'compiled/filter/Filter.cpp', | 67 'compiled/filter/Filter.cpp', |
65 'compiled/filter/InvalidFilter.cpp', | 68 'compiled/filter/InvalidFilter.cpp', |
66 'compiled/filter/RegExpFilter.cpp', | 69 'compiled/filter/RegExpFilter.cpp', |
67 'compiled/filter/WhitelistFilter.cpp', | 70 'compiled/filter/WhitelistFilter.cpp', |
68 'compiled/storage/FilterStorage.cpp', | 71 'compiled/storage/FilterStorage.cpp', |
69 'compiled/subscription/DownloadableSubscription.cpp', | 72 'compiled/subscription/DownloadableSubscription.cpp', |
70 'compiled/subscription/Subscription.cpp', | 73 'compiled/subscription/Subscription.cpp', |
71 'compiled/subscription/UserDefinedSubscription.cpp', | 74 'compiled/subscription/UserDefinedSubscription.cpp', |
72 ] | 75 ] |
73 | 76 # sources specific to core |
74 | 77 core_sources = [ |
75 # bindings | 78 'compiled/traceInit.cpp', |
76 bindings_sources = files( | 79 ] |
80 # sources for the bindings generator | |
81 bindings_sources = [ | |
77 'compiled/bindings/generator.cpp', | 82 'compiled/bindings/generator.cpp', |
78 'compiled/bindings/main.cpp', | 83 'compiled/bindings/main.cpp', |
79 ) | 84 ] |
80 | |
81 # convert the string list to a filesarray. | |
82 foreach source : sources | |
83 bindings_sources += files(source) | |
84 endforeach | |
85 | |
86 bindings_generator = custom_target('bindings-generator', | |
87 input: bindings_sources, | |
88 output: BINDINGS_GENERATOR, | |
89 command: [ | |
90 emcc, '-o', '@OUTPUT@', | |
91 '-std=c++1z', '--js-library', | |
92 JS_LIBRARY, | |
93 '--js-library', | |
94 files('compiled/bindings/library.js'), | |
95 '@INPUT@' | |
96 ]) | |
97 bindings_output = custom_target('bindings-output', | |
98 input: bindings_generator, | |
99 output: BINDINGS_OUTPUT, | |
100 capture: true, | |
101 command: [nodejs, '@INPUT@']) | |
102 | |
103 | 85 |
104 defines_args = [] | 86 defines_args = [] |
105 foreach define : DEFINES | 87 foreach define : DEFINES |
106 defines_args += '-D' + define | 88 defines_args += '-D' + define |
107 endforeach | 89 endforeach |
108 | 90 |
109 generation_args = [] | 91 generation_args = [] |
110 foreach param : GENERATION_PARAMS | 92 foreach param : GENERATION_PARAMS |
111 generation_args += '-s' | 93 generation_args += '-s' |
112 generation_args += param[0] + '=' + '@0@'.format(param[1]) | 94 generation_args += param[0] + '=' + '@0@'.format(param[1]) |
113 endforeach | 95 endforeach |
114 | 96 |
115 optional_args = [] | 97 optional_args = [] |
116 debug = get_option('buildtype') | 98 buildtype = get_option('buildtype') |
117 if debug.startswith('debug') | 99 if buildtype.startswith('debug') |
100 optional_args += '-DDEBUG' | |
118 optional_args += '-g3' | 101 optional_args += '-g3' |
119 endif | 102 endif |
120 tracing = get_option('tracing') | 103 tracing = get_option('tracing') |
121 if tracing | 104 if tracing |
122 optional_args += '--tracing' | 105 optional_args += '--tracing' |
123 endif | 106 endif |
124 | 107 |
125 compiler_args = defines_args + generation_args + optional_args + ADDITIONAL_PARA MS | 108 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS |
126 | 109 |
127 # build objects. | 110 # build objects. |
128 objects = [] | 111 core_objects = [] |
129 all_sources = sources + core_sources | 112 bindings_objects = [] |
130 foreach source_file : all_sources | 113 shared_objects = [] |
131 output_file = source_file.underscorify() + '.o' | 114 foreach group : ['core', 'bindings', 'shared'] |
Wladimir Palant
2017/10/12 08:46:09
Nit: You have three spaces indentation here.
hub
2017/10/12 18:12:11
Done.
| |
132 objects += custom_target(output_file, | 115 objects = [] |
133 input: files(source_file), | 116 foreach source_file : get_variable(group + '_sources') |
134 output: output_file, | 117 output_file = source_file.underscorify() + '.o' |
135 command: [ | 118 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', |
136 emcc, '-c', '-o', '@OUTPUT@', '@INPUT@' | 119 '@INPUT@' ] + compiler_args |
137 ] + compiler_args) | 120 if group != 'bindings' |
Wladimir Palant
2017/10/11 21:01:23
I looked into dependencies generation and we need
Wladimir Palant
2017/10/12 08:46:09
Actually, I succeeded reusing objects between bind
hub
2017/10/12 18:12:11
Done.
hub
2017/10/12 18:12:11
Done.
| |
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 | |
138 endforeach | 135 endforeach |
139 | 136 |
140 # link it all. | 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 | |
141 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) | 156 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) |
142 compiler_output = custom_target('compiled.js', | 157 compiler_output = custom_target(COMPILER_OUTPUT, |
143 build_by_default: true, | 158 build_by_default: true, |
144 input: objects, | 159 input: core_objects + shared_objects, |
145 output: COMPILER_OUTPUT, | 160 output: COMPILER_OUTPUT, |
161 depend_files: [ JS_LIBRARY ], | |
146 command: [ | 162 command: [ |
147 emcc, '-o', output_file, | 163 emcc, '-o', output_file, |
148 '--post-js', bindings_output, | 164 '--post-js', bindings_output, |
165 '--js-library', JS_LIBRARY, | |
149 '@INPUT@' | 166 '@INPUT@' |
150 ] + compiler_args) | 167 ] + compiler_args + optional_args) |
LEFT | RIGHT |