From 11e09f477480531487cd12b5c107ac1d8352a7a5 Mon Sep 17 00:00:00 2001 From: Joel Stålnacke Date: Sun, 6 Oct 2024 11:25:49 +0300 Subject: Initial commit --- .gitignore | 5 ++++ Djup/Djup.csproj | 16 ++++++++++++ Djup/Program.cs | 2 ++ doc/collision-model.ggb | Bin 0 -> 111985 bytes lib/.gitignore | 1 + lib/Djup.Native/.gitignore | 2 ++ lib/Djup.Native/Djup.Native.csproj | 27 +++++++++++++++++++ lib/Djup.Native/LibDjup.cs | 12 +++++++++ lib/Djup.Native/Program.cs | 2 ++ lib/build.sh | 52 +++++++++++++++++++++++++++++++++++++ lib/test.c | 9 +++++++ lib/types.h | 4 +++ 12 files changed, 132 insertions(+) create mode 100644 .gitignore create mode 100644 Djup/Djup.csproj create mode 100644 Djup/Program.cs create mode 100644 doc/collision-model.ggb create mode 100644 lib/.gitignore create mode 100644 lib/Djup.Native/.gitignore create mode 100644 lib/Djup.Native/Djup.Native.csproj create mode 100644 lib/Djup.Native/LibDjup.cs create mode 100644 lib/Djup.Native/Program.cs create mode 100755 lib/build.sh create mode 100644 lib/test.c create mode 100644 lib/types.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1955e4a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build/ +bin/ +obj/ + +core diff --git a/Djup/Djup.csproj b/Djup/Djup.csproj new file mode 100644 index 0000000..3c18b7c --- /dev/null +++ b/Djup/Djup.csproj @@ -0,0 +1,16 @@ + + + + + + + + + + Exe + net8.0 + enable + enable + + + diff --git a/Djup/Program.cs b/Djup/Program.cs new file mode 100644 index 0000000..c66eb42 --- /dev/null +++ b/Djup/Program.cs @@ -0,0 +1,2 @@ +using Djup.Native; +LibDjup.hello_world(); diff --git a/doc/collision-model.ggb b/doc/collision-model.ggb new file mode 100644 index 0000000..3548fdb Binary files /dev/null and b/doc/collision-model.ggb differ diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/lib/Djup.Native/.gitignore b/lib/Djup.Native/.gitignore new file mode 100644 index 0000000..c6e49ef --- /dev/null +++ b/lib/Djup.Native/.gitignore @@ -0,0 +1,2 @@ +obj/ +bin/ diff --git a/lib/Djup.Native/Djup.Native.csproj b/lib/Djup.Native/Djup.Native.csproj new file mode 100644 index 0000000..7184efb --- /dev/null +++ b/lib/Djup.Native/Djup.Native.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + + enable + enable + true + + + + runtimes/linux-x64/native/libdjup.so + PreserveNewest + runtimes/linux-x64/native/ + true + + + + + PreserveNewest + + + + + + + diff --git a/lib/Djup.Native/LibDjup.cs b/lib/Djup.Native/LibDjup.cs new file mode 100644 index 0000000..5e6db83 --- /dev/null +++ b/lib/Djup.Native/LibDjup.cs @@ -0,0 +1,12 @@ +using System.Runtime.InteropServices; + +namespace Djup.Native; + +public static partial class LibDjup +{ + const string LibraryName = "djup"; + const string Prefix = "dp_"; + + [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(hello_world))] + public static partial void hello_world(); +} diff --git a/lib/Djup.Native/Program.cs b/lib/Djup.Native/Program.cs new file mode 100644 index 0000000..2667048 --- /dev/null +++ b/lib/Djup.Native/Program.cs @@ -0,0 +1,2 @@ +/*using Djup.Native;*/ +/*LibDjup.hello_world();*/ diff --git a/lib/build.sh b/lib/build.sh new file mode 100755 index 0000000..f506120 --- /dev/null +++ b/lib/build.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +fail() { + echo "$0: $*" >&2 + exit 1 +} + +CC=cc +CFLAGS="-std=c99 -Wall -Wextra -Wpedantic -D_POSIX_C_SOURCE=200809L" +LDFLAGS="-fPIC" +SOURCES="test.c" +output="build" + +for arg ; do + case "$arg" in + --runtime=*) + runtime="${arg#*=}" + ;; + --output=*) + output="${arg#*=}" + ;; + *) + echo "usage" + ;; + esac +done + +if [ -z "$runtime" ]; then + echo "Guessing runtime ..." + + case "$(uname -s)" in + Linux) + case "$(uname -m)" in + x86_64) + runtime="linux-x64" + ;; + esac + ;; + esac +fi + +case "$runtime" in + linux-x64) + sofile="libdjup.so" + ;; + *) + fail "Unsupported runtime $runtime" +esac + +echo Building for runtime "$runtime ..." +mkdir -p "$output/runtimes/$runtime/native" && $CC $CFLAGS $SOURCES -shared $LDFLAGS -o "$output/runtimes/$runtime/native/$sofile" +echo Done diff --git a/lib/test.c b/lib/test.c new file mode 100644 index 0000000..78a0d02 --- /dev/null +++ b/lib/test.c @@ -0,0 +1,9 @@ +#include + +#include "types.h" + +void +dp_hello_world() +{ + printf("Hello World\n"); +} diff --git a/lib/types.h b/lib/types.h new file mode 100644 index 0000000..afffd4f --- /dev/null +++ b/lib/types.h @@ -0,0 +1,4 @@ +typedef struct { + float x; + float y; +} vec2; -- cgit v1.2.3