Using Nuclide as an IDE for Swift Compiler Development

Nuclide in action

I’ve started using Nuclide when working on the Swift compiler source code. Why?

Nuclide's lldb intergration

A Nuclude plugin idea: running Swift tests

In short, Nuclide provides the rich IDE-like features I enjoy from Xcode, but maintains the plugin-based customizability and cross-platform support I’d expect from Sublime Text or Vim.

 Setting Up Nuclide (on OS X)

Installing Nuclide takes a few seconds; just follow the instructions on the website.

To work its magic, Nuclide needs a list of the commands use to compile each file in the Swift codebase. You can generate that list by running the following commands from your Swift checkout root:

$ # 1. Generate the list.
$ utils/build-script --make --export-compile-commands
$ # 2. Symlink it to the root of your project.
$ ln -s ../build/Unix_Makefiles-DebugAssert/swift-macosx-x86_64/compile_commands.json compile_commands.json

That’s it! Open apple/swift in Nuclide and enjoy. :)

 Setting Up Nuclide (on Linux)

Note: The libclang integration preferences described in this section are still being developed by the Nuclide team, and haven’t been released yet. Expect an update next week.

Just like OS X, install Nuclide and run the following two lines from your Swift checkout root:

$ # 1. Generate the list of compile commands.
$ utils/build-script --make --export-compile-commands
$ # 2. Symlink it to the root of your project.
$ ln -s ../build/Unix_Makefiles-DebugAssert/swift-linux-x86_64/compile_commands.json compile_commands.json

On Linux you’ll need to install libclang, and tell Nuclide where it’s installed. Assuming you’re using Clang 3.6 to compile Swift, install libclang 3.6:

$ sudo apt-get install -y libclang-3.6-dev

Open your Nuclide preferences and set the libclang path. On Ubuntu 15.10, it’s /usr/lib/llvm-3.6/lib/libclang.so.

And that’s it!

 What alternatives are there to Nuclide?

I had been using SublimeText before. It supports CMake and Python, but doesn’t have type-aware autocompletion.

I also tried Vim. Using YouCompleteMe I was able to get type-aware autocompletion, but it was much harder to set up than Nuclide.

On OS X, I also tried Xcode. You can use the following command to generate an Xcode project for the Swift codebase:

$ utils/build-script --xcode

I normally love Xcode, but it doesn’t suit me for Swift compiler development. It doesn’t work on Linux, and it doesn’t support CMake or Python. The Swift.xcodeproj file contains a weird directory structure that looks nothing like what’s on the filesystem. Autocompletion is okay, but not as good as Nuclide’s.

If you use an editor not mentioned here, and you think I should try it out, tweet me!

Note: If you find this post on using Nuclide for compiler development useful, consider helping me write more of these posts, by supporting me on Patreon.

 
103
Kudos
 
103
Kudos

Now read this

CLANG WARN NULLABLE TO NONNULL CONVERSION

Xcode 7 includes a project setting named “Apple LLVM 7.0 - Warnings - All languages > Incorrect Uses of Nullable Values”, or CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION. You can pass it as a compiler flag using... Continue →