Skip to content

[wasm] Build improvements based on feedback #59391

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 25 commits into from
Sep 30, 2021

Conversation

radical
Copy link
Member

@radical radical commented Sep 21, 2021

  • Fix for a incremental build issue

  • Change native build defaults for Debug config, to make it faster (thanks @SteveSandersonMS, @mattleibow)

  • MonoAOTCompiler:

    • Skip unmanaged assemblies, and emit a warning
  • PInvokeTableGenerator:

    • Fix to not fail in presence of native variadic functions, and pinvokes with function pointers (eg. used by sqlite)

@ghost ghost added the area-Build-mono label Sep 21, 2021
@radical radical added the arch-wasm WebAssembly architecture label Sep 21, 2021
@ghost
Copy link

ghost commented Sep 21, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: radical
Assignees: -
Labels:

arch-wasm, area-Build-mono

Milestone: -

@radical radical marked this pull request as ready for review September 21, 2021 20:05
@radical radical force-pushed the wasm-improvements branch 2 times, most recently from 8f566c3 to 0da5608 Compare September 22, 2021 06:42
@radical radical changed the title [wasm] Misc improvements [wasm] Build improvements based on feedback Sep 22, 2021
radical and others added 15 commits September 25, 2021 19:05
The task needs to run `mono-aot-cross` on all the assemblies, even if a
given assembly is older than its output files, so as to correctly handle
changes in its dependencies.

This commit tries to check if all the input assemblies are up-to-date with their
corresponding output files, and avoids doing any work if that's true.
`WasmNativeStrip` -> `false`
Compile, and link optimization flags for `emcc` to `-O1`
.. rebuilds. Specifically, when a rebuild causes only the *linking* part
to be run again. In that case, we were correctly skipping over compiling
native files, but didn't add them to `@(FileWrites)`, which caused
msbuild's incremental clean logic to treat them as "orphaned" files,
and delete them!
Co-authored-by: Larry Ewing <lewing@microsoft.com>
- Ensure that the cache gets written even when some of the files failed
  to compile
- And when some were skipped, and others failed
For non-publish builds, undefined symbols will show up as warnings:

```
EXEC : warning : undefined symbol: sqlite3_column_database_name (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_column_origin_name (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_column_table_name (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_snapshot_cmp (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_snapshot_free (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_snapshot_get (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_snapshot_open (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
EXEC : warning : undefined symbol: sqlite3_snapshot_recover (referenced by top-level compiled C/C++ code) [/BlazorWebAssemblySqlite.csproj]
```
Currently, for a variadic function like:

`int sqlite3_config(int, ...);`

.. and multiple pinvokes like:

```csharp
[DllImport(SQLITE_DLL, ExactSpelling=true, EntryPoint = "sqlite3_config", CallingConvention = CALLING_CONVENTION)]
public static extern unsafe int sqlite3_config_none(int op);

[DllImport(SQLITE_DLL, ExactSpelling=true, EntryPoint = "sqlite3_config", CallingConvention = CALLING_CONVENTION)]
public static extern unsafe int sqlite3_config_int(int op, int val);

[DllImport(SQLITE_DLL, ExactSpelling=true, EntryPoint = "sqlite3_config", CallingConvention = CALLING_CONVENTION)]
public static extern unsafe int sqlite3_config_log(int op, NativeMethods.callback_log func, hook_handle pvUser);
```

.. we generate:

```c
int sqlite3_config (int);
int sqlite3_config (int,int);
int sqlite3_config (int,int,int);
```

.. which fails to compile.

Instead, this patch will generate a variadic declaration with one fixed
parameter:

```c
// Variadic signature created for
//   System.Int32 sqlite3_config_none(System.Int32)
//   System.Int32 sqlite3_config_int(System.Int32, System.Int32)
//   System.Int32 sqlite3_config_log(System.Int32, SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods+callback_log, SQLitePCL.hook_handle)
int sqlite3_config (int, ...);
```

TODO: functions with different first argument
- For pinvokes with function pointers, *no* declaration is added to
  `pinvoke-table.h`, and a warning is raised:

```
warning : DllImports with function pointers are not supported. Calling them will fail. Managed DllImports:  [/Users/radical/dev/r2/artifacts/bin/Wasm.Build.Tests/net6.0-Release/browser-wasm/g3acrk4b.a0o/variadic_g3acrk4b.a0o.csproj]
warning :    Type: Test, Method: System.Int32 using_sum_one(?) [/Users/radical/dev/r2/artifacts/bin/Wasm.Build.Tests/net6.0-Release/browser-wasm/g3acrk4b.a0o/variadic_g3acrk4b.a0o.csproj]
```

- Also, handle multiple pinvokes with the same number of params, but
  different types
- pinvokes with function pointers could be for variadic functions too
- if there are multiple pinvokes for the same native function, but some
  of them have function pointers, then ignore those but generate the
  declaration for the rest

- raise better warnings
- and emit info about the variadic pinvokes in pinvoke-table.h
@radical radical requested a review from vargaz September 27, 2021 18:50
…p-to-date" check"

Newer timestamp, but unchanged file is an indication of a build issue,
and doesn't need to be handled in this task.

This reverts commit 712dbb3.
@radical
Copy link
Member Author

radical commented Sep 27, 2021

Android failure is #59679
Coreclr failures are #10680

Unrelated to this PR.

@radical
Copy link
Member Author

radical commented Sep 28, 2021

wasm test failure is #48717

@radical
Copy link
Member Author

radical commented Sep 28, 2021

Coreclr failures are #10680 , unrelated to this PR.

@radical
Copy link
Member Author

radical commented Sep 29, 2021

Android failure is #59779 .

@radical radical merged commit 80f015d into dotnet:main Sep 30, 2021
@radical radical deleted the wasm-improvements branch September 30, 2021 04:53
@radical
Copy link
Member Author

radical commented Sep 30, 2021

/backport release/6.0

@radical
Copy link
Member Author

radical commented Sep 30, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1289670399

@github-actions
Copy link
Contributor

@radical an error occurred while backporting to release/6.0, please check the run log for details!

Error: @radical is not a repo collaborator, backporting is not allowed.

radical added a commit to radical/runtime that referenced this pull request Oct 2, 2021
- Fix for a incremental build issue
- Change native build defaults for `Debug` config, to make it faster (thanks @SteveSandersonMS, @mattleibow)

- MonoAOTCompiler:
  - Skip unmanaged assemblies, and emit a warning
- PInvokeTableGenerator:
  - Fix to not fail in presence of native variadic functions, and pinvokes with function pointers (eg. used by sqlite)

Co-authored-by: Larry Ewing <lewing@microsoft.com>
(cherry picked from commit 80f015d)
steveisok pushed a commit that referenced this pull request Oct 6, 2021
Backport of #59391

- Fix to handle pinvokes with function pointers, which resolves issue found testing new customer scenario with sqlite

- Fixes version of System.Reflection.MetadataLoadContext bundled with WasmBuilderApp task, to use the same as other tasks

- Fix for an incremental build issue where the compiled native .o files would
incorrectly get deleted after linking. And that would cause them to be
recompiled, unnecessarily increasing the build time.

- Change the default optimization flag used when building for Debug config
from -Oz to -O1 to improve development loop experience.
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Build-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants