Tuesday, October 23, 2018

Compile SFML app with VS Code on Linux

As official tutorial says, there are 3 ways to install SFML on Linux:
  1. Install it directly from your distribution's package repository
  2. Get the source code, build it and install it
  3. Download the precompiled SDK and manually copy the files
On Ubuntu 18.04, $ apt search sfml reports that the latest version in repository is 2.4.2, while actually the latest version is 2.5.1. So the first option might not be the best. Third option is probably the worst, because precompiled SDK was most likely compiled with different version of GCC.
So that makes the second option the best way to go. After SFML is installed, it's time to compile SFML app. Here's an example of VS Code configuration files:

c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/path/to/SFML/SFML-master/include/"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}


launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/sfml-app",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Skip raise.c files",
                    "text": "-interpreter-exec console \"skip -gfi /build/glibc-OTsEL5/glibc-2.27/**/*\""
                 }
            ],
            "preLaunchTask": "build"
        }
    ]
}


tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile",
            "type": "shell",
            "presentation": {
                "reveal": "never",
                "panel": "shared",
            },
            "command": "g++",
            "args": [
                "-g",
                "-c",
                "main.cpp"
            ]
        },
        {
            "label": "build",
            "type": "shell",
            "presentation": {
                "reveal": "never",
                "panel": "shared",
            },
            "command": "g++",
            "args": [
                "main.o",
                "-o",
                "sfml-app",
                "-lsfml-graphics",
                "-lsfml-window",
                "-lsfml-system"
            ],
            "dependsOn": ["compile"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Thursday, September 20, 2018

Swift development journey on Linux



After a few days of search to find the best IDE for Swift development on Linux/Ubuntu,
I concluded that currently the choice is VS Code + Swift Development Environment extension

First we need to download Swift from Swift.org
Follow download instructions. Just one note about setting toolchain path - if you run:
$ export PATH=/path/to/usr/bin:"${PATH}"

That change will affect $PATH variable only in current terminal seasson.
To make it permanent, there are few options on Ubuntu. For example, I appended
$ export PATH="$HOME/Dev/swift-4.2/usr/bin:$PATH"

to ~/.profile and that did the trick. The script gets loaded on re-login or it can be run manually by executing . ~/.profile.


Second step is installation of VS Code. Just a few clicks in Ubuntu Software app.

Next we install Maintained Swift Development Environment extension. There are several steps here and thy are described in extension's marketplace page and github. Make sure you also install LLDB extension for debugging.


All done? Great, now it's time to run some swift code. But first run some commands to create a Hello project:
$ mkdir HelloSwift
$ cd HelloSwift
$ swift package init --type=executable

Now in VS Code chose File/ Open Folder... and selecte HelloSwift.
Select Debug view (Ctrl+Shift+D)
Add LLDB configuration. launch.json should look like this:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${workspaceFolder}/.build/debug/HelloSwift",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "swift-build"
        }
    ]
}

Tap Run button and alert pops up about missing swift-build task. Tap Configure Task.
tasks.json should look like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "swift-build",
            "type": "shell",
            "command": "swift build"
        }
    ]
}


Tap Run again and voila! Console shows:

Hello, world!
Process exited with code 0.