graalvm

Discuss GraalVM related topics. Use clojure 1.10.2 or newer for all new projects. Contribute to https://github.com/clj-easy/graal-docs and https://github.com/BrunoBonacci/graalvm-clojure. GraalVM slack: https://www.graalvm.org/slack-invitation/.
2021-04-10T07:35:27.075400Z

Hey all. I’m trying to use test.check/generators in GraalVM and am getting the following error:

Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/test/check/generators__init.class, clojure/test/check/generators.clj or clojure/test/check/generators.cljc on classpath.
The demo app is very simple:
(ns test-check.main
  (:require
    [clojure.spec.alpha :as s]
    [clojure.spec.gen.alpha :as gen])
  (:gen-class))

(defn -main []
  (println "Hello test.check")
  (println (gen/generate (s/gen int?)))
  (println (gen/generate (s/gen nil?)))
  (println (gen/sample (s/gen string?)))
  (println (gen/sample (s/gen #{:club :diamond :heart :spade})))
  (println (gen/sample (s/gen (s/cat :k keyword? :ns (s/+ number?))))))
With the following in the project.clj
(defproject test-check "0.1.0-SNAPSHOT"

  :dependencies [[org.clojure/clojure "1.10.3"]
                 [org.clojure/test.check "1.1.0"]]

  :main test-check.main

  :profiles {:uberjar {:aot :all}
             :dev {:plugins [[lein-shell "0.5.0"]]}}

  :aliases
  {"native"
   ["shell"
    "native-image"
    "--no-fallback"
    "--no-server"
    "--report-unsupported-elements-at-runtime"
    "--initialize-at-build-time"
    "-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
    "-H:Name=./target/${:name}"]

   "run-native" ["shell" "./target/${:name}"]}) 
As a sanity check, I do have other successful native-image builds going, but am getting hung up on this one… Any advice?

borkdude 2021-04-10T07:45:32.075700Z

@campeterson > and am getting the following error when?

borkdude 2021-04-10T07:46:44.076200Z

@campeterson fwiw, clojure.test.check is also bundled with babashka and compiled with lein so you could look at that project

2021-04-10T07:48:31.076600Z

Sorry, getting that error when run the executable I built w/ native-image

2021-04-10T07:49:21.077300Z

It builds successfully, but when I run the output, that’s where it chokes

2021-04-10T07:50:03.078Z

@borkdude I’ll take a look at babashka.

borkdude 2021-04-10T07:53:32.078900Z

there is also a fix for the randomizer which doesn't work out of the box with graalvm native-image. I logged an issue about this in test.check

2021-04-10T07:54:10.079400Z

Yes, I saw your issue. Was double checking I was using the same flags

borkdude 2021-04-10T07:58:29.079800Z

I think you might need to require the clojure.test.check namespaces at compile time

2021-04-10T08:02:31.080800Z

That did it! source now looks like this:

(ns test-check.main
  (:require
    [clojure.spec.alpha :as s]
    #_[clojure.spec.gen.alpha :as gen]
    )
  (:gen-class))

(require '[clojure.test.check.generators :as gen])

(defn -main []
  (println "Hello test.check")
  (println (gen/generate (s/gen int?)))
  (println (gen/generate (s/gen nil?)))
  (println (gen/sample (s/gen string?)))
  (println (gen/sample (s/gen #{:club :diamond :heart :spade})))
  (println (gen/sample (s/gen (s/cat :k keyword? :ns (s/+ number?))))))

2021-04-10T08:02:55.081300Z

Compiles fine and now the executable runs

borkdude 2021-04-10T08:03:08.081600Z

But do you get random samples every new run?

2021-04-10T08:04:07.082500Z

Nope. Same samples each run

borkdude 2021-04-10T08:05:09.082900Z

A workaround can be found in the link I posted earlier

👍 1
2021-04-10T08:07:23.083500Z

Thanks @borkdude this is all great stuff. I appreciate the help

2021-04-10T08:08:24.084200Z

(We love bb at work, by the way. Your open source contributions are stellar)

❤️ 1
2021-04-10T08:30:33.085Z

P.S. I added these lines in and it works as you said https://github.com/babashka/babashka/blob/master/feature-test-check/babashka/impl/clojure/test/check.clj#L6-L27

👍 1