Adobe recently beta released a new project codenamed Alchemy.
Alchemy is basically a research project that allows you to compile C and C++ code to run on the Actionscript Virtual Machine (AVM2), essentially, enabling you to utilise compiled C and C++ libraries, ‘as Actionscript’, in all your web applications:
Alchemy is primarily intended to be used with C/C++ libraries that have few operating system dependencies. Ideally suited for computation-intensive use cases, such as audio/video transcoding, data manipulation, XML parsing, cryptographic functions or physics simulation.
It used to be called FlaCC, and was previewed at Adobe MAX last year. Although it’s not intended to produce complete applications, it can run up to ten times faster than Actionscript – although still slower than native C/C++ code.
The Alchemy site at Adobe Labs offers a promising ‘Getting Started’ guide with tutorials for Windows, Macintosh and Linux now that each platform – Flash Player 10, Adobe Air, the Flex SDK and the Alchemy toolkit – are all cross-platform and open source.
I decided to give it a go, working with my preferred development environment running on Ubuntu 8. However, in following the seemingly quite simple steps to compile my first library, I ran across a number holes in the guide and problems in the toolkit.
Alongside my efforts, Tim Crook tried the same on Machintosh.
Unable to get any success from Adobe’s instructions, we took following steps to get Alchemy up and (almost) running:
Set up your environment – make sure you have up-to-date versions of Java, Perl and GCC. Then download the latest Flex SDK and add the bin directory to your system path. If you’ve not done this before, you’ve basically two methods. Firstly get the path to the SDK, mine is at:
Then, to add the bin directory for the current session, execute:
Obviously change the path accordingly if yours isn’t in the same place. But you’ll have to do this with every new session you create, because the append is only temporary.
Instead, to add the path automatically you’ll need to modify your login script or bash profile – depending on your system. On Ubuntu 8, I add the above line to the end of of my bash startup file, which I find at:
There are different ways to add directories for various user types – whether for single or multiple users, for the root user etc – there’s a troubleshoot here. You can check whether either method was successful by calling:
You should see the path appended – there’ll most likely be other directories listed too. Test the path and SDK by running:
You should see output similar to:
adt version “220.127.116.1120″
Which is just your Air Developer Tool version number. You’ll need to restart the session if you’ve modified your bash script rather than modifying the path temporarily.
Then download and extract the Alchemy toolkit, again, mine is at:
Run the configuration file by navigating to the folder using the cd command and execute:
As you’ll be prompted, there’s a set-up that needs to be run every time you login. To achieve this automatically, open up the bash profile again and before the path modification add:
If you’ve followed the ‘Getting Started’ guide – it’s all the same up until now, but here’s where we begin to differ. Restart your terminal session. As far as we found, you’ve no need to modify your path any further. To check whether the set-up did run successfully, turn Alchemy on and check which GCC you are using:
You should see something along the lines of:
The Adobe instructions say you’re now ready to compile one of the sample libraries. Navigate to:
gcc stringecho.c -03 -Wall -swc -o stringecho.swc
And you should see some ouput. But I didn’t, neither did Tim – ours both die silently.
After a lot of head scratching a Googling we found a forum complaint that there are some bad symlinks in the current release of the toolkit – and we found them too. There’s two symlinks in /alchemy/bin:
llvm-g++ -> /usr/lib/alchemy/bin/llvm-gcc4-ubuntu-install/bin/llvm-g++
llvm-gcc -> /usr/lib/alchemy/bin/llvm-gcc4-ubuntu-install/bin/llvm-gcc
These go nowhere, so created new links to the correct compilers as follows:
ln -s /usr/lib/alchemy/bin/llvm-gcc4-ubuntu-install/bin/g++ llvm-g++
ln -s /usr/lib/alchemy/bin/llvm-gcc4-ubuntu-install/bin/gcc llvm-gcc
Then try again.
For Tim, success – for me, not so much.
There’s obviously something in the Linux toolkit that’s not in the Macintosh version. Amongst the output I do get though, is the following line:
cc1 error: /usr/lib/alchemy/usr/lib/alchemy/avm2-libc/avm2/AVM2Env.h
So it’s another path issue somewhere that’s causing the duplication – I’m just yet to locate it, or find a way to resolve it. I’m working on it.
This whole project could be incredible, Adobe are strongly encouraging developers to share ported libraries and support the open source ethos.
If anybody has run into the same problems as I, or even fixed them – get in touch!
Update (03.12.08): I’ve since found the fix.