From 95155c16d0b7ebfe5d74afe9b531774f4c602769 Mon Sep 17 00:00:00 2001 From: Paulo Feodrippe Date: Sun, 21 Jul 2024 21:11:28 -0400 Subject: [PATCH] wip2 --- .github/workflows/ci.yml | 74 ++++++++++++++++++++++++++++++++++++---- bin/ci.sh | 4 +++ bin/jextract-libs.sh | 15 +++++--- bin/kaocha | 3 ++ deps.edn | 5 +++ src/vybe/flecs/impl.clj | 14 +++++--- src/vybe/jolt/impl.clj | 4 +-- src/vybe/panama.clj | 13 ++++--- src/vybe/raylib.clj | 16 ++++----- src/vybe/raylib/impl.clj | 4 +-- tests.edn | 1 + 11 files changed, 121 insertions(+), 32 deletions(-) create mode 100755 bin/kaocha create mode 100644 tests.edn 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..9129d374 --- /dev/null +++ b/bin/kaocha @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +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..ab166f5b 100644 --- a/src/vybe/flecs/impl.clj +++ b/src/vybe/flecs/impl.clj @@ -7,16 +7,22 @@ (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") + +(defn- try-bean + [s] + (try + (bean (Class/forName s)) + (catch Exception _))) (def ^:private declared-methods (concat (:declaredMethods (bean flecs)) - (:declaredMethods (bean flecs_1)) - (:declaredMethods (bean flecs_2)))) + (:declaredMethods (try-bean "org.vybe.flecs.flecs_1")) + (:declaredMethods (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..904a0309 100644 --- a/src/vybe/jolt/impl.clj +++ b/src/vybe/jolt/impl.clj @@ -11,8 +11,8 @@ (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)) diff --git a/src/vybe/panama.clj b/src/vybe/panama.clj index b9bd1643..56fa9e7b 100644 --- a/src/vybe/panama.clj +++ b/src/vybe/panama.clj @@ -17,10 +17,15 @@ (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))) (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..500c492a 100644 --- a/src/vybe/raylib/impl.clj +++ b/src/vybe/raylib/impl.clj @@ -12,8 +12,8 @@ (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 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 {}