Skip to content

Instantly share code, notes, and snippets.

@oskargargas
Last active December 28, 2023 17:13
Show Gist options
  • Save oskargargas/1a9b925bdbc486ffc96ee4d82fac66a5 to your computer and use it in GitHub Desktop.
Save oskargargas/1a9b925bdbc486ffc96ee4d82fac66a5 to your computer and use it in GitHub Desktop.
Notes on Swift development for Windows

Environment setup

  1. winget is your brew \ apt
    • winget install Microsoft.VisualStudio.2022.Community
    • winget install Microsoft.VisualStudioCode
    • winget install Microsoft.WindowsTerminal
    • winget install Microsoft.PowerShell
    • winget install Git.Git
    • winget install Ninja-build.Ninja
  2. Visual Studio Community
    • Select C++ development component and make sure that CMake is selected
  3. Microsoft Terminal looks and works great
    • Git for Windows also installs bash and some useful UNIX tools we're all used to (ls, grep, vim) which might make switching to Windows more comfortable. You can configure it to be used inside Terminal. Important: it will not see Windows SDK. Hopefully such configuration is possible and someone can share it.
    • Screenshot of Windows Terminal settings with Bash configuration
    • Put attached bashrc to %USERPROFILE%/.bashrc. It's basically copied from Ubuntu/WSL.
  4. Install Swift Toolchain
  5. Install Swift Lint and make sure it is PATH: https://github.com/thebrowsercompany/swift-build/releases/tag/SwiftLint-DEVELOPMENT-SNAPSHOT-2023-08-12-a
  6. Install Swift Format and make sure it is in PATH: https://github.com/nicklockwood/SwiftFormat/releases/tag/0.52.11
  7. Add your development/project folder to Windows Defender exclusion path: https://support.microsoft.com/en-us/windows/add-an-exclusion-to-windows-security-811816c0-4dfd-af4a-47e4-c301afe13b26

Configuring Visual Studio Code

Extensions:

C/C++ Development

# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
alias ll='ls -alF'
alias la='ll -A'
alias l='ls -CF'
alias cddev='cd $USERPROFILE/Developer'
{
"terminal.integrated.profiles.windows": {
"PowerShell (Developer)": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": [
"-noe",
"-File",
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1",
"-SkipAutomaticLocation",
"-Arch",
"amd64",
"-HostArch",
"amd64"
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment