Skip to content

[SwiftBuild] PackageToJS plugin fails to generate correct js initializer code #796

Description

@sliemeobn

for a browser / WASI use case this will result in an error like: "wasi_snapshot_preview1": module is not an object or function

because triple detection is based on the build output path:

static func deriveBuildConfiguration(wasmProductArtifact: URL) -> (configuration: String, triple: String) {
// e.g. path/to/.build/wasm32-unknown-wasi/debug/Basic.wasm -> ("debug", "wasm32-unknown-wasi")
// First, resolve symlink to get the actual path as SwiftPM 6.0 and earlier returns unresolved
// symlink path for product artifact.
let wasmProductArtifact = wasmProductArtifact.resolvingSymlinksInPath()
let buildConfiguration = wasmProductArtifact.deletingLastPathComponent().lastPathComponent
let triple = wasmProductArtifact.deletingLastPathComponent().deletingLastPathComponent().lastPathComponent
return (buildConfiguration, triple)
}

and swift-build produces different out paths like this: .build/out/Products/Release-webassembly-wasm32/App.wasm

template variables like IS_WASI are no longer correctly derived

"IS_WASI": triple.hasPrefix("wasm32-unknown-wasi"),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions