Add raylib
Some checks failed
release / linux/aarch64 (pull_request) Failing after 1m7s
release / linux/armv7 (pull_request) Failing after 1m13s
release / linux/i686 (pull_request) Failing after 1m0s
release / linux/x86_64 (pull_request) Failing after 56s
release / android (pull_request) Successful in 2m46s
release / freebsd/x86_64 (pull_request) Failing after 4m56s
release / windows/i686 (pull_request) Failing after 2m19s
release / windows/x86_64 (pull_request) Failing after 2m14s

This commit is contained in:
pedro-bento 2026-10-22 19:49:43 +01:00
parent 9bf4155970
commit b893cd4dbf
12 changed files with 12718 additions and 187 deletions

View file

@ -1,11 +1,8 @@
#!/bin/sh
# Build hate-no-d inside a FreeBSD VM and copy the binary and the static
# library back.
# Build hate-no-d inside a FreeBSD VM and copy the binary back.
#
# freebsd-build.sh <output-file> [source-dir]
#
# The archive lands next to <output-file> as libhate-no-d.a.
#
# Needs qemu-system-x86, cloud-image-utils, openssh-client, xz and curl, plus
# /dev/kvm (act_runner: options: "--device /dev/kvm"); under TCG the boot takes
# many minutes. The guest runs with -snapshot, so nothing persists.
@ -24,9 +21,6 @@ fi
OUT_DIR=$(dirname "$1")
mkdir -p "$OUT_DIR"
OUT=$(cd "$OUT_DIR" && pwd)/$(basename "$1")
# Absolute: the script cd's into $WORK below, so a relative path would land there
# instead of next to $OUT.
LIB_OUT=$(dirname "$OUT")/libhate-no-d.a
SRC=$(cd "${2:-.}" && pwd)
WORK="${FBSD_WORK:-${TMPDIR:-/tmp}/fbsd-ci}"
@ -116,12 +110,12 @@ log "guest up after ~$((i * 2))s: $(ssh_vm 'uname -sr')"
# --- build -------------------------------------------------------------------
log "installing gmake in guest"
ssh_vm 'set -e; env ASSUME_ALWAYS_YES=yes pkg install -y gmake >/dev/null 2>&1; gmake --version | head -1'
ssh_vm 'set -e; env ASSUME_ALWAYS_YES=yes pkg install -y gmake luajit >/dev/null 2>&1; gmake --version | head -1'
log "transferring source"
tar czf "$WORK/src.tar.gz" -C "$SRC" \
--exclude=.git --exclude=.build --exclude=hate-no-d \
--exclude='*.o' --exclude='*.a' --exclude='*.so' .
--exclude=.git --exclude=.build --exclude=build --exclude=hate-no-d \
--exclude=hate-no-d.lua --exclude='*.o' --exclude='*.a' --exclude='*.so' .
scp $SCP_OPTS "$WORK/src.tar.gz" "root@127.0.0.1:/root/src.tar.gz"
# FreeBSD has no gcc: CC must be on the command line to reach the sub-make.
@ -131,11 +125,10 @@ ssh_vm 'set -e
tar xzf /root/src.tar.gz -C /root/src
cd /root/src
gmake CC=cc clean >/dev/null 2>&1 || true
gmake CC=cc all lib'
gmake CC=cc all'
log "fetching artifacts"
log "fetching artifact"
scp $SCP_OPTS "root@127.0.0.1:/root/src/hate-no-d" "$OUT"
scp $SCP_OPTS "root@127.0.0.1:/root/src/libhate-no-d.a" "$LIB_OUT"
scp $SCP_OPTS "root@127.0.0.1:/root/src/hate-no-d.lua" "$OUT_DIR/hate-no-d.lua"
log "built $OUT ($(wc -c < "$OUT") bytes)"
log "built $LIB_OUT ($(wc -c < "$LIB_OUT") bytes)"

View file

@ -1,7 +1,7 @@
# Apple targets (macOS + iOS), kept out of release.yml: they need a `macos`
# runner. Gating them there with `if: vars.*` does not work -- Forgejo does not
# evaluate `vars` in `if:`, so the jobs queued forever and the run never
# finished. Manual dispatch only, until a Mac runner exists.
# macOS, kept out of release.yml: it needs a `macos` runner. Gating it there
# with `if: vars.*` does not work -- Forgejo does not evaluate `vars` in `if:`,
# so the job queued forever and the run never finished. Manual dispatch only,
# until a Mac runner exists.
name: apple
on:
@ -40,12 +40,15 @@ jobs:
- name: Fetch submodules
run: git submodule update --init --recursive
- name: Install LuaJIT
run: brew install luajit
- name: Build
run: |
make \
CFLAGS="-O2 -Wall -arch ${{ matrix.arch }}" \
LUAJIT_EXTRA="TARGET_FLAGS=-arch ${{ matrix.arch }}" \
all lib
all
- name: Verify architecture
run: |
@ -56,42 +59,8 @@ jobs:
- name: Package
run: |
sh .forgejo/scripts/make-archive.sh "hate-no-d-macos-${{ matrix.arch }}" tar.gz \
./hate-no-d ./libhate-no-d.a
./hate-no-d ./hate-no-d.lua
- name: Attach to release
if: github.event.inputs.tag != ''
run: sh .forgejo/scripts/release-asset.sh "./hate-no-d-macos-${{ matrix.arch }}.tar.gz"
# ---------------------------------------------------------------------------
# iOS. Builds only the archive (JIT compiled out) for an Xcode app target.
# ---------------------------------------------------------------------------
ios:
name: ios/arm64
runs-on: macos
steps:
- name: Checkout
uses: https://data.forgejo.org/actions/checkout@v4
with:
submodules: false
- name: Fetch submodules
run: git submodule update --init --recursive
- name: Build static library
run: make PLATFORM=iOS IOS_ARCH=arm64 all lib
- name: Verify archive
run: |
set -eu
# libhate-no-d.a is what ships; it must be single-arch arm64 Mach-O.
lipo -info ./libhate-no-d.a
lipo -info ./libhate-no-d.a | grep -q arm64
- name: Package
# Only a static archive ships here: iOS forbids JIT, so libhate-no-d.a is
# the deliverable to link into an Xcode target. There is no binary.
run: sh .forgejo/scripts/make-archive.sh hate-no-d-ios-arm64 tar.gz ./libhate-no-d.a
- name: Attach to release
if: github.event.inputs.tag != ''
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d-ios-arm64.tar.gz

View file

@ -7,7 +7,7 @@
# Windows), each unpacking to a directory of the same name holding the binary
# plus LICENSE and README.md. Release attachments are a flat list with no
# folders, so the archive is what groups a target's files together.
# macOS/iOS live in apple.yml; everything here builds on the Linux runner.
# macOS lives in apple.yml; everything here builds on the Linux runner.
name: release
on:
@ -87,10 +87,10 @@ jobs:
fi
apt-get update -qq
apt-get install -y --no-install-recommends \
make gcc libc6-dev binutils jq curl ca-certificates ${{ matrix.packages }}
make gcc libc6-dev binutils jq curl ca-certificates luajit ${{ matrix.packages }}
- name: Build
run: make ${{ matrix.make_args }} all lib
run: make ${{ matrix.make_args }} all
# A mis-set CC silently yields a host binary, so check the ELF machine.
- name: Verify architecture
@ -100,7 +100,7 @@ jobs:
echo "architecture ok: ${{ matrix.machine }}"
- name: Package
run: sh .forgejo/scripts/make-archive.sh "hate-no-d-linux-${{ matrix.arch }}" tar.gz ./hate-no-d ./libhate-no-d.a
run: sh .forgejo/scripts/make-archive.sh "hate-no-d-linux-${{ matrix.arch }}" tar.gz ./hate-no-d ./hate-no-d.lua
- name: Attach to release
if: startsWith(github.ref, 'refs/tags/')
@ -134,7 +134,7 @@ jobs:
set -eu
apt-get update -qq
apt-get install -y --no-install-recommends \
make gcc libc6-dev binutils jq curl ca-certificates unzip \
make gcc libc6-dev binutils jq curl ca-certificates unzip luajit \
gcc-multilib libc6-dev-i386
- name: Install NDK r27c
@ -155,15 +155,14 @@ jobs:
make clean >/dev/null 2>&1 || true
if [ "$abi" = armeabi-v7a ]; then
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all lib
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all
else
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
ANDROID_ABI="$abi" HOST_CC=gcc all lib
ANDROID_ABI="$abi" HOST_CC=gcc all
fi
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -E 'AArch64|ARM|X86-64'
mkdir -p "dist/$abi"
cp ./hate-no-d "dist/$abi/hate-no-d"
cp ./libhate-no-d.a "dist/$abi/libhate-no-d.a"
done
- name: Package
@ -171,7 +170,7 @@ jobs:
set -eu
for abi in arm64-v8a armeabi-v7a x86_64; do
sh .forgejo/scripts/make-archive.sh "hate-no-d-android-$abi" tar.gz \
"dist/$abi/hate-no-d" "dist/$abi/libhate-no-d.a"
"dist/$abi/hate-no-d" ./hate-no-d.lua
done
- name: Attach to release
@ -218,7 +217,7 @@ jobs:
- name: Package
run: |
sh .forgejo/scripts/make-archive.sh hate-no-d-freebsd-x86_64 tar.gz \
dist/hate-no-d dist/libhate-no-d.a
dist/hate-no-d ./hate-no-d.lua
- name: Attach to release
if: startsWith(github.ref, 'refs/tags/')
@ -259,10 +258,10 @@ jobs:
set -eu
apt-get update -qq
apt-get install -y --no-install-recommends \
make gcc libc6-dev gcc-multilib mingw-w64 jq zip
make gcc libc6-dev gcc-multilib mingw-w64 jq zip luajit
- name: Build
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all lib
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all
- name: Verify executable
run: |
@ -277,7 +276,7 @@ jobs:
- name: Package
run: |
sh .forgejo/scripts/make-archive.sh "hate-no-d-windows-${{ matrix.arch }}" zip \
./hate-no-d.exe ./libhate-no-d.a
./hate-no-d.exe ./hate-no-d.lua
- name: Attach to release
if: startsWith(github.ref, 'refs/tags/')

5
.gitignore vendored
View file

@ -7,7 +7,6 @@ hate-no-d-*/
hate-no-d-*.tar.gz
hate-no-d-*.zip
# Build artifacts (make lib).
# Build artifacts.
*.o
*.mri
libhate-no-d.a
*.obj

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "submodules/luajit"]
path = submodules/luajit
url = https://luajit.org/git/luajit.git
[submodule "submodules/raylib"]
path = submodules/raylib
url = https://github.com/raysan5/raylib.git

6
.luarc.json Normal file
View file

@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"runtime.version": "LuaJIT",
"workspace.checkThirdParty": false,
"workspace.library": ["./hate-no-d.lua"]
}

257
Makefile
View file

@ -4,15 +4,16 @@
# make
# make PLATFORM=Android ANDROID_NDK=/opt/android-ndk
# make PLATFORM=Android ANDROID_NDK=... ANDROID_ABI=armeabi-v7a ANDROID_API=21
# make PLATFORM=iOS IOS_ARCH=arm64 IOS_MIN=12.0
# make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64)
#
# Targets:
# make the CLI (hate-no-d, or hate-no-d.exe / libluajit.a on iOS)
# make lib libhate-no-d.a, for embedding into another program
# make the CLI (hate-no-d or hate-no-d.exe)
# make help every target and option
#
# raylib is linked into the CLI.
# luajit requires GNU Make (use `gmake` on FreeBSD/OpenBSD/NetBSD).
# The guard below only runs under GNU make; BSD make fails earlier.
ifndef .FEATURES
$(error This build requires GNU Make -- on BSD use 'gmake')
endif
@ -22,21 +23,18 @@ endif
LUAJIT_DIR := submodules/luajit
LUAJIT_SRC := $(LUAJIT_DIR)/src
LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a
RAYLIB_DIR := submodules/raylib
RAYLIB_SRC := $(RAYLIB_DIR)/src
RAYLIB_AR := $(RAYLIB_SRC)/libraylib.a
RAYLIB_API := $(RAYLIB_DIR)/tools/rlparser/output/raylib_api.lua
RLPARSER_DIR := $(RAYLIB_DIR)/tools/rlparser
RLPARSER := $(RLPARSER_DIR)/rlparser
API_DIR := $(RLPARSER_DIR)/output
BINDING := hate-no-d.lua
OBJ := hate-no-d.o
BIN := hate-no-d
LIB := libhate-no-d.a
# Everything that goes into $(LIB) besides LuaJIT itself. Empty today: the only
# C in the tree is the CLI driver, and its main() belongs to the executable an
# embedder already has, not to a library (a -all_load/--whole-archive link would
# collide). Runtime modules added later get listed here, e.g.
# LIB_OBJS += hnod.o
# and are merged into the archive automatically -- that is why the archive has
# a name of its own instead of just being LuaJIT's.
LIB_OBJS :=
# Archiver used to merge $(LIB). Cross toolchains ship their own; Apple has no
# `ar -M`, so those targets use libtool instead (see the $(LIB) rule).
# Archiver passed to raylib's build. Cross toolchains ship their own.
AR ?= ar
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
@ -51,35 +49,43 @@ else ifeq ($(PLATFORM),Android)
OS_KIND := android
else ifeq ($(PLATFORM),Darwin)
OS_KIND := macos
else ifeq ($(PLATFORM),iOS)
OS_KIND := ios
else ifeq ($(PLATFORM),Windows)
OS_KIND := windows
else ifneq (,$(filter $(PLATFORM),FreeBSD OpenBSD NetBSD DragonFly GNU/kFreeBSD))
OS_KIND := bsd
else ifneq (,$(filter MINGW% MSYS% CYGWIN%,$(PLATFORM)))
# Native MinGW/MSYS2/Cygwin shell: uname reports e.g. MINGW64_NT-10.0.
OS_KIND := windows
PLATFORM := Windows
MINGW_ARCH := $(shell uname -m)
ifeq ($(MINGW_ARCH),amd64)
WIN_ARCH ?= x86_64
else ifeq ($(MINGW_ARCH),x86)
WIN_ARCH ?= i686
else
OS_KIND := posix
WIN_ARCH ?= $(MINGW_ARCH)
endif
else ifneq (,$(filter $(PLATFORM),FreeBSD OpenBSD NetBSD DragonFly))
OS_KIND := bsd
endif
# raylib build args; per-platform overrides follow.
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC
RAYLIB_LINK := -Wl,--whole-archive $(RAYLIB_AR) -Wl,--no-whole-archive
# Linux (ELF)
ifeq ($(OS_KIND),linux)
EXPORT_LDFLAGS := -Wl,-E
PLAT_LIBS := -lm -ldl
PLAT_LIBS := -lm -ldl -lGL -lX11 -lpthread -lrt
LINK_TARGET := $(BIN)
endif
# BSD (ELF or Mach-O, dlopen lives in libc)
# BSD (ELF, dlopen lives in libc)
ifeq ($(OS_KIND),bsd)
EXPORT_LDFLAGS := -Wl,-E
PLAT_LIBS := -lm
LINK_TARGET := $(BIN)
# raylib's own BSD list lacks the X11 set its examples link.
PLAT_LIBS := -lm -lGL -lpthread -lX11 -lXrandr -lXinerama -lXi -lXcursor
ifneq (,$(filter $(PLATFORM),OpenBSD NetBSD))
PLAT_LIBS += -lossaudio
endif
# Generic POSIX fallback (Solaris/illumos, AIX, Haiku, ...).
# Note: Solaris ld's -E is NOT --export-dynamic, so it is deliberately off.
ifeq ($(OS_KIND),posix)
EXPORT_LDFLAGS :=
PLAT_LIBS := -lm
LINK_TARGET := $(BIN)
endif
@ -91,9 +97,6 @@ endif
# compiler, because LuaJIT's buildvm runs natively and its pointer size must
# match the target:
# make PLATFORM=Windows WIN_ARCH=i686 HOST_CC="gcc -m32"
#
# No export table: ffi.C resolves through msvcrt/kernel32 handles on Windows,
# unlike ELF where the Lua API has to be exported with -Wl,-E.
ifeq ($(OS_KIND),windows)
WIN_ARCH ?= x86_64
@ -104,10 +107,16 @@ ifeq ($(OS_KIND),windows)
CC := $(WIN_ARCH)-w64-mingw32-gcc
AR := $(WIN_ARCH)-w64-mingw32-ar
HOST_CC ?= gcc
PLAT_LIBS := -lm
PLAT_LIBS := -lm -lopengl32 -lgdi32 -lwinmm
BIN := $(BIN).exe
LINK_TARGET := $(BIN)
# raylib detects the host's OS, so pin the target for cross builds.
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC PLATFORM_OS=WINDOWS
# Export the exe's symbols so ffi.C can resolve raylib on Windows.
EXPORT_LDFLAGS := -Wl,--export-all-symbols
# LuaJIT derives HOST_CC from CC, so label both to the sub-make: otherwise
# the host tools (minilua, buildvm) are compiled with the cross compiler.
LUAJIT_EXTRA := "CC=$(CC)" "HOST_CC=$(HOST_CC)" TARGET_SYS=Windows
@ -127,9 +136,13 @@ ifeq ($(OS_KIND),macos)
export MACOSX_DEPLOYMENT_TARGET
EXPORT_LDFLAGS := -Wl,-export_dynamic
PLAT_LIBS := -lm
PLAT_LIBS := -lm -framework OpenGL -framework Cocoa -framework IOKit \
-framework CoreAudio -framework CoreVideo -framework QuartzCore
LINK_TARGET := $(BIN)
# ld64 has no --whole-archive.
RAYLIB_LINK := -Wl,-force_load,$(RAYLIB_AR)
# MAP_JIT path: needed for the hardened runtime (and therefore notarization).
# Requires MACOSX_DEPLOYMENT_TARGET >= 11.0 or LuaJIT compiles it back out.
MACOSX_HRT ?= 1
@ -151,6 +164,10 @@ ifeq ($(OS_KIND),android)
$(error PLATFORM=Android requires ANDROID_NDK (or ANDROID_NDK_HOME) to be set)
endif
ifneq (,$(filter MINGW% MSYS% CYGWIN%,$(shell uname -s)))
$(error PLATFORM=Android must be built from a Linux or macOS host)
endif
ifeq ($(ANDROID_ABI),arm64-v8a)
ANDROID_TRIPLET := aarch64-linux-android
else ifeq ($(ANDROID_ABI),armeabi-v7a)
@ -172,46 +189,48 @@ ifeq ($(OS_KIND),android)
ANDROID_BIN := $(ANDROID_NDK)/toolchains/llvm/prebuilt/$(ANDROID_HOST_TAG)/bin
ANDROID_CC := $(ANDROID_BIN)/$(ANDROID_TRIPLET)$(ANDROID_API)-clang
ifeq ($(ANDROID_ABI),arm64-v8a)
RAYLIB_ANDROID_ARCH := arm64
else ifeq ($(ANDROID_ABI),armeabi-v7a)
RAYLIB_ANDROID_ARCH := arm
else ifeq ($(ANDROID_ABI),x86_64)
RAYLIB_ANDROID_ARCH := x86_64
else
RAYLIB_ANDROID_ARCH := x86
endif
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_ANDROID RAYLIB_LIBTYPE=STATIC \
ANDROID_NDK=$(ANDROID_NDK) ANDROID_ARCH=$(RAYLIB_ANDROID_ARCH) \
ANDROID_API_VERSION=$(ANDROID_API)
CC := $(ANDROID_CC)
AR := $(ANDROID_BIN)/llvm-ar
EXPORT_LDFLAGS := -Wl,-E
PLAT_LIBS := -lm
# -Wl,--wrap=fopen is raylib's APK asset hook.
PLAT_LIBS := -lm -llog -landroid -lEGL -lGLESv2 -lOpenSLES -ldl -Wl,--wrap=fopen
LINK_TARGET := $(BIN)
LUAJIT_EXTRA := CROSS=$(ANDROID_BIN)/$(ANDROID_TRIPLET)- STATIC_CC=$(ANDROID_CC) TARGET_LD=$(ANDROID_CC) "TARGET_AR=$(ANDROID_BIN)/llvm-ar rcus" TARGET_STRIP=$(ANDROID_BIN)/llvm-strip
endif
# iOS (Mach-O, ARM64 only)
#
# There is no runnable binary: link libluajit.a into your Xcode app target.
# The JIT is compiled out by LuaJIT itself (no runtime code generation is
# allowed on iOS), so you get the fast interpreter only.
ifeq ($(OS_KIND),ios)
IOS_SDK ?= $(shell xcrun --sdk iphoneos --show-sdk-path 2>/dev/null)
IOS_CC ?= $(shell xcrun --sdk iphoneos --find clang 2>/dev/null)
IOS_ARCH ?= arm64
IOS_MIN ?= 12.0
ifeq ($(strip $(IOS_SDK)),)
$(error PLATFORM=iOS requires Xcode/xcrun on the build host)
endif
IOS_FLAGS := -arch $(IOS_ARCH) -isysroot $(IOS_SDK) -mios-version-min=$(IOS_MIN)
CC := $(IOS_CC)
EXPORT_LDFLAGS :=
PLAT_LIBS :=
LINK_TARGET := $(LUAJIT_AR)
# DEFAULT_CC keeps the host toolchain (minilua/buildvm) native; CROSS
# switches only the target objects to the iOS SDK.
LUAJIT_EXTRA := DEFAULT_CC=clang CROSS=$(dir $(IOS_CC)) TARGET_SYS=iOS "TARGET_FLAGS=$(IOS_FLAGS)"
LUAJIT_EXTRA := CROSS=$(ANDROID_BIN)/$(ANDROID_TRIPLET)- \
STATIC_CC=$(ANDROID_CC) TARGET_LD=$(ANDROID_CC) \
"TARGET_AR=$(ANDROID_BIN)/llvm-ar rcus" \
TARGET_STRIP=$(ANDROID_BIN)/llvm-strip TARGET_SYS=Linux
endif
ifndef LINK_TARGET
$(error Unsupported platform '$(PLATFORM)')
$(error Unsupported platform '$(PLATFORM)' -- supported: Linux, Android, Darwin, Windows, BSD)
endif
# Host compiler for build-time tools (rlparser). The Windows branch above
# already pins gcc; everywhere else 'cc' is the native compiler.
HOST_CC ?= cc
LUAJIT ?= luajit
# raylib's RELEASE desktop build appends -O1. -O2 is a large win for CPU-bound
# code (measured 0.83s -> 0.47s on image generation here); -O3 adds nothing.
# Override with RAYLIB_OPT=..., then run `make clean` (objects are not
# flag-aware, so raylib will not rebuild by itself).
RAYLIB_OPT ?= -O2
RAYLIB_MAKE_ARGS += CUSTOM_CFLAGS="$(RAYLIB_OPT)"
# Compiler / linker flags
CFLAGS ?= -O2 -Wall
CPPFLAGS += -I$(LUAJIT_SRC)
@ -222,72 +241,89 @@ LUAJIT_MAKE_ARGS := BUILDMODE=static XCFLAGS="$(LUAJIT_XCFLAGS)" $(LUAJIT_EXTRA)
$(LUAJIT_AR):
$(MAKE) -C $(LUAJIT_SRC) $(LUAJIT_MAKE_ARGS) "LJCORE_O=ljamalg.o" libluajit.a
# raylib: static archive only; CC/AR are pinned because its Makefile defaults to
# native gcc/ar.
$(RAYLIB_AR):
$(MAKE) -C $(RAYLIB_SRC) $(RAYLIB_MAKE_ARGS) CC="$(CC)" AR="$(AR)"
# Targets
help:
@echo "hate-no-d -- LuaJIT-based Lua runtime"
@echo ""
@echo "Targets:"
@echo " make [all] CLI for the auto-detected platform (hate-no-d,"
@echo " hate-no-d.exe, or libluajit.a on iOS)"
@echo " make lib libhate-no-d.a: LuaJIT plus LIB_OBJS, for embedding"
@echo " make luajit LuaJIT static archive only"
@echo " make [all] CLI for the current platform + hate-no-d.lua"
@echo " make bindings regenerate hate-no-d.lua only"
@echo " make check-bindings verify hate-no-d.lua is reproducible and loads"
@echo " make print-config resolved configuration for the current target"
@echo " make clean remove build artifacts, LuaJIT's included"
@echo " make clean remove build artifacts, submodules included"
@echo " make help this text"
@echo ""
@echo "Options (pass as VAR=value):"
@echo " PLATFORM= Linux | Android | Darwin | iOS | Windows | a BSD"
@echo " PLATFORM= Linux | Android | Darwin | Windows | a BSD"
@echo " (default: uname -s)"
@echo " WIN_ARCH= x86_64 | i686 [Windows]"
@echo " ANDROID_NDK= NDK root, or export ANDROID_NDK_HOME [Android]"
@echo " ANDROID_ABI= arm64-v8a | armeabi-v7a | x86_64 | x86 [Android]"
@echo " ANDROID_API= target API level, default 21 [Android]"
@echo " IOS_ARCH= IOS_MIN= arm64 / 12.0 [iOS]"
@echo " IOS_SDK= IOS_CC= Xcode paths, default from xcrun [iOS]"
@echo " MACOSX_HRT= hardened-runtime JIT, default 1 [macOS]"
@echo " MACOSX_DEPLOYMENT_TARGET= default 11.0 [macOS]"
@echo " HOST_CC= host compiler for minilua/buildvm; needed"
@echo " when the target is 32-bit and the host is not"
@echo " LUAJIT= host LuaJIT for the generator, default luajit"
@echo " CFLAGS= default -O2 -Wall"
@echo " RAYLIB_OPT= raylib optimization flags, default -O2"
@echo " LDFLAGS= extra linker flags"
@echo " LIB_OBJS= extra objects merged into libhate-no-d.a"
@echo " AR= archiver used to merge libhate-no-d.a"
@echo " AR= archiver for raylib's build"
all: $(LINK_TARGET)
all: $(LINK_TARGET) $(BINDING)
$(OBJ): hate-no-d.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
$(BIN): $(OBJ) $(LUAJIT_AR)
# raylib must be pulled in whole: nothing references it, so the linker would
# otherwise drop it and ffi.C would have nothing to resolve.
$(BIN): $(OBJ) $(LUAJIT_AR) $(RAYLIB_AR)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
$(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
$(RAYLIB_LINK) $(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
luajit: $(LUAJIT_AR)
# ---------------------------------------------------------------------------
# Lua bindings (hate-no-d.lua)
#
# rlparser emits plain Lua tables; gen-hate-no-d.lua turns raylib.h + rlgl.h +
# raymath.h into one ffi.cdef block, constants, wrappers and LuaCATS comments.
# The tables live in raylib's own tools output directory, next to the committed
# raylib_api.lua; there is no second copy of the parser in this repo.
#
# rlparser is built for the host with HOST_CC, never with the target CC: cross
# builds still have to execute it while generating the platform-independent
# hate-no-d.lua.
# ---------------------------------------------------------------------------
# raylib gitignores this binary; its own Makefile builds it in place when a
# fresh checkout does not have one yet. CFLAGS is pinned so a cross/target
# build's command-line flags never leak into the host tool.
$(RLPARSER): $(RLPARSER_DIR)/rlparser.c
$(MAKE) -C $(RLPARSER_DIR) CC="$(HOST_CC)" CFLAGS="-O2 -Wall -std=c99" rlparser
# Static library for embedding: $(LIB_OBJS) plus LuaJIT, merged into one archive
# so a host program links a single file, and modules added to $(LIB_OBJS) later
# join it without the host's link line changing.
lib: $(LIB)
$(API_DIR)/rlgl_api.lua: $(RLPARSER) $(RAYLIB_SRC)/rlgl.h
$(RLPARSER) -i $(RAYLIB_SRC)/rlgl.h -o $@ -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
# Apple's ar (cctools) has no MRI script mode, so archives are merged with
# libtool there. Everywhere else GNU ar, binutils ar and llvm-ar all parse MRI
# scripts (ADDMOD for objects, ADDLIB for another archive).
APPLE := $(filter macos ios,$(OS_KIND))
$(API_DIR)/raymath_api.lua: $(RLPARSER) $(RAYLIB_SRC)/raymath.h
$(RLPARSER) -i $(RAYLIB_SRC)/raymath.h -o $@ -f LUA -d RMAPI
$(LIB): $(LIB_OBJS) $(LUAJIT_AR)
ifeq ($(APPLE),)
@rm -f $@ $@.mri
@{ echo "CREATE $@"; \
for o in $(LIB_OBJS); do echo "ADDMOD $$o"; done; \
echo "ADDLIB $(LUAJIT_AR)"; \
echo "SAVE"; echo "END"; } > $@.mri
$(AR) -M < $@.mri
@rm -f $@.mri
else
@rm -f $@
libtool -static -o $@ $(LIB_OBJS) $(LUAJIT_AR)
endif
@echo "lib: built $@ ($$($(AR) t $@ | wc -l | tr -d ' ') members)"
$(BINDING): gen-hate-no-d.lua $(API_DIR)/rlgl_api.lua $(API_DIR)/raymath_api.lua $(RAYLIB_API)
@command -v $(LUAJIT) >/dev/null 2>&1 || { \
echo "hate-no-d: cannot run '$(LUAJIT)' -- install LuaJIT or set LUAJIT=..." >&2; exit 1; }
$(LUAJIT) gen-hate-no-d.lua --out=$@
bindings: $(BINDING)
# Fail if regeneration is not byte-identical or the module does not load; also
# checks the three API families are present.
check-bindings: $(BINDING)
$(LUAJIT) gen-hate-no-d.lua --out=hate-no-d.lua.tmp
cmp $(BINDING) hate-no-d.lua.tmp
rm -f hate-no-d.lua.tmp
$(LUAJIT) -e 'local M = dofile("$(BINDING)"); assert(type(M) == "table"); assert(type(M.GetMousePosition) == "function", "raylib"); assert(type(M.rlLoadIdentity) == "function", "rlgl"); assert(type(M.Vector2Add) == "function", "raymath"); print("bindings ok")'
# Show the resolved configuration for the current (or selected) platform.
# Useful for checking a cross build before committing to it.
@ -296,19 +332,28 @@ print-config:
@echo "OS_KIND = $(OS_KIND)"
@echo "CC / AR = $(CC) / $(AR)"
@echo "CFLAGS = $(CFLAGS)"
@echo "RAYLIB_OPT = $(RAYLIB_OPT)"
@echo "CPPFLAGS = $(CPPFLAGS)"
@echo "EXPORT_LDFLAGS = $(EXPORT_LDFLAGS)"
@echo "PLAT_LIBS = $(PLAT_LIBS)"
@echo "LINK_TARGET = $(LINK_TARGET)"
@echo "OBJ / LIB = $(OBJ) / $(LIB) [$(LIB_OBJS)]"
@echo "OBJ = $(OBJ)"
@echo "HOST_CC = $(HOST_CC)"
@echo "LUAJIT = $(LUAJIT)"
@echo "API_DIR = $(API_DIR)"
@echo "BINDING = $(BINDING)"
@echo "LUAJIT_MAKE_ARGS = $(LUAJIT_MAKE_ARGS)"
@echo "RAYLIB_AR = $(RAYLIB_AR)"
@echo "RAYLIB_MAKE_ARGS = $(RAYLIB_MAKE_ARGS)"
@echo "MACOSX_DEPLOYMENT_TARGET = $(MACOSX_DEPLOYMENT_TARGET) (HRT=$(MACOSX_HRT))"
@echo "ANDROID_ABI / API = $(ANDROID_ABI) / $(ANDROID_API)"
@echo "IOS_ARCH / MIN = $(IOS_ARCH) / $(IOS_MIN)"
@echo "WIN_ARCH = $(WIN_ARCH) (HOST_CC=$(HOST_CC))"
clean:
$(MAKE) -C $(LUAJIT_DIR) clean
rm -f $(BIN) $(OBJ) $(LIB) $(LIB).mri
@if [ -f $(LUAJIT_DIR)/Makefile ]; then $(MAKE) -C $(LUAJIT_DIR) clean; fi
@if [ -f $(RAYLIB_SRC)/Makefile ]; then $(MAKE) -C $(RAYLIB_SRC) clean; fi
rm -f $(BIN) hate-no-d.exe $(OBJ) libhate-no-d.a libhate-no-d.a.mri $(LUAJIT_AR) $(RAYLIB_AR)
rm -f $(BINDING) hate-no-d.lua.tmp
rm -f $(API_DIR)/rlgl_api.lua $(API_DIR)/raymath_api.lua
.PHONY: all clean luajit print-config lib help
.PHONY: all clean print-config help bindings check-bindings

145
README.md
View file

@ -2,25 +2,141 @@
A [Love2D](https://www.love2d.org/) antagonist.
A glorified [Makefile](./Makefile), plus a small `build.bat` for MSVC.
Should work on:
- Linux (x86, x86_64, ARM, ARM64)
- Android (armeabi-v7a, arm64-v8a, x86, x86_64)
- macOS (x86_64, ARM64)
- Windows (x86, x86_64 via MinGW; ARM64 via MSVC)
- FreeBSD, OpenBSD, NetBSD (x86, x86_64) or DragonFly BSD (x86_64)
## Quick Start
### On Linux, macOS, BSD, POSIX or Windows-MinGW
Once you have the binary, save this as `quick-start.lua`:
```lua
local hnd = require("hate-no-d")
hnd.InitWindow(1280, 720, "hate-no-d")
local text = "Your first hate-no-d application!"
local fontSize = 48
local spacing = fontSize / hnd.GetFontDefault().baseSize
local textSize = hnd.MeasureTextEx(hnd.GetFontDefault(), text, fontSize, spacing)
local posX = (hnd.GetRenderWidth() / 2) - (textSize.x / 2)
local posY = (hnd.GetRenderHeight() / 2) - (textSize.y / 2)
while not hnd.WindowShouldClose() do
hnd.ClearBackground(hnd.SKYBLUE)
hnd.BeginDrawing()
hnd.DrawText(text, posX, posY, fontSize, hnd.DARKBLUE)
hnd.EndDrawing()
end
hnd.CloseWindow()
```
Then run it:
```sh
echo -e 'print("Hey! I am hate-no-d!")' > quick-start.lua
./hate-no-d quick-start.lua
```
### On Windows MSVC
`hate-no-d.lua` is the generated raylib/rlgl/raymath binding module. Release
archives include it next to the binary; when building from source, `make`
generates it automatically.
On Windows, use `cmd` or PowerShell:
```bat
echo print("Hey! I am hate-no-d!") > quick-start.lua
hate-no-d.exe quick-start.lua
```
## Build
## Building
### On Linux, macOS, BSD, POSIX or Windows-MinGW
You can download precompiled builds from the [releases page](https://git.pbento.pt/pedro-bento/hate-no-d/releases).
### Linux prerequisites
Install a C toolchain, `git` and the OpenGL/X11 development headers:
Debian/Ubuntu:
```sh
sudo apt install build-essential git luajit libgl1-mesa-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
```
Fedora:
```sh
sudo dnf install gcc make git luajit mesa-libGL-devel libX11-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel
```
Arch:
```sh
sudo pacman -S --needed base-devel git luajit mesa libx11 libxrandr libxinerama libxcursor libxi
```
Void:
```sh
sudo xbps-install -S base-devel git luajit MesaLib-devel libX11-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel
```
Gentoo:
```sh
sudo emerge --ask sys-devel/gcc dev-build/make dev-vcs/git dev-lang/luajit media-libs/mesa x11-libs/libX11 x11-libs/libXrandr x11-libs/libXinerama x11-libs/libXcursor x11-libs/libXi
```
### macOS prerequisites
Install the Xcode Command Line Tools:
```sh
xcode-select --install
```
`make` and `clang` come with them. Install the host LuaJIT used by the binding
generator:
```sh
brew install luajit
```
### BSD prerequisites
Install GNU Make and the X11 development headers. FreeBSD:
```sh
sudo pkg install gmake luajit libX11 libXrandr libXinerama libXi libXcursor
```
On OpenBSD, NetBSD and DragonFly, install `gmake` and `luajit` with the system
package manager (`pkg_add gmake luajit`, `pkgin install gmake luajit` or
`pkg install gmake luajit`); X11 headers are usually in the base X sets, but
install the X11 libraries if they are missing. Use `gmake` instead of `make`.
### Android prerequisites
Android builds cross-compile from Linux or macOS. Install the Android NDK and
pass its path with `ANDROID_NDK`, or set `ANDROID_NDK_HOME`.
### Windows prerequisites
For MSVC, install Visual Studio 2022 with the "Desktop development with C++" workload. `build.bat` locates it automatically and uses the bundled CMake when available; raylib requires CMake 3.22 or newer, so install CMake if your VS2022 copy bundles an older version.
For MinGW, use MSYS2 with the mingw-w64 toolchain and `make`. A native MSYS2 build is auto-detected; when cross-compiling from another host, pass `PLATFORM=Windows` (and `WIN_ARCH=i686` for 32-bit).
### Building from source
To build manually on Linux, macOS or a BSD, run:
```sh
git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git
@ -28,10 +144,25 @@ cd hate-no-d
make
```
### On Windows MSVC
`make` builds the CLI and regenerates `hate-no-d.lua`; the generator needs a
host `luajit` in `PATH` (override with `make LUAJIT=/path/to/luajit`). On the
BSDs, use `gmake` instead of `make`.
On Windows with MinGW (MSYS2), run `make` in the MSYS2 MINGW shell. To cross-compile
from another host, run `make PLATFORM=Windows` (add `WIN_ARCH=i686` for 32-bit).
On Windows with MSVC:
```bat
git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git
cd hate-no-d
build.bat
```
To build for Android from Linux or macOS, pass your NDK path (or set `ANDROID_NDK_HOME`):
```sh
make PLATFORM=Android ANDROID_NDK=/path/to/ndk
```
`ANDROID_ABI` defaults to `arm64-v8a` and `ANDROID_API` to `21`; see `make help` for the other ABIs. Building `armeabi-v7a` on a 64-bit host also needs `HOST_CC="gcc -m32"`.

View file

@ -7,7 +7,8 @@
@rem
@rem Works from a plain cmd.exe (locates Visual Studio itself) or from an
@rem existing Developer Command Prompt. Produces hate-no-d.exe in this
@rem directory, statically linked against LuaJIT.
@rem directory, statically linked against LuaJIT and raylib. raylib is built
@rem with CMake (shipped with Visual Studio) and linked in whole.
@echo off
setlocal EnableExtensions
@ -41,12 +42,18 @@ if not exist "submodules\luajit\src\msvcbuild.bat" (
@rem msvcbuild.bat only ever appends options in a fixed order and deletes its
@rem own .obj files at the end, so every run is a full rebuild anyway.
@rem Pin /MT through the CL environment so LuaJIT's static CRT matches raylib's
@rem below; the static branch of msvcbuild.bat does not choose a runtime itself.
echo === Building LuaJIT (static, lua52compat) for Windows/%ARCH% ===
if exist "submodules\luajit\src\lua51.lib" del /q "submodules\luajit\src\lua51.lib"
set "HNOD_CL=%CL%"
set "CL=/MT"
pushd "submodules\luajit\src" >nul
call msvcbuild.bat lua52compat static
popd >nul
set "CL=%HNOD_CL%"
set "HNOD_CL="
@rem msvcbuild.bat does not set errorlevel when it fails, so the artifact is
@rem the only trustworthy signal.
@ -56,15 +63,67 @@ if not exist "submodules\luajit\src\lua51.lib" (
goto :fail
)
@rem raylib is built through CMake, which ships with Visual Studio.
@rem It uses the static CRT to match LuaJIT's default msvcbuild output, and
@rem defines BUILD_LIBTYPE_SHARED so its RLAPI functions carry dllexport and
@rem land in the exe's export table -- MSVC has no --export-dynamic, and ffi.C
@rem resolves C symbols through that table at runtime.
if not exist "submodules\raylib\CMakeLists.txt" (
echo build.bat: submodules\raylib is missing.
echo Fetch it with: git submodule update --init submodules/raylib
goto :fail
)
where cmake >nul 2>&1
if errorlevel 1 (
echo build.bat: cmake not found - install CMake 3.22+ or use a Developer Command Prompt.
goto :fail
)
if /I "%ARCH%"=="x64" set "CMAKE_ARCH=x64"
if /I "%ARCH%"=="x86" set "CMAKE_ARCH=Win32"
if /I "%ARCH%"=="arm64" set "CMAKE_ARCH=ARM64"
@rem One build tree per arch: CMake refuses to reuse a cache configured for
@rem another -A platform, so `build.bat x86` after x64 must not share it.
set "RAYLIB_BUILD=build\raylib-%ARCH%"
echo === Building raylib (static) for Windows/%ARCH% ===
cmake -S "submodules\raylib" -B "%RAYLIB_BUILD%" -A %CMAKE_ARCH% ^
-DBUILD_SHARED_LIBS=OFF ^
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ^
-DCMAKE_C_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /DBUILD_LIBTYPE_SHARED" ^
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE="%CD%\%RAYLIB_BUILD%\lib" ^
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG="%CD%\%RAYLIB_BUILD%\lib"
if errorlevel 1 goto :fail
cmake --build "%RAYLIB_BUILD%" --config Release --target raylib
if errorlevel 1 goto :fail
if not exist "%RAYLIB_BUILD%\lib\raylib.lib" (
echo build.bat: raylib.lib was not produced.
goto :fail
)
echo === Building hate-no-d.exe ===
if exist hate-no-d.obj del /q hate-no-d.obj
cl /nologo /c /O2 /W4 /D_CRT_SECURE_NO_WARNINGS ^
cl /nologo /c /O2 /W4 /MT /D_CRT_SECURE_NO_WARNINGS ^
/I "submodules\luajit\src" /Fo"hate-no-d.obj" hate-no-d.c
if errorlevel 1 goto :fail
link /nologo /OUT:hate-no-d.exe hate-no-d.obj "submodules\luajit\src\lua51.lib"
link /nologo /OUT:hate-no-d.exe hate-no-d.obj ^
"/WHOLEARCHIVE:%CD%\%RAYLIB_BUILD%\lib\raylib.lib" ^
"submodules\luajit\src\lua51.lib" ^
opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib advapi32.lib
if errorlevel 1 goto :fail
@rem ffi.C reads the exe's export table, so verify raylib really got exported.
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" >nul
if errorlevel 1 (
echo build.bat: hate-no-d.exe does not export raylib - ffi.C would not find it.
goto :fail
)
del /q hate-no-d.obj
echo.
@ -84,6 +143,7 @@ if exist "submodules\luajit\src" (
del /q *.obj host\*.obj *.manifest >nul 2>&1
popd >nul
)
if exist "build" rmdir /s /q "build"
popd >nul
endlocal
exit /b 0

1185
gen-hate-no-d.lua Normal file

File diff suppressed because it is too large Load diff

11140
hate-no-d.lua Normal file

File diff suppressed because it is too large Load diff

1
submodules/raylib Submodule

@ -0,0 +1 @@
Subproject commit ad124dd7f5864fcdd9cc8868d5baae61041a7d3c