{ Notes }


Using Xcode to develop on your remote Linux systems

Posted on | Development linux


Linux Linux Operating System (OS) is universally considered best OS in regards to programming. Similarly Mac OS X with a beautiful Graphical User Interface (GUI) along with decent development tools hovering on powerful Unix kernel is perhaps a good choice as well. Imagine if you could develop your Linux based softwares from your Mac by utilising its development tools. If you have such kind of requirement this post elaborates to make this functionality work seamlessly.

I develop applications on the Linux environment, which are primarily targeted to run on workstations and HPC (High Performance Computing) Clusters. My development workstation and HPC cluster runs Ubuntu 12.04 LTS and Ubuntu Server 10.4 respectively. I switch between these two machines, which involves lots of “SSH’ing” (connection over Secure Shell). Access to the HPC cluster is only possible through SSH, and while telecommuting I connect to my workstation over SSH. Moreover this involves exploiting my favourite text editor VIM, which is an instant solution for remote file manipulation and default choice as well. I develop in languages such as C++, OpenCL, CUDA, MPI and CMake; in fact I write lot of code comprising several different files. I can achieve this by opening multiple terminals or using TMUX followed by “vsplit” command in VIM (which I was actually doing). I desired something where my code files are instantly accessible with all features of file and string manipulation. An IDE (Integrated Development Environment) seems an optimum solution for the problem.

Apparently Mac OS has its own good native IDE: Xcode, which I will be using to satisfy my requirement. I was using a similar technique with Eclipse Juno on Ubuntu, which worked seamlessly. However ever since I moved to Mac I was looking for similar kind of solution. Initially I tried Eclipse Juno but that was too slow in this context, Secondly I tried with Xcode, which proved optimal. however one can use any preferable IDE; in my case mine this is Xcode.
Alright then, I am going to use the Xcode IDE on MBA to develop code that is present on another desktop or server, and is accessible through SSH. In fact Xcode will see the code as it’s native on same machine.

Note: Please be informed this setup requires a decent Internet connection while connecting remotely. In my case I reside approximately 2 km away from work and my workstation and the HPC cluster resides on site at work. Perhaps this solution would be inappropriate for long distance connection or slower bandwidth Internet.

Requirements:

  • SSHFS – a file system client, which will be used to mount remote folders using SSH on your Mac.
  • FUSE – required by SSHFS to mount file system.
  • Xcode on your Mac

Accessing remote files on your Mac

To mount remote folders you would need SSHFS installed. If you need help installing SSHFS please refer to the SSHFS website: they have a good installation guide for SSHFS and FUSE. Assuming you have SSHFS  installed, you can run the command below:
sshfs username@remoteserver:path-to-remote-directory path-to-local-directory

However using the above approach requires the access password to the machine therefore it is recommended to provide access to the remote machine using a private/public key to avoid typing a password every time one tries to mount. If you are not familiar with configuring SSH access without password this is good article to help you out. I also prefer to provide remote connections with user-friendly names. In which case my SSHFS line will be like the snippet in code block below. It is more convenient to store your SSHFS details inside a script file so that you can just run script file to mount the directories.
sshfs officepc:openmm ~/OpenMM
Eventually on executing the script if SSHFS access is granted you should see your local mount folder name replaced by “OSXFUSE volume 0” prefixed by an eject icon. You can click on this eject image in-order to un-mount the remote directory on your local machine.

Setup Xcode

Now you should view remote files and folders on your Mac so it’s virtually like your own native files and folders unless the SSHFS volume is not mounted. Subsequently you can configure Xcode by adding a new project and further adding files to the project. However when you add files and folder to project you should add “OSXFUSE volume 0”. Further you should see your remote code files and folders listed in the left pane of your Xcode window.

Building you code

By now you should see all your code files on your Xcode interface. You are now ready to edit code but you also have to build that code on remote system. You can achieve this by executing a bash script remotely by adding bash commands inside Xcode. Follow the steps below inside Xcode: 1. Assuming your project is open inside Xcode, click on Product -> Edit Scheme or alternatively press Command + Option + < on your keyboard. 2. You shall see a pop-up window, enlarge the build section on top-left corner and then select pre-actions. Click on ‘+’ followed by new run action. 3. In the shell text box type “/bin/bash” 4. In the script box you can drag a script file or add bash commands. 5. Inside the script box the script will be a combination of your SSH URI and your commands to execute. These commands are similar to what you use to compile your code including changing directory. In my case I use CMake to compile my code, in which case the script is ssh officepc “cd openmm/build4.1; make && make install;”
6. Eventually you can simply press ‘command + b’ and build you code on your remote machine.

Desktop

Conclusion

This technique has proved productive for me, now I can now develop with a good UI, which helps in good code indentation and file manipulation as well. Essentially there is elimination of multiple terminal windows with easier file traversal and text manipulation. Moreover it proved so optimal that, I have been using my development Workstation from my laptop with an external 27” display.

Further Work

I am able to build the code write from Xcode IDE but I can’t view build output therefore I need to find a way to see the build output inside output window. There is another tool called Vagrant which solves similar kind of problem but its moreover intended while dealing with Virtual Machines my further work is to investigate Vagrant in this context.