Skip to content

WasmImportLinkage is not propagated in LibraryImport #109181

@RReverser

Description

@RReverser

Description

As per #93824 (comment):

Not really API Review related, but would we want to have LibraryImport automatically propagate this attribute to the inner DllImport? My initial thought is yes, but just wanted to cover my bases.

Correct, this would need to be propagated.

This works as expected for simple functions that don't require any transform by the LibraryImport, but seems to be broken when using any marshalled types.

Reproduction Steps

Example:

[LibraryImport("foo")]
[WasmImportLinkage]
public static partial void test1();

[LibraryImport("foo")]
[WasmImportLinkage]
public static partial void test2(byte[] marshalMe);

Expected behavior

Both functions become Wasm imports.

Actual behavior

Only simple test1 function becomes a Wasm import. The generated pinvoke-table.h looks like this:

__attribute__((import_module("foo"),import_name("test1")))
extern void SpacetimeDB_Internal_23_foo_23_test1 ();

void test2 (void *);

This, in turn, results in a linker error:

    wasm-ld : error : D:/.../obj/Release/net9.0/wasi-wasm/wasm/for-publish/pinvoke.o: undefined symbol: test2

Regression?

No response

Known Workarounds

  1. Use DllImport with manual marshalling, which can get pretty cumbersome when using a lot of functions.
  2. Manually declare all functions in an extra C file with __attribute__((import_module("foo")) applied to each of them, and add it to MSBuild linker args. This is what we did before .NET 9 as WasmImportLinkage didn't exist yet, but it is also pretty cumbersome to maintain such a list manually.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

arch-wasmWebAssembly architecturearea-System.Runtime.InteropServicesin-prThere is an active PR which will close this issue when it is mergedos-wasiRelated to WASI variant of arch-wasm

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions