try fixing flake

This commit is contained in:
2026-07-26 18:29:13 +01:00
parent a9054b3be4
commit 1935be52ac
5 changed files with 161 additions and 54 deletions
+16 -17
View File
@@ -19,6 +19,11 @@ SDL_CFLAGS := $(shell pkg-config --cflags sdl3 sdl3-ttf sdl3-image)
SDL_LIBS_DEBUG := $(shell pkg-config --libs sdl3 sdl3-ttf sdl3-image) SDL_LIBS_DEBUG := $(shell pkg-config --libs sdl3 sdl3-ttf sdl3-image)
SDL_LIBS_RELEASE := $(shell pkg-config --libs sdl3 sdl3-ttf sdl3-image) SDL_LIBS_RELEASE := $(shell pkg-config --libs sdl3 sdl3-ttf sdl3-image)
# ----------------- MRUBY --------------
MRUBY_CFLAGS := -I$(MRUBY_INCLUDE)
MRUBY_LIBS := $(MRUBY_LIB)
# ---------------- FLAGS ---------------- # ---------------- FLAGS ----------------
CFLAGS_DEBUG := \ CFLAGS_DEBUG := \
@@ -26,25 +31,19 @@ CFLAGS_DEBUG := \
-Og -g -fno-omit-frame-pointer \ -Og -g -fno-omit-frame-pointer \
-Wno-unused-command-line-argument \ -Wno-unused-command-line-argument \
-I./include -I./libs/mruby/build/host/include \ -I./include -I./libs/mruby/build/host/include \
$(SDL_CFLAGS) $(SDL_CFLAGS) $(MRUBY_CFLAGS)
CFLAGS_RELEASE := \ CFLAGS_RELEASE := \
-std=c++20 -O3 -march=x86-64 -mtune=generic \ -std=c++20 -O3 -mtune=generic \
-flto=thin \ -flto=thin \
-fno-rtti -fomit-frame-pointer -DNDEBUG -s \ -fno-rtti -fomit-frame-pointer -DNDEBUG -s \
-Wno-unused-command-line-argument \ -Wno-unused-command-line-argument \
-I./include -I./libs/mruby/build/host/include \ -I./include -I./libs/mruby/build/host/include \
$(SDL_CFLAGS) $(SDL_CFLAGS) $(MRUBY_CFLAGS)
PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header
PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header
# ---------------- LIBS ----------------
LIBS := ./libs/mruby/build/host/lib/libmruby.a
MGEM_DIR := ./libs/l_mgems
# ---------------- SOURCES ---------------- # ---------------- SOURCES ----------------
SRC := $(shell find $(SRC_DIR) -name "*.cc") SRC := $(shell find $(SRC_DIR) -name "*.cc")
@@ -57,18 +56,18 @@ DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
# ---------------- TARGETS ---------------- # ---------------- TARGETS ----------------
.PHONY: all debug release clean mgems .PHONY: all debug release clean scripts
all: debug all: debug
debug: mgems $(TARGET_DEBUG) debug: scripts $(TARGET_DEBUG)
release: mgems $(TARGET_RELEASE) release: scripts $(TARGET_RELEASE)
# ---------------- MRB_MGEMS ---------------- # ---------------- MRB_MGEMS ----------------
mgems: scripts:
@$(MGEM_DIR)/compile.sh ./scripts/compile.sh
# ---------------- PCH ---------------- # ---------------- PCH ----------------
@@ -86,12 +85,12 @@ $(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG)
@mkdir -p $(BIN_DIR) @mkdir -p $(BIN_DIR)
@$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(SDL_LIBS_DEBUG) $(LIBS) @$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(SDL_LIBS_DEBUG) $(MRUBY_LIBS)
@echo "Debug build complete: $@" @echo "Debug build complete: $@"
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE)
@mkdir -p $(BIN_DIR) @mkdir -p $(BIN_DIR)
@$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(SDL_LIBS_RELEASE) $(LIBS) @$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(SDL_LIBS_RELEASE) $(MRUBY_LIBS)
@echo "Release build complete: $@" @echo "Release build complete: $@"
# ---------------- COMPILE ---------------- # ---------------- COMPILE ----------------
@@ -115,5 +114,5 @@ $(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE)
clean: clean:
@rm -rf $(OBJ_DIR) $(BIN_DIR) @rm -rf $(OBJ_DIR) $(BIN_DIR)
@$(MGEM_DIR)/compile.sh clean ./compile.sh clean
@echo "Cleaned build artifacts." @echo "Cleaned build artifacts."
+112 -34
View File
@@ -3,48 +3,126 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
self.submodules = true;
}; };
outputs = outputs =
{ self, nixpkgs }: { nixpkgs, ... }:
let let
systems = [ "x86_64-linux" ]; system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
staticPkgs = pkgs.pkgsStatic;
mruby = staticPkgs.stdenv.mkDerivation {
pname = "mruby";
version = "0.0.1";
src = staticPkgs.lib.cleanSourceWith {
src = ./libs;
name = "mruby-src";
};
patches = [
./libs/changes.patch
];
nativeBuildInputs = with pkgs; [
ruby
gnumake
clang
];
buildPhase = ''
cd mruby
rake
'';
installPhase = ''
mkdir -p $out
cp -r build/host/lib $out/lib
cp -r build/host/include $out/include
mkdir -p $out/bin
cp build/host/bin/mrbc $out/bin/mrbc
'';
};
game-engine = staticPkgs.stdenv.mkDerivation {
pname = "game-engine";
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
pkg-config
gnumake
bear
ccache
xxd
];
buildInputs = [
pkgs.sdl3
pkgs.sdl3-ttf
pkgs.sdl3-image
mruby
];
buildPhase = ''
make \
MRBC=${mruby}/bin/mrbc \
MRUBY_INCLUDE=${mruby}/include \
MRUBY_LIB=${mruby}/lib/libmruby.a
'';
installPhase = ''
mkdir -p $out/bin
cp game-engine $out/bin/game-engine
'';
CC = "${pkgs.clang}/bin/clang";
CXX = "${pkgs.clang}/bin/clang++";
};
forAllSystems =
f:
nixpkgs.lib.genAttrs systems (
system:
f (
import nixpkgs {
inherit system;
}
)
);
in in
{ {
devShells = forAllSystems (pkgs: { packages.${system} = {
default = pkgs.mkShell { default = game-engine;
packages = with pkgs; [ game-engine = game-engine;
clang-tools mruby = mruby;
clang };
ccache
pkg-config
gnumake
ruby
xxd
bear
sdl3 devShells.${system}.default = pkgs.mkShell {
sdl3-ttf inputsFrom = [ game-engine ];
sdl3-image
];
shellHook = '' packages = [
export CC=clang pkgs.clang-tools
export CXX=clang++ pkgs.clang
export LD=clang pkgs.ccache
''; pkgs.pkg-config
}; pkgs.gnumake
}); pkgs.bear
pkgs.ruby
pkgs.xxd
pkgs.sdl3
pkgs.sdl3-ttf
pkgs.sdl3-image
];
shellHook = ''
export CC=clang
export CXX=clang++
export LD=clang
export MRBC=${mruby}/bin/mrbc
export MRUBY_INCLUDE=${mruby}/include
export MRUBY_LIB=${mruby}/lib/libmruby.a
'';
};
}; };
} }
+30
View File
@@ -0,0 +1,30 @@
--- ./mruby/build_config/default.rb
+++ ./mruby/build_config/default.rb
@@ -1,6 +1,18 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
- conf.toolchain
+ conf.toolchain :gcc
+
+ conf.cc do |cc|
+ cc.command = ENV['CC']
+ end
+
+ conf.cxx do |cxx|
+ cxx.command = ENV['CXX']
+ end
+
+ conf.linker do |linker|
+ linker.command = ENV['CXX']
+ end
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
@@ -79,5 +79,5 @@
# Turn on `enable_debug` for better debugging
# conf.enable_debug
- conf.enable_bintest
- conf.enable_test
+ # conf.enable_bintest
+ # conf.enable_test
end
@@ -4,7 +4,7 @@ set -e
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_TMP=$(mktemp) OUTPUT_TMP=$(mktemp)
OUTPUT="$SCRIPT_DIR/../../include/bindings/ruby_compiled.h" OUTPUT="$SCRIPT_DIR/../include/bindings/ruby_compiled.h"
if test "$1" = "clean"; then if test "$1" = "clean"; then
rm -f "$OUTPUT" rm -f "$OUTPUT"
@@ -28,7 +28,7 @@ fi
echo "Compiling mgems..." echo "Compiling mgems..."
"$SCRIPT_DIR/../mruby/bin/mrbc" -o "$OUTPUT_TMP" "${FILES[@]}" "${MRBC:-mrbc}" -o "$OUTPUT_TMP" "${FILES[@]}"
{ {
echo "#ifndef MGEMS_H" echo "#ifndef MGEMS_H"