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

canImport(Dispatch) is wrongly truthy on WASI target #5202

Open
robbertvanginkel opened this issue Jan 19, 2023 · 1 comment
Open

canImport(Dispatch) is wrongly truthy on WASI target #5202

robbertvanginkel opened this issue Jan 19, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@robbertvanginkel
Copy link

Description
While trying to compile the same swift to wasm from both linux and macos, I noticed that some builds would fail depending on the host OS for the same toolchain release.

Steps to reproduce
For the following swift file:

var x = "nodispatch"
#if canImport(Dispatch)
import Dispatch
var q = DispatchQueue(label: "foo", attributes: .concurrent)
x = "yesdispatch"
#endif
print(x)

On macos:

$ curl -SL -O https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.7-SNAPSHOT-2023-01-17-a/swift-wasm-5.7-SNAPSHOT-2023-01-17-a-macos_arm64.pkg
$ pkgutil --expand-full swift-wasm-5.7-SNAPSHOT-2023-01-17-a-macos_arm64.pkg toolchain/
$ export PATH="$PWD/toolchain/Payload/usr/bin:$PATH"
$ swiftc -target wasm32-unknown-wasi test.swift -o test.wasm
$ wasmtime test.wasm
nodispatch

But on linux (tested under docker run -it ubuntu:20.04):

$ curl -SL -O https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.7-SNAPSHOT-2023-01-17-a/swift-wasm-5.7-SNAPSHOT-2023-01-17-a-ubuntu20.04_aarch64.tar.gz
$ tar -xf swift-wasm-5.7-SNAPSHOT-2023-01-17-a-ubuntu20.04_aarch64.tar.gz
$ export PATH="/swift-wasm-5.7-SNAPSHOT-2023-01-17-a/usr/bin:$PATH"
$ swiftc -target wasm32-unknown-wasi test.swift -o test.wasm
test.swift:5:9: error: cannot find 'DispatchQueue' in scope
var q = DispatchQueue(label: "foo", attributes: .concurrent)
        ^~~~~~~~~~~~~

Expected behavior
I expected some difference in behavior for swift on macos vs linux, but given that I'm targetting wasm here I expected a statement like #if canImport(Dispatch) would be consistently pass/failing depending on the target toolchain irrespective of the host.

@robbertvanginkel robbertvanginkel added the bug Something isn't working label Jan 19, 2023
@kateinoigakukun
Copy link
Member

kateinoigakukun commented Jan 21, 2023

Thank you for creating a ticket for this :)
This is an issue of the toolchain directory layout. The libdispatch's mdoulemap is placed at usr/lib/swift_static/dispatch/module.modulemap but the directory is shared between all platforms. This is apparently wrong place considering crosscompiling. Ideally, that should be moved to platform-specific directory like usr/lib/swift_static/wasi/ to avoid this kind of issue.

But I haven't tried this yet and I think it's better to discuss the toolchain layout in the forum at first to fix it in upstream also.

@kateinoigakukun kateinoigakukun changed the title Difference between macos and linux host when targetting wasm canImport(Dispatch) is wrongly truthy on WASI target Mar 9, 2024
@kateinoigakukun kateinoigakukun moved this to To triage in Yuta's project Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: To triage
Development

No branches or pull requests

2 participants