From 79215819c47c74a02456776a63b5bffc8de8173f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 1 Sep 2026 10:35:20 +0900 Subject: [PATCH 1/3] Move the rules for win32_vk Enable the rules only when `gperf` command is available. And replace `gperf.sed` with `extract-vk.rb` script. ruby/ruby@3d4e682dafd988b50d1050dcbc90dd49c17382bc --- ext/io/console/extconf.rb | 16 +++++++++++++++- ext/io/console/extract-vk.rb | 13 ++++++++++++- ext/io/console/{depend => win32_vk.mk} | 8 +++----- tool/gperf.sed | 4 ---- 4 files changed, 30 insertions(+), 11 deletions(-) rename ext/io/console/{depend => win32_vk.mk} (60%) delete mode 100644 tool/gperf.sed diff --git a/ext/io/console/extconf.rb b/ext/io/console/extconf.rb index d10bdcfe..fb058f61 100644 --- a/ext/io/console/extconf.rb +++ b/ext/io/console/extconf.rb @@ -52,8 +52,22 @@ have_const("RB_WARN_CATEGORY_DEPRECATED") win32 or have_func("ttyname_r") or have_func("ttyname") have_func("rb_prepend_module") # not exported by TruffleRuby + vk_tool = find_executable("gperf") create_makefile("io/console") {|conf| - conf << "\n""VK_HEADER = #{vk_header}\n" + if vk_header + conf << <<~MK + VK_HEADER = #{vk_header} + all: + console.#$OBJEXT: $(VK_HEADER) + MK + end + if vk_tool + unless conf.any? {|c| /^ *top_srcdir *=/.match?(c)} + conf << "top_srcdir = $(srcdir)/../../..\n" + end + conf.concat(depend_rules(File.read("#$srcdir/win32_vk.mk"))) + end + conf } when nil File.write("Makefile", dummy_makefile($srcdir).join("")) diff --git a/ext/io/console/extract-vk.rb b/ext/io/console/extract-vk.rb index 387d5b38..94c3bac7 100644 --- a/ext/io/console/extract-vk.rb +++ b/ext/io/console/extract-vk.rb @@ -1,7 +1,18 @@ code = [+""] -ARGF.read.scan(/^\w+,\s*\KVK_\w+/) do |n| +source = File.read(ARGV.shift) +source.scan(/^\w+,\s*\KVK_\w+/) do |n| puts("#ifndef #{n}\n# define #{n} UNDEFINED_VK\n#endif") code << +"" if n.size + code.last.size > 60 code.last << " x(#{n})z" end puts ["#define EACH_VK(x,z)", code].join(" \\\n "), "" +IO.popen(["gperf", *ARGV], "r+") do |f| + w = Thread.start { + f.puts source + f.close_write + } + puts f.read.sub(/^\w*hash .*\{(?m:.*?)\n\}/) { + $&.sub!(" hval = ", " hval = (unsigned int)") + } + w.join +end diff --git a/ext/io/console/depend b/ext/io/console/win32_vk.mk similarity index 60% rename from ext/io/console/depend rename to ext/io/console/win32_vk.mk index 73638fe7..97757a05 100644 --- a/ext/io/console/depend +++ b/ext/io/console/win32_vk.mk @@ -1,11 +1,9 @@ win32_vk.inc: win32_vk.list $(srcdir)/extract-vk.rb .list.inc: - ( \ - $(RUBY) $(srcdir)/extract-vk.rb $< && \ - gperf --ignore-case -L ANSI-C -E -C -P -p -j1 -i 1 -g -o -t -K ofs -N console_win32_vk -k* $< \ - | sed -f $(top_srcdir)/tool/gperf.sed \ - ) > $(@F) + $(Q)$(RUBY) $(srcdir)/extract-vk.rb $< \ + --ignore-case -L ANSI-C -E -C -P -p -j1 -i 1 -g -o -t -K ofs -N console_win32_vk -k* \ + > $(@F) .SUFFIXES: .chksum .list .inc diff --git a/tool/gperf.sed b/tool/gperf.sed deleted file mode 100644 index 9550a522..00000000 --- a/tool/gperf.sed +++ /dev/null @@ -1,4 +0,0 @@ -/^[a-zA-Z_0-9]*hash/,/^}/{ - s/ hval = / hval = (unsigned int)/ - s/ return / return (unsigned int)/ -} From ff6c22cb9f5a84bee404f5e5723144cf11d2fae9 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 2 Sep 2026 14:34:10 +0900 Subject: [PATCH 2/3] Add generated dependency rules Keep generated dependency metadata in the upstream repository so it can be updated there and synchronized into ruby/ruby. --- ext/io/console/depend | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ext/io/console/depend diff --git a/ext/io/console/depend b/ext/io/console/depend new file mode 100644 index 00000000..e7555961 --- /dev/null +++ b/ext/io/console/depend @@ -0,0 +1,3 @@ +# AUTOGENERATED DEPENDENCIES START +console.o: console.c +# AUTOGENERATED DEPENDENCIES END From 207a809235d424effbbc2877dd121bd7baadb103 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 2 Sep 2026 14:42:21 +0900 Subject: [PATCH 3/3] Fix the main target --- ext/io/console/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/io/console/extconf.rb b/ext/io/console/extconf.rb index fb058f61..65d36057 100644 --- a/ext/io/console/extconf.rb +++ b/ext/io/console/extconf.rb @@ -54,10 +54,10 @@ have_func("rb_prepend_module") # not exported by TruffleRuby vk_tool = find_executable("gperf") create_makefile("io/console") {|conf| + conf << "###\n" "all: # the default target\n" if vk_header conf << <<~MK VK_HEADER = #{vk_header} - all: console.#$OBJEXT: $(VK_HEADER) MK end