Run Swift toolchain from command line with flags

As stated in the Async/await proposal, I'm trying to run the latest main snapshot with

-Xfrontend -enable-experimental-concurrency

in order to test the current implementation.

I'm running macOS Catalina 10.15.7 (19H2), I have Xcode 12.0.1 (12A7300). I installed the most recent Trunk Development Snapshot from here, I set it in Xcode and created a command line Xcode project having the above flags under Build Settings > Swift Compiler - Custom Flags > Other Swift Flags. In order to check the output of the main file I need to build it and run it by double clicking on the built product from the Finder. It does the job but I feel like it's not the best way to do it.

  • Is there a way to have the output show in Xcode directly?

  • Alternatively, is there a way to run that toolchain from command line?
    I tried with

    xcrun --toolchain /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-29-a swift -Xfrontend -enable-experimental-concurrency
    

    but it looks like the flag doesn't get used. I also tried with

    /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-29-a.xctoolchain/usr/bin/swift -Xfrontend -enable-experimental-concurrency  
    

    but I'm getting the following error:

    dyld: Library not loaded: @rpath/Python3.framework/Versions/3.8/Python3
      Referenced from: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-29-a.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB
      Reason: image not found
    zsh: abort       -Xfrontend -enable-experimental-concurrency
    
  • Even better, is there a way to set flags in a Playground?

  • Is there a better way to do it? Via swiftenv maybe? How do you set up testing for downloaded snapshots?

If I need to run swift code on the fly, I usually do it in the terminal within the REPL run via the swift command or in a Playground page (that would be optimal, but I suppose there's no way to set flags within Playground projects).

Thank you in advance,
Stefano

Use Product>Run menu item in Xcode. May need to open a console window in bottom half of Xcode window. You can also look at the compiler invocation in the Build logs.

I'm probably doing something wrong then, since either clicking on the play button or on Product > Run the following shows up:

The console window in the bottom right corner of the main Xcode panel doesn't show up since the "Could not launch Testing" terminates the run command early.

This is my current flag section in the Build Settings tab:

As a quick workaround, in a terminal window, I did the following:

export TOOLCHAIN=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-10-29-a.xctoolchain
xcrun $TOOLCHAIN/usr/bin/swiftc -Xfrontend -enable-experimental-concurrency main.swift

That creates an executable called main, which will run without a problem.

2 Likes

Thank you, building scripts into executables works. It's not that different from my current workflow, so if someone has better alternatives (namely run the command line REPL with the required flags or, better, have those flags active in a Playground) I'm open to suggestions.

Terms of Service

Privacy Policy

Cookie Policy