swiftwasm / swiftwasm/WasmKit

`--dir .` and `--dir /` conflict with each other

Open
#208 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Swift
Stars
504
Forks
37
Avg merge
1d 1h
Merged PRs (30d)
44

Description

Description

When I run wasmkit run --dir . --dir / <Wasm binary>, it succeeds or fails randomly. When I use --dir .build --dir / or --dir . --dir /Users instead, it always succeeds. So I think --dir . and --dir / conflict with each other.

Steps to reproduce

  1. Run mkdir foo && cd foo

  2. Run swift package init --type executable

  3. Edit Sources/foo/foo.swift

    import Foundation
    
    @main
    struct foo {
        static func main() {
            print(try! String(contentsOf: URL(filePath: #filePath), encoding: .utf8))
            print(Bundle.main)
        }
    }
    
  4. Run swift build --swift-sdk swift-DEVELOPMENT-SNAPSHOT-2025-10-02-a_wasm

  5. Run wasmkit run --dir . --dir / .build/wasm32-unknown-wasip1/debug/foo.wasm several times

Expected behavior

It succeeds every time. Or it fails every time with the same error messages.

Actual behavior

It always fails, but its error messages randomly change each time it is executed.

Pattern 1:

import Foundation                                                                                                                                    
                                                                                                                                                     
@main                                                                                                                                                
struct foo {                                                                                                                                         
    static func main() {                                                                                                                             
        print(try! String(contentsOf: URL(filePath: #filePath), encoding: .utf8))                                                                    
        print(Bundle.main)                                                                                                                           
    }                                                                                                                                                
}                                                                                                                                                    
                                                                                                                                                     
Error: Trap: unreachable                                                                                                                             
    0: $s10Foundation6BundleC05_mainB033_6273FB07A96EB35BCC520B3A80F5C3CDLL_WZ                                                                       
    1: swift_once                                                                                                                                    
    2: $s10Foundation6BundleC4mainACvgZ
    3: $s3fooAAV4mainyyFZ            
    4: $s3fooAAV5$mainyyFZ
    5: main
    6: __main_void
    7: _start
    8: unknown

Pattern 2:

foo/foo.swift:9: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file doesn’t exist."UserI
nfo={NSFilePath=/Users/kebo/foo/Sources/foo/foo.swift, NSURL=file:///Users/kebo/foo/Sources/foo/foo.swift, NSUnderlyingError=Error Domain=NSPOSIXErro
rDomain Code=44 "No such file or directory"}
Error: Trap: unreachable
    0: $ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF
    1: swift_unexpectedError
    2: $s3fooAAV4mainyyFZ
    3: $s3fooAAV5$mainyyFZ
    4: main
    5: __main_void
    6: _start
    7: unknown

Environemnt

$ uname -a
Darwin Xylotrupes-gideon.local 25.1.0 Darwin Kernel Version 25.1.0: Sun Oct  5 21:11:28 PDT 2025; root:xnu-12377.40.120~10/RELEASE_ARM64_T8132 arm64
$ which swift
/Users/kebo/Library/Application Support/swiftly/bin/swift
$ swiftly list
Installed release toolchains
----------------------------
Swift 6.2.0 (default)

Installed snapshot toolchains
-----------------------------
main-snapshot-2025-10-02 (in use)
main-snapshot-2025-09-20
main-snapshot-2025-09-06
$ swift --version
Apple Swift version 6.3-dev (LLVM 0d0246569621d5b, Swift 199240b3fe97eda)
Target: arm64-apple-macosx26.0
Build config: +assertions
$ which wasmkit
/Users/kebo/Library/Application Support/swiftly/bin/wasmkit
$ wasmkit --version
0.1.6

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the shown wasmkit run --dir . --dir / command and the Swift package example. Trace the directory handling used by the wasmkit run entry point, then verify that repeated runs produce consistent behavior and error messages for overlapping directory arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift, wasm
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.