Skip to content
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

SwiftWasm modules depending on JavaScriptKit fail to load when compiled with Swift 6.x compiler #262

Open
ephemer opened this issue Sep 26, 2024 · 1 comment

Comments

@ephemer
Copy link

ephemer commented Sep 26, 2024

We updated to macOS Sequoia and are trying to get SwiftWasm working again in this environment.

After installing a Swift release toolchain (6.0.1) and a matching SwiftWasm SDK, we are able to build our Swift package, with some changes.

    swift.setInstance(instance);
    wasi.initialize(instance);
    swift.main(); // <-- new
    runCmd(
        "swift",
        [
            "build",
            "--swift-sdk", // <-- new
            "6.0-SNAPSHOT-2024-08-30-a-wasm32-unknown-wasi", // <-- new
            // "--skip-update", // for offline support
            "-c",
            BUILD_CONFIG,
            "--product",
            PRODUCT_NAME,
            "-Xswiftc",
            "-Xclang-linker",
            "-Xswiftc",
            "-mexec-model=reactor",
            "-Xlinker",
            "--export-if-defined=main",
            "-Xlinker",
            "--export-if-defined=__main_argc_argv", // <-- new

            "-Xswiftc",
            "-DJAVASCRIPTKIT_WITHOUT_WEAKREFS",
        ],
        {
            cwd: swiftPackageDir,
            env: { ...process.env, TOOLCHAINS: "Swift 6.0.1" }, // <-- new
            shell: true,
            stdio: "inherit",
        }
    );

After the above changes, almost everything works as expected.

Now here is the issue: previously we had issues with JavaScriptKit using resources in its target definition (in Package.swift) under certain circumstances – I think because we were using an API that "might" be provided by Foundation if it's imported (note that the resources flag depends on Foundation, see here).

This happens due to this line:

.target(
            name: "JavaScriptKit",
            dependencies: ["_CJavaScriptKit"],
            resources: [.copy("Runtime")] // <-- here
        ),

Now it seems we can't escape it. I can remove the resources line and the package will build fine, but doing so would require a fork of JavaScriptKit to get reproducible builds. Do you have any idea what could be going on here? Have you seen this issue yourself at all?

image

To be clear: we don't want or need Foundation at all in our project. It is being automatically imported due to the resources line in JavaScriptKit's Package.swift. I can't see how to workaround this any more in Swift 6.x: it seems like something has changed such that whenever resources is there, Foundation is required. Any ideas?

@ephemer
Copy link
Author

ephemer commented Sep 26, 2024

For now, I went with the workaround here, but I do wonder what has changed since Swift 5.7 that means that Foundation is linked even if we're not using it at all. This appears to be a regression to me but I'm not sure it's related to SwiftWasm directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant