FAQ

[Clojure] AOT compilation for library targeting multiple Clojure versions

Sam Ritchie
Dec 7, 2011 at 4:00 pm
Hey all,

I'm almost finished integration Kryo serialization into Cascalog using Alex
Miller's Carbonite library, and I'm running into a bit of a hitch with
AOT-compilation. I'm exposing the Clojure serializers to Kryo using a
namespace compiled with :gen-class:

https://github.com/sritchie/carbonite/blob/master/src/carbonite/JavaBridge.clj

and calling JavaBridge.enhanceRegistry(kryo); from my java code. The
problem is that this locks me into Clojure 1.3.0, or whatever version was
used to compile JavaBridge.

What's the recommended way to work around this and support multiple Clojure
versions? Should I build JavaBridge for 1.2 and 1.3 under different names
and query *clojure-version* from java at runtime to decide which version to
use?

Thanks all,
--
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie09

(Too brief? Here's why! http://emailcharter.org)

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
reply

Search Discussions

3 responses

  • Meikel Brandmeyer (kotarak) at Dec 7, 2011 at 4:17 pm
    Hi,

    I found the easiest approach to be a small wrapper written in Java.
    Something like this should work. Not tested, though.

    package carbonite;

    import clojure.lang.RT;
    import clojure.lang.Var;
    import com.esotericsoftware.kryo.Kryo;

    public class JavaBridge {
    static Var require = RT.var("clojure.core", "require");
    static Var symbol = RT.var("clojure.core", "symbol");

    static Var defaultReg;
    static Var regSerializers;
    static Var cljPrimitives;
    static var cljCollections;

    static {
    require.invoke(symbol.invoke("carbonite.api"));
    require.invoke(symbol.invoke("carbonite.serializer"));

    defaultReg = RT.var("carbonite.api", "default-registry");
    regSerializers = RT.var("carbonite.api", "register-serializers");
    cljPrimitives = RT.var("carbonite.serializer",
    "clojure-primitives");
    cljCollections = RT.var("carbonite.serializer",
    "clojure-collections");
    }

    static Kryo defaultRegistry() {
    return (Kryo)defaultReg.invoke();
    }

    static void enhanceRegistry(Kryo registry) {
    regSerializers.invoke(registry, cljPrimitives.deref());
    regSerializers.invoke(registry, cljCollections.invoke(registry));
    }
    }

    Sincerely
    Meikel

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Sam Ritchie at Dec 7, 2011 at 7:00 pm
    Meikel, thanks so much for this. I followed your
    advice<https://github.com/sritchie/carbonite/blob/master/src/jvm/carbonite/JavaBridge.java>and
    Cascalog and Carbonite are now working Clojures 1.2, 1.3 and 1.4 :)

    Cheers,
    Sam
    On Wed, Dec 7, 2011 at 8:17 AM, Meikel Brandmeyer (kotarak) wrote:

    Hi,

    I found the easiest approach to be a small wrapper written in Java.
    Something like this should work. Not tested, though.

    package carbonite;

    import clojure.lang.RT;
    import clojure.lang.Var;
    import com.esotericsoftware.kryo.Kryo;

    public class JavaBridge {
    static Var require = RT.var("clojure.core", "require");
    static Var symbol = RT.var("clojure.core", "symbol");

    static Var defaultReg;
    static Var regSerializers;
    static Var cljPrimitives;
    static var cljCollections;

    static {
    require.invoke(symbol.invoke("carbonite.api"));
    require.invoke(symbol.invoke("carbonite.serializer"));

    defaultReg = RT.var("carbonite.api", "default-registry");
    regSerializers = RT.var("carbonite.api", "register-serializers");
    cljPrimitives = RT.var("carbonite.serializer",
    "clojure-primitives");
    cljCollections = RT.var("carbonite.serializer",
    "clojure-collections");
    }

    static Kryo defaultRegistry() {
    return (Kryo)defaultReg.invoke();
    }

    static void enhanceRegistry(Kryo registry) {
    regSerializers.invoke(registry, cljPrimitives.deref());
    regSerializers.invoke(registry, cljCollections.invoke(registry));
    }
    }

    Sincerely
    Meikel

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with
    your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en



    --
    Sam Ritchie, Twitter Inc
    703.662.1337
    @sritchie09

    (Too brief? Here's why! http://emailcharter.org)

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Stuart Sierra at Dec 7, 2011 at 8:09 pm
    This is a well-known issue. Some workarounds and potential fixes here:
    http://dev.clojure.org/display/design/Transitive+AOT+Compilation

    -S

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en

Related Discussions

Discussion Navigation
viewthread | post