I think there could be a bug in Embedded Swift with @_cdecl inside a dependency package.

Toolchain: swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-09-a
Build command: swift build -c release --triple wasm32-unknown-none-wasm

App package code

// Sources/App/App.swift
import Lib1

@_expose(wasm, "main")
func main() {
    __hello()
}

@_extern(c)
func __hello()

Lib1 package code

// Sources/_CLib/_CLib.c
extern void _swiftMethod();

void __hello() {
    _swiftMethod();
}

// Sources/Lib1/Lib1.swift
import _CLib

@_cdecl("_swiftMethod")
public func _swiftMethod() {}

Compilation error

Building for production...
error: link command failed with exit code 1 (use -v to see invocation)
clang: warning: argument unused during compilation: '-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks' [-Wunused-command-line-argument]
wasm-ld: error: .build/wasm32-unknown-none-wasm/release/_CLib.build/_CLib.c.o: undefined symbol: _swiftMethod
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[11/12] Linking App.wasm

Expected result

I guess @_cdecl("_swiftMethod") should be taken by the compiler from the Lib1

CDeclDependencyBug.zip – project that reproduces the issue

Temporary workaround is to bring

@_cdecl("_swiftMethod")
public func _swiftMethod() {}

into the App for now

Opened the issue