Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
# Kotlin Native Xcode Support

Plugin to facilitate debugging iOS applications using Kotlin Native in Xcode.
Defines Kotlin files as source code, with basic highlighting. Allows you to
set breakpoints and includes llvm support to view data in the debug window.
Plugin to facilitate debugging iOS applications using Kotlin Native in Xcode. Defines Kotlin files as source code, with basic highlighting. Allows you to set breakpoints and includes llvm support to view data in the debug window. Xcode does not officially support custom language definitions, but they also don't explicitly block them.

> ## **We're Hiring!**
>
> Touchlab is looking for Android-focused mobile engineers, experienced with Kotlin and
> looking to get involved with Kotlin Multiplatorm in the near future. [More info here](https://on.touchlab.co/2P94J5q).

# Xcode 11+

Xcode does not officially support custom language definitions, but they also don't explicitly block them. However,
Xcode 11 introduced several breaking changes from earlier versions, and some resolutions are still outstanding.

## Xcode <= 10.x

For earlier versions, please see [xcode10 branch](https://github.com/touchlab/xcode-kotlin/tree/xcode10). Life moves on,
and we'll only be supporting Xcode 11+.
> Touchlab is looking for Android-focused mobile engineers, experienced with Kotlin and looking to get involved with Kotlin Multiplatorm in the near future. [More info here](https://on.touchlab.co/2P94J5q).

## Installation

There are 2 parts to Kotlin support: 1) debugging support and 2) language color and style formatting.

### Step 1: Debugging Support
You need to tell Xcode that `*.kt` files are source files, and run an lldb formatter script when debugging starts. Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the setup script.

### Xcode 11

You need to tell Xcode that `*.kt` files are source files, and run an lldb formatter script when debugging starts.
Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the
setup script.
For debugging support in Xcode 11, run the installation script:

```
./setup.sh
./setup-xcode11.sh
```

### Step 2: Formatting Support
Xcode 11 introduced several breaking changes from earlier versions, and some resolutions are still outstanding. If you're using Xcode 11, you need to move some files into a protected area. Some users may not want to do this, and may possibly not have permissions to do this. You'll need to run the formatting support script with sufficient permissions, which generally means `sudo`.

In Xcode 11, you need to move some files into a protected area. Some users may not want to do this, and may possibly
not have permissions to do this. You'll need to run the script with sufficient permissions, which generally means
`sudo`.
```
sudo ./colorsetup-xcode11.sh
```

*You can still debug Kotlin without formatting support, just FYI. This step is not required.*

### All Other Xcode Versions

For all other versions of Xcode, the following script will install both debugging and formatting support:

```
sudo ./colorsetup.sh
./setup.sh
```

## Kotlin 1.3.6x Issue
Expand Down Expand Up @@ -70,12 +61,9 @@ The [Droidcon NYC](https://github.com/touchlab/DroidconKotlin/) app has both the

### Sources

Setting up the Plugin has been an amalgam of various source projects, as Xcode "Plugins"
are undocumented. The most significant piece, the language color file, came from other color
files shipped with Xcode. Xcode plugin file from [GraphQL](https://github.com/apollographql/xcode-graphql/blob/master/GraphQL.ideplugin/Contents/Resources/GraphQL.xcplugindata)
Setting up the Plugin has been an amalgam of various source projects, as Xcode "Plugins" are undocumented. The most significant piece, the language color file came from other color files shipped with Xcode. Xcode plugin file from [GraphQL](https://github.com/apollographql/xcode-graphql/blob/master/GraphQL.ideplugin/Contents/Resources/GraphQL.xcplugindata)

LLDB formatting originally comes from the Kotlin/Native project, source [konan_lldb.py](https://github.com/JetBrains/kotlin-native/blob/dbb162a4b523071f31913e888e212df344a1b61e/llvmDebugInfoC/src/scripts/konan_lldb.py), although the way data is grabbed has been heavily modified to better
support an interactive debugger.
LLDB formatting originally comes from the Kotlin/Native project, source [konan_lldb.py](https://github.com/JetBrains/kotlin-native/blob/dbb162a4b523071f31913e888e212df344a1b61e/llvmDebugInfoC/src/scripts/konan_lldb.py), although the way data is grabbed has been heavily modified to better support an interactive debugger.

## Possible Future Stuff

Expand Down
File renamed without changes.
61 changes: 61 additions & 0 deletions setup-xcode11.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

# Use this script for Xcode 11.

###################
# DEFINITIONS
###################

service='Xcode'
plugins_dir=~/Library/Developer/Xcode/Plug-ins

###################
# SHUT DOWN XCODE IF IT'S RUNNING
###################

if pgrep -xq -- "${service}"; then
echo "Xcode is running. Attempt to shut down? y/n"
read answer
if [ "$answer" = "y" ]; then
echo "Shutting down Xcode"
pkill -x $service
else
echo "Xcode needs to be closed"
exit 1
fi
fi

###################
# FORGET EXISTING PLUG-IN
###################

if [ -d "${plugins_dir}/Kotlin.ideplugin/" ]; then
echo "Kotlin plugin found. Deleting and forgetting..."
rm -rf "$plugins_dir/Kotlin.ideplugin/"
defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-$(xcodebuild -version | grep Xcode | cut -d ' ' -f 2)
fi

###################
# CREATE PLUG-IN
###################

echo "Creating new Kotlin plugin"
mkdir -p $plugins_dir
cp -r Kotlin.ideplugin $plugins_dir

###################
# LLDB DEFINITIONS
###################

lldb_config="command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb_config.py"
lldb_format="command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb.py"

if grep --quiet -s konan_lldb ~/.lldbinit-Xcode
then
# code if found
echo "konan_lldb.py found in ~/.lldbinit-Xcode"
else
# code if not found
echo $lldb_config >> ~/.lldbinit-Xcode
echo $lldb_format >> ~/.lldbinit-Xcode
fi
32 changes: 24 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env bash

# Use this script for versions of Xcode other than Xcode 11.

###################
# DEFINITIONS
###################

service='Xcode'
plugins_dir=~/Library/Developer/Xcode/Plug-ins/
plugins_dir=~/Library/Developer/Xcode/Plug-ins
spec_dir=~/Library/Developer/Xcode/Specifications

###################
# SHUT DOWN XCODE IF IT'S RUNNING
Expand All @@ -15,7 +18,7 @@ if pgrep -xq -- "${service}"; then
echo "Xcode is running. Attempt to shut down? y/n"
read answer
if [ "$answer" = "y" ]; then
echo "Shutting down Xcode"
echo "Shutting down Xcode..."
pkill -x $service
else
echo "Xcode needs to be closed"
Expand All @@ -24,22 +27,36 @@ if pgrep -xq -- "${service}"; then
fi

###################
# DELETE EXISTING PLUG-IN
# FORGET EXISTING PLUG-IN
###################

if [ -d "${plugins_dir}Kotlin.ideplugin/" ]; then
echo "Plugins directory and Kotlin plugin found..."
if [ -d "$spec_dir/Kotlin.xclangspec" ]; then
echo "Kotlin language spec found. Deleting..."
rm "$spec_dir/Kotlin.xclangspec"
fi

if [ -d "$plugins_dir/Kotlin.ideplugin/" ]; then
echo "Kotlin plugin found. Deleting and forgetting..."
rm -rf "$plugins_dir/Kotlin.ideplugin/"
defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-$(xcodebuild -version | grep Xcode | cut -d ' ' -f 2)
fi

###################
# CREATE PLUG-IN
###################

echo "Creating plugins directory"
echo "Creating new Kotlin plugin"
mkdir -p $plugins_dir
cp -r Kotlin.ideplugin $plugins_dir

###################
# CREATE SPECS DIR
###################

echo "Creating new Kotlin language spec"
mkdir -p $spec_dir
cp Kotlin.xclangspec $spec_dir

###################
# LLDB DEFINITIONS
###################
Expand All @@ -55,5 +72,4 @@ else
# code if not found
echo $lldb_config >> ~/.lldbinit-Xcode
echo $lldb_format >> ~/.lldbinit-Xcode
fi

fi