Syed Sayem blog

Setup Swift and Clion on Arch Linux

In this blog post, I’ll show you how to get started with Swift programming language on Arch Linux. This tutorial includes installation of Swift in Arch Linux and set up Clion IDE by JetBrains.

Open the terminal and run the following command to install: swift

$ yaourt -S swift

Now, run the following command to install: Clion

$ yaourt -S clion

Create a swift project

$ mkdir SwiftProjects && SwiftProjects
$ mkdir Hello && cd Hello

Now run the swift package’s init command with executable type:

$ swift package init --type executable

Compile the package by running the swift build command:

$ swift build

After the command finishes, the built products will be available in the .build directory. Run the Hello program with the following command:

$ .build/debug/Hello
Hello, world!

Now, we’re going to import Hello project to Clion IDE

Open CLion, Select “Import Project from Sources” and then navigate to “SwiftProjects” and then select Hello

first-screenshot

Navigate to Hello project second-screenshot

Make sure all the box are check third-screenshot

If you get this error message, you’ll need to modify CMakeLists.txt. fourth-screenshot

Replace the following code in CMakeLists.txt

cmake_minimum_required(VERSION 3.6)
project(Hello)

add_custom_target(Hello
        COMMAND swift build
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        SOURCES Package.swift Sources/main.swift)

You can learn more about swift-plugin from JetBrains blog post.

Now, Open File > Settings, and search for Swift

  • Setup SDK Home to /usr/bin
  • Enable Use Swift debugger

fifth-screenshot

Now, search for CMake and select CMAKE. Under Build, Execution, Deployment

  • Change Build output path to .build/debug

sixth-screenshot

Now, go to Run > Edit Configuration

  • Target to Hello
  • Configuration to Debug
  • Executable to Hello

seventh-screenshot

Now, Run the Hello program by going to Run > Run eight-screenshot

Hello, World!
woof

Congratulations! You have just finished writing your first Swift Application in Clion.

Happy Coding :-)

comments powered by Disqus