Xcode 5 custom compiler

January 15, 2014

Chrome 32 ships with PNaCl enabled by default. It has begun.

Ok but what to do if You want to jump into deep water and port an SDK consisting of quite large C/C++ codebase to PNaCl ( everybody understand that the possibility to run native code with almost native performance directly in the browser is cool )? Which tools to use?

I started with QMake. I thought it would be easy. Create new MkSpec, set paths to pnacl-clang and that is it. Well it is not that easy, but possible.

For some reason, though, I am not really into makefiles. These days i would expect that a click on the error or warning  generated by the compiler taking me  directly on the line of source code that caused problem (or at least compiler thinks so). Wait a second… Our SDK is already ported to iOS. And we have nice Xcode project and C++ unit test, all running. And Xcode used to support GCC side by side with LLVM compiler. Maybe there is a way to tweak Xcode and add custom compiler that would compile PNaCl code in Xcode?

First i looked around and found a few attempts (Erlang Xcode plugin, C# Mono plugin). I did not realize that these plug-ins stopped development in Xcode 3.0 stage. Nevertheless i tried. First by copying : 

/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/Clang LLVM 1.0.xcplugin

to 

/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/PNaCl.xcplugin

and renaming compiler specification file Contents/Resources/Clang LLVM 1.0.xcspec to PNaCl.xcspec and then modifying ExecPath to point to pnacl-clang (and also Identifier, and a few others) after rerunning Xcode (actually there were few other steps involved)   – voila, the PNaCL compiler appear on the list of the compilers in Xcode. So I copied one of the existing targets in the SDK project, named it SDK-PNaCl and clicked Build. The actual pnacl-clang command was run, but it failed because of -F option which was not understood. After a few hours of searching and thinking i decided that there is no way to override this behavior just by modifying the xcspec, while the class is still XCCompilerSpecificationClang.

I needed a custom class. I tried to copy the implementation of compiler specification from Erlang Xcode plugin’ but the method 

-computeDependenciesForInputFile:ofType:variant:architecture:outputDirectory:inTargetBuildContext:

was not called no matter what i did. After some time i realized that in Xcode 4+ this method has changed to: 

- computeDependenciesForInputNodes:ofType:variant:architecture:outputDirectory:withMacroExpansionScope:

But, wtf? I was able to link to /Applications/Xcode.app/Contents/OtherFrameworks/DevToolsCore.framework so there must be another version of this framework. A quick search under /Application/Xcode.app revealed that there is another set of frameworks, for Xcode 5, namely here: 

/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework

which were correct for Xcode 5. I used class dump to generate headers out of the binary versions of framework. Class dump is an awesome tool but it has some flaw which means that generated headers need to be manually fixed. One of them is that it tries to include “NSObject.h” where it should include <Foundation/Foundation.h>. 

Having obtained the correct header i tried to go through them and try to understand but this will take me another i don’t know how many sleepless hours. Currently i am able to compile a file into an object file but i am not sure how to substitute the linker/librarian. 

Open questions. Just a few: 

  1. How to substitute linker/librarian? Does product node play a role in this process? Does a file type play a role? 
  2. How to set output file type of the node of the C/C++ file node to newly created pnacl-o, as opposed to mach-o?
  3. How to get rid of unnecessary Build options?
  4. Would it be beneficial to define PNaCl.platform as a platform, and each of  pepper_32, pepper_30, pepper_canary as their SDK? Is it possible?
  5. Very naive: is there a documentation pointing out the Xcode build process, role of specifications, etc?

UPDATE:Added references with very important link. I should have read it thoroughly earlier since it might have a solution for the linker thing ready.
References:

Juniper Network Connect won’t connect on MacOS X.

June 17, 2013

If You came across problem with Juniper Network Connect not connecting to VPN on MacOS then You might try this. In my case this was not enough. Every time i update Safari by autoupdate it  stops working again (this happened to me when updating from  6.0.3 to 6.0.4 and to 6.0.5) for no reason. If it happened to You as well You might go to java test plugin site and click on the plugin. For unknown reasons this reenabled my Juniper Network Connect to connect. 

Please note that this problems might have been fixed in newer version of Juniper Network Connect but our network administrators can’t be bother to update. 

I am using 10.7 Lion, Safari 6.0.5, Java 1.7 Update 21. 

Application Unit Testing from command line on iPhoneSimulator.

June 6, 2013

It’s hard to tell the reasons behind not supporting application-hosted tests on IPhoneSimulator and the infamous warning message:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests:81: warning: Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set).

But people need to do this and there are solutions to this problem on the Internet, especially here. The solution seem to work in Xcode 4.5 but things seem to be changed slightly in Xcode 4.6 (4.6.2).

In version 4.6.2 script :

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/
Tools/RunPlatformUnitTests

seems to have bash script method RunTestForApplication redefined:

### Simulator app testing isn't supported, so redefine RunTestsForApplication.
RunTestsForApplication() {
Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."
}

So in addition to the solution linked above this method needs to be commented out in this file. Also please make sure that You somehow append -RegisterForSystemEvents flag to the test command run. You can do this either in a way described in the cited article or by adding the following line:

export OTHER_TEST_FLAGS=-RegisterForSystemEvents

after line 124 of
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests,
otherwise You will end up with the following error:

Couldn't open shared capabilities memory GSCapabilities (No such file or directory)
Couldn't open shared capabilities memory GSCapabilities (No such file or directory)
Couldn't open shared capabilities memory GSCapabilities (No such file or directory)
Terminating since there is no system event server.
(Run the EventPump or pass the argument "-RegisterForSystemEvents" if you want to run without SpringBoard.

Inception

June 4, 2013

Today I made my first move to have a blog. I plan to write about the stuff I do. Because I am a computer geek there might be something technical stuff. Because I like fishing, there might be some fishing stories as well.

There were a few reasons to do start a blog:

  1. I recently tried to solve a problem at my work and could not find a solution. I spent some time trying to solve and I think I would like to share what I have done.
  2. To promote myself. There are some companies and some jobs that require You to have a solid fingerprint in the Internet.
  3. Improve my writing in English skills. Since English is not my first language (I love this euphemism, used by natives in situations where my English really didn’t shine) it would be nice to exercise it a bit. Feel free to correct me (although spell checker does a good job, I believe).

I hope this blog will thrive and will be updated from time to time and that I will have motivation to do something more than putting under construction sign. This happens to too many sites, expressing short lived zeal.

It would be nice to have a commitment at this point. Ok. I will write a subpage introducing myself ( can’t promise it will be interesting ) and I will present a solution on how to integrate unit tests that use CPPUnit framework in Xcode (SenTesting framework).


Follow

Get every new post delivered to your Inbox.