Skip to content

[wasm] Improve terser setup #79466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const linked_functions = [
"mono_wasm_release_cs_owned_object",
"mono_wasm_typed_array_to_array_ref",
"mono_wasm_typed_array_from_ref",
"mono_wasm_compile_function_ref",
"mono_wasm_bind_js_function",
"mono_wasm_invoke_bound_function",
"mono_wasm_invoke_import",
Expand All @@ -121,8 +120,7 @@ const linked_functions = [
// -- this javascript file is evaluated by emcc during compilation! --
// we generate simple proxy for each exported function so that emcc will include them in the final output
for (let linked_function of linked_functions) {
const fn_template = `return __dotnet_runtime.__linker_exports.${linked_function}.apply(__dotnet_runtime, arguments)`;
DotnetSupportLib[linked_function] = new Function(fn_template);
DotnetSupportLib[linked_function] = new Function("");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks calling into mono C functions on threads because replace_linker_placeholders is not installed there.

cc @kg @lambdageek @thaystg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #81268 for it

}

autoAddDeps(DotnetSupportLib, "$DOTNET");
Expand Down
23 changes: 6 additions & 17 deletions src/mono/wasm/runtime/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,20 @@ const monoWasmThreads = process.env.MonoWasmThreads === "true" ? true : false;
const monoDiagnosticsMock = process.env.MonoDiagnosticsMock === "true" ? true : false;
const terserConfig = {
compress: {
defaults: false,// too agressive minification breaks subsequent emcc compilation
defaults: true,
passes: 2,
drop_debugger: false,// we invoke debugger
drop_console: false,// we log to console
unused: false,// this breaks stuff
// below are minification features which seems to work fine
collapse_vars: true,
conditionals: true,
computed_props: true,
properties: true,
dead_code: true,
if_return: true,
inline: true,
join_vars: true,
loops: true,
reduce_vars: true,
evaluate: true,
hoist_props: true,
sequences: true,
},
mangle: {
// because of stack walk at src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
// and unit test at src\libraries\System.Runtime.InteropServices.JavaScript\tests\System.Runtime.InteropServices.JavaScript.Legacy.UnitTests\timers.mjs
keep_fnames: /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message|mono_wasm_set_timeout_exec)/,
keep_classnames: /(ManagedObject|ManagedError|Span|ArraySegment|WasmRootBuffer|SessionOptionsBuilder)/,
},
format: {
wrap_iife: true
}
};
const plugins = isDebug ? [writeOnChangePlugin()] : [terser(terserConfig), writeOnChangePlugin()];
const banner = "//! Licensed to the .NET Foundation under one or more agreements.\n//! The .NET Foundation licenses this file to you under the MIT license.\n";
Expand Down Expand Up @@ -81,7 +70,7 @@ function consts(dict) {
let newDict = {};
for (const k in dict) {
const newKey = "consts:" + k;
const newVal = JSON.stringify (dict[k]);
const newVal = JSON.stringify(dict[k]);
newDict[newKey] = `export default ${newVal}`;
}
return virtual(newDict);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/wasm.proj
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
<_RollupInputs Include="$(MonoProjectRoot)wasm/runtime/*.js"/>
</ItemGroup>

<Target Name="SetMonoRollupEnvironment">
<Target Name="SetMonoRollupEnvironment" DependsOnTargets="GetProductVersions">
<PropertyGroup>
<MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),MonoDiagnosticsMock:$(MonoDiagnosticsMock)</MonoRollupEnvironment>
</PropertyGroup>
Expand Down