diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a5f6893..76bf9bc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,30 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 strategy: - fail-fast: false + fail-fast: true steps: - uses: actions/checkout@v4 - uses: mlugg/setup-zig@v1 + - name: Prepare java + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '22' + + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@12.5 + with: + cli: latest + + - name: install tools + run: | + wget -O jextract.tar.gz https://download.java.net/java/early_access/jextract/22/5/openjdk-22-jextract+5-33_linux-x64_bin.tar.gz + tar -xvzf jextract.tar.gz + + sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libxkbcommon-dev + - name: install bake run: | git clone https://github.com/SanderMertens/bake @@ -21,41 +39,79 @@ jobs: - name: compile and jextract native modules run: | - bake --strict + bin/ci.sh + + - name: run test + run: | + bin/kaocha build-macos: runs-on: macOS-latest timeout-minutes: 30 strategy: - fail-fast: false + fail-fast: true steps: - uses: actions/checkout@v4 - uses: mlugg/setup-zig@v1 + - name: Prepare java + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '22' + + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@12.5 + with: + cli: latest + + - name: install tools + run: | + wget -O jextract.tar.gz https://download.java.net/java/early_access/jextract/22/5/openjdk-22-jextract+5-33_macos-aarch64_bin.tar.gz + tar -xvzf jextract.tar.gz + - name: install bake run: | git clone https://github.com/SanderMertens/bake make -C bake/build-$(uname) bake/bake setup - # TODO install zig - - name: compile and jextract native modules run: | bin/ci.sh + - name: run test + run: | + bin/kaocha + build-windows: runs-on: windows-latest timeout-minutes: 30 strategy: - fail-fast: false + fail-fast: true steps: - uses: actions/checkout@v4 - uses: ilammy/msvc-dev-cmd@v1 - uses: mlugg/setup-zig@v1 + - name: Prepare java + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '22' + + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@12.5 + with: + cli: latest + + - name: install tools + run: | + wget -O jextract.tar.gz https://download.java.net/java/early_access/jextract/22/5/openjdk-22-jextract+5-33_windows-x64_bin.tar.gz + tar -xvzf jextract.tar.gz + - name: install bake run: | git clone https://github.com/SanderMertens/bake @@ -65,4 +121,8 @@ jobs: ./bake setup --local - name: compile and jextract native modules - run: bake/bake --strict --cfg release + run: bin/ci.sh + + - name: run test + run: | + bin/kaocha diff --git a/bin/ci.sh b/bin/ci.sh index b67b5d53..8d1f5eba 100755 --- a/bin/ci.sh +++ b/bin/ci.sh @@ -3,4 +3,8 @@ set -ex git submodule update --init --recursive + +export VYBE_JEXTRACT=jextract-22/bin/jextract bin/jextract-libs.sh + +clojure -T:build compile-app diff --git a/bin/jextract-libs.sh b/bin/jextract-libs.sh index 8b72693b..eb27d1b7 100755 --- a/bin/jextract-libs.sh +++ b/bin/jextract-libs.sh @@ -2,14 +2,21 @@ set -ex -__VYBE_DEFAULT_GCC_ARGS="gcc -undefined dynamic_lookup" +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) VYBE_EXTENSION=so; __VYBE_DEFAULT_GCC_ARGS="gcc -undefined"; VYBE_GCC_FLECS_OPTS="-fPIC";; + Darwin*) VYBE_EXTENSION=dylib; __VYBE_DEFAULT_GCC_ARGS="gcc -undefined dynamic_lookup"; VYBE_GCC_FLECS_OPTS="";; + CYGWIN*) VYBE_EXTENSION=dll; __VYBE_DEFAULT_GCC_ARGS="gcc -undefined dynamic_lookup"; VYBE_GCC_FLECS_OPTS="";; + MINGW*) VYBE_EXTENSION=dll; __VYBE_DEFAULT_GCC_ARGS="gcc -undefined dynamic_lookup"; VYBE_GCC_FLECS_OPTS="";; + MSYS_NT*) VYBE_EXTENSION=dll; __VYBE_DEFAULT_GCC_ARGS="gcc -undefined dynamic_lookup"; VYBE_GCC_FLECS_OPTS="";; + *) VYBE_EXTENSION="UNKNOWN:${unameOut}" +esac + __VYBE_JEXTRACT_DEFAULT=~/Downloads/jextract-osx/bin/jextract VYBE_JEXTRACT="${VYBE_JEXTRACT:-$__VYBE_JEXTRACT_DEFAULT}" VYBE_GCC="${VYBE_GCC:-$__VYBE_DEFAULT_GCC_ARGS}" -VYBE_EXTENSION="${VYBE_EXTENSION:-dylib}" - rm -rf src-java/org/vybe/jolt rm -rf src-java/org/vybe/flecs rm -rf src-java/org/vybe/raylib @@ -68,7 +75,7 @@ cp flecs/flecs.h bin/ cp flecs/flecs.c bin/ $VYBE_GCC \ - -std=gnu99 -Dflecs_EXPORTS -DFLECS_NDEBUG -DFLECS_KEEP_ASSERT -DFLECS_SOFT_ASSERT \ + -std=gnu99 "$VYBE_GCC_FLECS_OPTS" -Dflecs_EXPORTS -DFLECS_NDEBUG -DFLECS_KEEP_ASSERT -DFLECS_SOFT_ASSERT \ -shared \ bin/vybe_flecs.c \ bin/flecs.c \ diff --git a/bin/kaocha b/bin/kaocha new file mode 100755 index 00000000..88599e45 --- /dev/null +++ b/bin/kaocha @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +clojure -M:dev -m vybe.native.loader && clojure -M:test "$@" diff --git a/deps.edn b/deps.edn index 1478b593..563e71d1 100644 --- a/deps.edn +++ b/deps.edn @@ -26,6 +26,11 @@ :build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.3"}} :ns-default build} + :test {:jvm-opts ["--enable-native-access=ALL-UNNAMED"] + :extra-paths ["test"] + :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}} + :main-opts ["-m" "kaocha.runner"]} + :dev {:jvm-opts ["--enable-native-access=ALL-UNNAMED" #_ "-Djdk.attach.allowAttachSelf" #_ "-XX:+UnlockDiagnosticVMOptions" diff --git a/src/vybe/flecs/impl.clj b/src/vybe/flecs/impl.clj index 10aa0895..132c8444 100644 --- a/src/vybe/flecs/impl.clj +++ b/src/vybe/flecs/impl.clj @@ -7,16 +7,16 @@ (java.lang.foreign Arena MemorySegment MemoryLayout ValueLayout FunctionDescriptor StructLayout) (jdk.internal.foreign.layout ValueLayouts) (java.lang.reflect Method Parameter) - (org.vybe.flecs flecs flecs_1 flecs_2))) + (org.vybe.flecs flecs))) (set! *warn-on-reflection* true) -(vp/-copy-resource! "libvybe_flecs.dylib") +(vp/-copy-lib! "vybe_flecs") (def ^:private declared-methods (concat (:declaredMethods (bean flecs)) - (:declaredMethods (bean flecs_1)) - (:declaredMethods (bean flecs_2)))) + (:declaredMethods (vp/-try-bean "org.vybe.flecs.flecs_1")) + (:declaredMethods (vp/-try-bean "org.vybe.flecs.flecs_2")))) (defn- ->type [^StructLayout v] diff --git a/src/vybe/jolt/impl.clj b/src/vybe/jolt/impl.clj index 3988f2cc..35ad9e07 100644 --- a/src/vybe/jolt/impl.clj +++ b/src/vybe/jolt/impl.clj @@ -7,16 +7,16 @@ (java.lang.foreign Arena MemorySegment MemoryLayout ValueLayout FunctionDescriptor StructLayout) (jdk.internal.foreign.layout ValueLayouts) (java.lang.reflect Method Parameter) - (org.vybe.jolt jolt jolt_1))) + (org.vybe.jolt jolt))) (set! *warn-on-reflection* true) -(vp/-copy-resource! "libjoltc_zig.dylib") -(vp/-copy-resource! "libvybe_jolt.dylib") +(vp/-copy-lib! "joltc_zig") +(vp/-copy-lib! "vybe_jolt") (def ^:private declared-methods (concat (:declaredMethods (bean jolt)) - (:declaredMethods (bean jolt_1)))) + (:declaredMethods (vp/-try-bean "org.vybe.jolt.jolt_1")))) (defn- ->type [^StructLayout v] diff --git a/src/vybe/panama.clj b/src/vybe/panama.clj index b9bd1643..8c308350 100644 --- a/src/vybe/panama.clj +++ b/src/vybe/panama.clj @@ -17,10 +17,21 @@ (defn -copy-resource! [resource-filename] - (let [resource-file (io/resource resource-filename) - tmp-file (io/file "/tmp/pfeodrippe_vybe_native" resource-filename)] - (io/make-parents tmp-file) - (with-open [in (io/input-stream resource-file)] (io/copy in tmp-file)))) + (if-let [resource-file (io/resource resource-filename)] + (let [tmp-file (io/file "/tmp/pfeodrippe_vybe_native" resource-filename)] + (io/make-parents tmp-file) + (with-open [in (io/input-stream resource-file)] (io/copy in tmp-file))) + (throw (ex-info "Resource does not exist" {:resource resource-filename})))) + +(defn -copy-lib! + [lib-name] + (-copy-resource! (System/mapLibraryName lib-name))) + +(defn -try-bean + [s] + (try + (bean (Class/forName s)) + (catch Exception _))) (defonce ^Arena arena-root (Arena/ofAuto) diff --git a/src/vybe/raylib.clj b/src/vybe/raylib.clj index fd91f684..2294b12f 100644 --- a/src/vybe/raylib.clj +++ b/src/vybe/raylib.clj @@ -60,15 +60,6 @@ v))} (org.vybe.raylib.Color/layout)) -;; Start server as we need to be on the main thread, see -;; https://medium.com/@kadirmalak/interactive-opengl-development-with-clojure-and-lwjgl-2066e9e48b52 -(defonce server - (let [port (or (System/getenv "VYBE_NREPL_PORT") 7888)] - (try - (start-server :port port :handler cider-nrepl-handler) - (finally - (println :nrepl-connection :port port))))) - (defmacro t "Runs command (delayed) in the main thread. @@ -168,6 +159,13 @@ (defn -main [] + ;; Start server as we need to be on the main thread, see + ;; https://medium.com/@kadirmalak/interactive-opengl-development-with-clojure-and-lwjgl-2066e9e48b52 + (let [port (or (System/getenv "VYBE_NREPL_PORT") 7888)] + (try + (start-server :port port :handler cider-nrepl-handler) + (finally + (println :nrepl-connection :port port)))) (while (empty? (:buf-general @vr.impl/*state)) (Thread/sleep 30)) diff --git a/src/vybe/raylib/impl.clj b/src/vybe/raylib/impl.clj index ff28e141..8b9434c7 100644 --- a/src/vybe/raylib/impl.clj +++ b/src/vybe/raylib/impl.clj @@ -5,15 +5,15 @@ [clojure.java.shell :as sh] [vybe.panama :as vp]) (:import - (org.vybe.raylib raylib raylib_1 Color) + (org.vybe.raylib raylib Color) (java.lang.foreign Arena MemorySegment MemoryLayout ValueLayout FunctionDescriptor StructLayout) (jdk.internal.foreign.layout ValueLayouts) (java.lang.reflect Method Parameter))) (set! *warn-on-reflection* true) -(vp/-copy-resource! "libraylib.dylib") -(vp/-copy-resource! "libvybe_raylib.dylib") +(vp/-copy-lib! "raylib") +(vp/-copy-lib! "vybe_raylib") ;; Compile to OSX #_(def lib-name @@ -53,7 +53,7 @@ (def ^:private declared-methods (concat (:declaredMethods (bean raylib)) - (:declaredMethods (bean raylib_1)))) + (:declaredMethods (vp/-try-bean "org.vybe.raylib.raylib_1")))) (defn- ->type [^StructLayout v] @@ -110,7 +110,7 @@ [] (->> declared-methods (filter #(str/includes? (.getName ^Method %) "$descriptor")) - #_(filter #(= (.getName %) "GetMonitorName$descriptor")) + (remove #(str/starts-with? (.getName ^Method %) "__")) #_(take 10) (pmap (fn [^Method method] (let [^FunctionDescriptor desc (.invoke method nil (into-array Object [])) diff --git a/tests.edn b/tests.edn new file mode 100644 index 00000000..9d8d845c --- /dev/null +++ b/tests.edn @@ -0,0 +1 @@ +#kaocha/v1 {}