Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeodrippe committed Jul 22, 2024
1 parent 4f126a8 commit 890cdbd
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 37 deletions.
74 changes: 67 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
Expand All @@ -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/[email protected]
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/[email protected]
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
Expand All @@ -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
4 changes: 4 additions & 0 deletions bin/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 11 additions & 4 deletions bin/jextract-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions bin/kaocha
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

clojure -M:dev -m vybe.native.loader && clojure -M:test "$@"
5 changes: 5 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/vybe/flecs/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/vybe/jolt/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 15 additions & 4 deletions src/vybe/panama.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions src/vybe/raylib.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions src/vybe/raylib/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 []))
Expand Down
1 change: 1 addition & 0 deletions tests.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#kaocha/v1 {}

0 comments on commit 890cdbd

Please sign in to comment.