Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .claude/rules/ruby/rsdl.md

This file was deleted.

4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
path = ruby/ruby-sdl2
url = https://github.com/smalruby/ruby-sdl2.git
branch = smalruby/add-read-pixels
[submodule "ruby/rsdl"]
path = ruby/rsdl
url = https://github.com/smalruby/rsdl.git
branch = smalruby/ruby-4.0-support
1 change: 0 additions & 1 deletion ruby/rsdl
Submodule rsdl deleted from 21829f
7 changes: 7 additions & 0 deletions ruby/smalruby3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ lib/smalruby3/smalruby3_imageutil.bundle
lib/smalruby3/smalruby3_imageutil.so
*.gem

# Launcher build artifacts
ext/smalruby3_launcher/smalruby3
ext/smalruby3_launcher/smalruby3_launcher.c
ext/smalruby3_launcher/smalruby3_launcher.o
ext/smalruby3_launcher/Makefile
ext/smalruby3_launcher/mkmf.log

# Docker marker
.built
2 changes: 2 additions & 0 deletions ruby/smalruby3/.standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "ext/**/extconf.rb"
18 changes: 18 additions & 0 deletions ruby/smalruby3/exe/smalruby3
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

# smalruby3 launcher wrapper — exec's the native SDL2 binary.
# The native binary (smalruby3-bin) is installed to Ruby's bindir
# by ext/smalruby3_launcher during gem install.

require "rbconfig"

bindir = RbConfig::CONFIG["bindir"]
binary = File.join(bindir, "smalruby3-bin")

# Fallback: development mode (built locally in ext/)
unless File.exist?(binary)
binary = File.join(File.dirname(__FILE__, 2),
"ext", "smalruby3_launcher", "smalruby3")
end

exec binary, *ARGV
26 changes: 26 additions & 0 deletions ruby/smalruby3/ext/smalruby3_launcher/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CC = <%= config['CC'] %>

CFLAGS = <%= config['CFLAGS'] %>
LIBS = <%= config['LIBS'] %>
LDFLAGS = <%= config['LDFLAGS'] %>
LIBPATH = <%= config['LIBPATH'] %>
LIBRUBYARG = <%= config['LIBRUBYARG'] %>
EXEEXT = <%= config['EXEEXT'] %>

PROGRAM = smalruby3$(EXEEXT)

OBJS = smalruby3_launcher.o

.c.o:
$(CC) $(CFLAGS) -c $<

all: $(PROGRAM)

clean:
<%= config['RMALL'] %> $(PROGRAM) $(OBJS)

install:
<%= config['INSTALL'] %> $(PROGRAM) <%= config['bindir'] %>/smalruby3-bin

$(PROGRAM): $(OBJS)
$(CC) $(OBJS) $(LIBPATH) $(LDFLAGS) $(LIBRUBYARG) $(LIBS) -o $@
48 changes: 48 additions & 0 deletions ruby/smalruby3/ext/smalruby3_launcher/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Build the smalruby3 launcher binary (SDL2 main thread wrapper).
# Based on rsdl's extconf.rb.

require "mkmf"
require "erb"

# Source directory where .in templates live
srcdir = File.dirname(File.expand_path(__FILE__))

dir_config("sdl")
sdlconfig = with_config("sdl-config", "sdl-config")

config = {}
config["arch"] = RbConfig::CONFIG["arch"]
config["INSTALL"] = RbConfig::CONFIG["INSTALL"]
config["RMALL"] = RbConfig::CONFIG["RMALL"] || "rm -fr"
config["CC"] = RbConfig::CONFIG["CC"]
config["CFLAGS"] = RbConfig::CONFIG["CFLAGS"]
config["CFLAGS"] += " -I\"#{$hdrdir}\"" if $hdrdir
config["CFLAGS"] += " -I\"#{$arch_hdrdir}\"" if $arch_hdrdir
config["CFLAGS"] += " " + `"#{sdlconfig}" --cflags` if sdlconfig && !sdlconfig.empty?
config["LDFLAGS"] = RbConfig::CONFIG["LDFLAGS"]
config["LIBS"] = RbConfig::CONFIG["LIBS"]
config["LIBS"] += " " + `"#{sdlconfig}" --libs` if sdlconfig && !sdlconfig.empty?
config["LIBPATH"] = RbConfig.expand(libpathflag)
config["LIBRUBYARG"] = RbConfig::CONFIG["LIBRUBYARG"]
config["EXEEXT"] = RbConfig::CONFIG["EXEEXT"]
config["bindir"] = RbConfig::CONFIG["bindir"]
# gem_dir: where the gem is installed (for install target)
config["gem_dir"] = srcdir

headers = []
headers << "#define HAVE_RUBY_SYSINIT 1" if have_func("ruby_sysinit")
headers << "#define HAVE_RUBY_RUN_NODE 1" if have_func("ruby_run_node")
config["COMMON_HEADERS"] = ([(COMMON_HEADERS || "")] + headers).join("\n")

%w[Makefile smalruby3_launcher.c].each do |file|
# Read template from source directory
template_path = File.join(srcdir, file + ".in")
template = ERB.new(File.read(template_path), trim_mode: "%")
message "creating %s\n" % file
File.open(file, "w") do |f|
f.print template.result(binding)
end
end
38 changes: 38 additions & 0 deletions ruby/smalruby3/ext/smalruby3_launcher/smalruby3_launcher.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* smalruby3 launcher — SDL2 main thread wrapper for macOS */
/* Based on rsdl (https://github.com/knu/rsdl) */

#include <ruby.h>
<%= config['COMMON_HEADERS'] %>
#include <SDL.h>
#include "SDL_main.h"
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif

#ifdef RUBY_GLOBAL_SETUP
RUBY_GLOBAL_SETUP
#endif

int main(int argc, char **argv)
{
#ifdef HAVE_LOCALE_H
setlocale(LC_CTYPE, "");
#endif

#ifdef HAVE_RUBY_SYSINIT
ruby_sysinit(&argc, &argv);
#endif
{
#ifdef RUBY_INIT_STACK
RUBY_INIT_STACK;
#endif
ruby_init();
#ifdef HAVE_RUBY_RUN_NODE
return ruby_run_node(ruby_options(argc, argv));
#else
ruby_options(argc, argv);
ruby_run();
return 0;
#endif
}
}
6 changes: 4 additions & 2 deletions ruby/smalruby3/smalruby3.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ Gem::Specification.new do |spec|
spec.license = "MIT"
spec.required_ruby_version = ">= 3.3"

spec.files = Dir["lib/**/*.rb", "lib/**/*.json", "ext/**/*.{rb,rs,toml}", "assets/**/*", "LICENSE", "README.md"]
spec.files = Dir["lib/**/*.rb", "lib/**/*.json", "ext/**/*.{rb,rs,toml,in,c.in}", "exe/*", "assets/**/*", "LICENSE", "README.md"]
spec.bindir = "exe"
spec.executables = ["smalruby3"]
spec.require_paths = ["lib"]
spec.extensions = ["ext/smalruby3_imageutil/extconf.rb"]
spec.extensions = ["ext/smalruby3_imageutil/extconf.rb", "ext/smalruby3_launcher/extconf.rb"]

spec.add_dependency "ruby-sdl2", "~> 0.3"
spec.add_dependency "rb_sys", "~> 0.9"
Expand Down
Loading