Skip to content

Commit 7e5ab40

Browse files
authored
Store generated struct info rather than auto-generating it in the sysroot. NFC (#19013)
I noticed while working `gen_sig_info.py` in #18985 that is was simpler to just keep a copy of the generated file checked into source control. We can use a unit test check that its up-to-date on each commit. In fact we already had a unit test that was doing this and keeping a copy of the expected output in the test directory. This simplifies the emcc linker code since we can always assume the presence of the struct info file. Also allows us to remove the `varies=False` special case in cache logic.
1 parent 3266e42 commit 7e5ab40

14 files changed

+1508
-76
lines changed

embuilder.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from tools import ports
2525
from tools.settings import settings
2626
from tools.system_libs import USE_NINJA
27-
import emscripten
2827

2928

3029
# Minimal subset of targets used by CI systems to build enough to useful
@@ -61,7 +60,6 @@
6160
'libsockets',
6261
'libstubs',
6362
'libstubs-debug',
64-
'struct_info',
6563
'libstandalonewasm',
6664
'crt1',
6765
'crt1_proxy_main',
@@ -150,11 +148,6 @@ def build_port(port_name):
150148
def get_system_tasks():
151149
system_libraries = system_libs.Library.get_all_variations()
152150
system_tasks = list(system_libraries.keys())
153-
# This is needed to build the generated_struct_info.json file.
154-
# It is not a system library, but it needs to be built before
155-
# running with FROZEN_CACHE.
156-
system_tasks += ['struct_info']
157-
158151
return system_libraries, system_tasks
159152

160153

@@ -257,11 +250,6 @@ def main():
257250
cache.erase_file('sysroot_install.stamp')
258251
if do_build:
259252
system_libs.ensure_sysroot()
260-
elif what == 'struct_info':
261-
if do_clear:
262-
emscripten.clear_struct_info()
263-
if do_build:
264-
emscripten.generate_struct_info()
265253
elif what in PORTS:
266254
if do_clear:
267255
clear_port(what)

emcc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ def generate_js_symbols():
514514
# TODO(sbc): Find a way to optimize this. Potentially we could add a super-set
515515
# mode of the js compiler that would generate a list of all possible symbols
516516
# that could be checked in.
517-
emscripten.generate_struct_info()
518517
_, forwarded_data = emscripten.compile_javascript(symbols_only=True)
519518
# When running in symbols_only mode compiler.js outputs a flat list of C symbols.
520519
return json.loads(forwarded_data)

emscripten.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
import shutil
2121

2222
from tools import building
23-
from tools import cache
2423
from tools import diagnostics
2524
from tools import js_manipulation
2625
from tools import shared
2726
from tools import utils
28-
from tools import gen_struct_info
2927
from tools import webassembly
3028
from tools import extract_metadata
3129
from tools.utils import exit_with_error, path_from_root
@@ -920,26 +918,5 @@ def normalize_line_endings(text):
920918
return text
921919

922920

923-
def clear_struct_info():
924-
output_name = cache.get_lib_name('struct_info.json', varies=False)
925-
cache.erase_file(output_name)
926-
927-
928-
def generate_struct_info():
929-
# If we are running in BOOTSTRAPPING_STRUCT_INFO we don't populate STRUCT_INFO
930-
# otherwise that would lead to infinite recursion.
931-
if settings.BOOTSTRAPPING_STRUCT_INFO:
932-
return
933-
934-
@ToolchainProfiler.profile()
935-
def generate_struct_info(out):
936-
gen_struct_info.main(['-q', '-o', out])
937-
938-
output_name = cache.get_lib_name('struct_info.json', varies=False)
939-
settings.STRUCT_INFO = cache.get(output_name, generate_struct_info)
940-
941-
942921
def run(in_wasm, out_wasm, outfile_js, memfile):
943-
generate_struct_info()
944-
945922
emscript(in_wasm, out_wasm, outfile_js, memfile)

site/source/docs/contributing/developers_guide.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,19 @@ one of them, with the others kept fixed). Doing this will require rebuilding
151151
locally, which was not needed in the main bisection described in this
152152
section.
153153

154+
Working with C structs and defines
155+
==================================
156+
157+
If you change the layout of C structs or modify C defines that are used in
158+
JavaScript library files you may need to modify ``tools/struct_info.json``. Any
159+
time that file is modified or a struct layout is changed you will need to run
160+
``./tools/gen_struct_info.py`` to re-generate the information used by
161+
JavaScript.
162+
163+
The ``test_gen_struct_info`` test will fail if you forget to do this.
164+
154165
See also
155166
========
156167

157168
- :ref:`Debugging`
158169
- :ref:`Building-Projects`
159-
160-
File renamed without changes.

0 commit comments

Comments
 (0)