Adobe Alchemy

Adobe Labs has a prerelease project called Alchemy, which allows you to compile C/C++ code into SWC libraries that are usable in your AS3 code. For a former C/C++ coder like myself, this is music to my ears, but those without that background might be wondering why the hell you would even bother. Well, there’s 2 major points to consider:

  • You’ll be able to use the existing mountains of C/C++ libraries in your AS3 without having to create a port.
  • To quote the Adobe Alchemy page:  (Its) ideally suited for computation-intensive use cases, such as audio/video transcoding, data manipulation, XML parsing, cryptographic functions or physics simulation, performance can be considerably faster than ActionScript 3.0…

Now before you go getting all excited to compile your favorite C/C++ library into an SWC, there are some things to consider:

  • The more OS and other library dependencies your compiling target has, the less likely it is to work.
  • This is a prerelease labs project, so expect bugs and lots of visits to the Alchemy forums.  This should probably not be used for production code.
  • Adobe has not made it clear whether or not they plan to continue development of Alchemy, or whether it will ever be rolled into an official release.

If that hasn’t scared you off I’d highly suggest going to the Alchemy project page to get your necessary downloads and then heading immediately to the “Getting Started” page to setup up your development environment.  See if you can get their basic stringecho.c program working.  Once you have built your environment and compiled your first SWC for use in your AS3 code, it’s time to actually build your own Alchemy version of a C/C++ library.  Here’s a few examples of libraries that have been successfully ported to AS3 via Alchemy:

aalib Ascii Art in Alchemy

aalib Ascii Art in Alchemy

Box2D Physics in Alchemy

Box2D Physics in Alchemy

Now remember how I said you would inevitably run into bugs?  Yeah, that’s gonna happen, it wasn’t just a maybe.  Well, here’s a list of bugs I’ve run into so far (in attempting to port IJG’s JPEG library) and what I had to do to work around them.  And by “work around them” I mean “what people on the Alchemy forums did to work around them.”

  • adl.exe stuck

    checking whether we are cross compiling... \
    $FLEX_HOME/bin/adl.exe c:\\cygwin/tmp/t35f0.0/app.xml \
    2> /tmp/adl.trace & echo $!

    Cygwin must installed at C:\cygwin because Swfbridge, which loads AIR apps on the fly during configure scripts, is hardcoded to reference C:\cygwin.

    If you are working on a Linux system and get a similar error, make sure that you can execute your $FLEX_HOME/bin/adl file successfully. The executable for the standard Flex 3.2 SDK does not include a valid Linux ADL, only Windows and Mac. For a Linux version, download the AIR SDK for Linux and use its ADL.

  • Bad regex in achack/gcc

    Compiler] Error #1084: Syntax error: expecting identifier before \
    leftbrace., Ln 1, Col 18:
        package cmodule. {

    Change line 274 of $ALCHEMY_HOME/achacks/gcc in the following way:

    #if($o =~ /([^\.]*)/)
    if($o =~ /([^\/\.]+)(\..*)*$/)

    or just replace $ALCHEMY_HOME/achacks/gcc with this fixed version.

  • Missing

    [Compiler] Error #1063: Unable to open file: \

    Don’t compile shared libraries, only static. You can usually set this in a configure script using “–enable-shared=no –enable-static=yes”. You can also pass the “-static” option to gcc directly when compiling.

That’s the list so far, but I’m sure there’ll be more. When all else fails, be sure to check the your /tmp directory for log files. I hope its saves anyone reading this a few hours as thats how long it took me to track these all down as an Alchemy noob. If you have the brains, guts, and patience to churn out an Alchemy port of a C/C++ library, leave a comment and let me know about it. Hopefully if enough of us do some real head turning work with it Adobe will actually put some serious effort into an actual supported release. Keep your fingers crossed.

4 Responses to “Adobe Alchemy”

  1. Karthik S says:

    Hi Tony, the post is really a saver for all the novice..

  2. Karthuk,

    Glad to hear it helped. What are you up to with alchemy?

  3. Karthik S says:

    I am trying to build a ogg speex decoder. In between my adl.exe gets stuck even when my cygwin is installed in c drive.C:\cygwin. Any idea why this happens?

    This is my personal id :

  4. Nenad O says:

    I’d also like to say thanks, first time using Alchemy and it’s giving me a hard time but I’m not giving up ;)