MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / phase_post_link

Function phase_post_link

tools/link.py:1900–1944  ·  view source on GitHub ↗
(options, in_wasm, wasm_target, target, js_syms, base_metadata=None)

Source from the content-addressed store, hash-verified

1898
1899@ToolchainProfiler.profile_block('post link')
1900def phase_post_link(options, in_wasm, wasm_target, target, js_syms, base_metadata=None):
1901 global final_js
1902
1903 target_basename = unsuffixed_basename(target)
1904
1905 if options.oformat != OFormat.WASM:
1906 final_js = in_temp(target_basename + '.js')
1907
1908 settings.TARGET_BASENAME = unsuffixed_basename(target)
1909
1910 if options.oformat in {OFormat.JS, OFormat.MJS}:
1911 js_target = target
1912 else:
1913 js_target = get_secondary_target(target, '.js')
1914
1915 settings.TARGET_JS_NAME = os.path.basename(js_target)
1916
1917 if settings.WASM_BINDGEN:
1918 bindgen_jslib = building.run_wasm_bindgen(in_wasm)
1919 settings.JS_LIBRARIES.append(bindgen_jslib)
1920
1921 metadata = phase_emscript(in_wasm, wasm_target, js_syms, base_metadata)
1922
1923 if settings.EMBIND_AOT:
1924 phase_embind_aot(options, wasm_target, js_syms)
1925
1926 if options.emit_tsd:
1927 phase_emit_tsd(options, wasm_target, js_target, js_syms, metadata)
1928
1929 if options.js_transform:
1930 phase_source_transforms(options)
1931
1932 phase_binaryen(target, options, wasm_target)
1933
1934 # Compute the SHA-256 hash of the final wasm (after binaryen) and substitute
1935 # the <<< WASM_HASH_VALUE >>> placeholder that preamble.js left in the JS.
1936 if final_js and settings.CROSS_ORIGIN_STORAGE:
1937 wasm_hash_value = hashlib.sha256(utils.read_binary(wasm_target)).hexdigest()
1938 logger.debug(f'CROSS_ORIGIN_STORAGE: wasm SHA-256 = {wasm_hash_value}')
1939 js_content = do_replace(read_file(final_js), '<<< WASM_HASH_VALUE >>>', wasm_hash_value)
1940 write_file(final_js, js_content)
1941
1942 # If we are not emitting any JS then we are all done now
1943 if options.oformat != OFormat.WASM:
1944 phase_final_emitting(options, target, js_target, wasm_target)
1945
1946
1947@ToolchainProfiler.profile_block('emscript')

Callers 2

run_post_linkFunction · 0.85
runFunction · 0.85

Calls 13

unsuffixed_basenameFunction · 0.85
in_tempFunction · 0.85
get_secondary_targetFunction · 0.85
phase_emscriptFunction · 0.85
phase_embind_aotFunction · 0.85
phase_emit_tsdFunction · 0.85
phase_source_transformsFunction · 0.85
phase_binaryenFunction · 0.85
do_replaceFunction · 0.85
phase_final_emittingFunction · 0.85
appendMethod · 0.80
read_fileFunction · 0.70

Tested by

no test coverage detected