Skip to content

Commit dbde834

Browse files
Migrate to extconf from raw Makefile
1 parent 4346270 commit dbde834

File tree

7 files changed

+55
-64
lines changed

7 files changed

+55
-64
lines changed

Rakefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ namespace :build do
289289
args = build.configure_args(RbConfig::CONFIG["host"])
290290
sh "#{source.configure_file} #{args.join(" ")}", chdir: build.build_dir
291291
end
292+
# NOTE: we need rbconfig.rb at configuration time to build user given extensions with mkmf
293+
sh "make rbconfig.rb", chdir: build.build_dir
292294
end
293295

294296
desc "Build #{build.name}"
@@ -323,7 +325,24 @@ namespace :build do
323325
libs.each do |lib|
324326
objdir = "#{build.ext_build_dir}/#{lib}"
325327
FileUtils.mkdir_p objdir
326-
make_cmd = %Q(make -C "#{base_dir}/ext/#{lib}" #{make_args.join(" ")} OBJDIR=#{objdir} obj)
328+
srcdir = "#{base_dir}/ext/#{lib}"
329+
extconf_args = [
330+
"--disable=gems",
331+
# HACK: top_srcdir is required to find ruby headers
332+
"-e", %Q('$top_srcdir="#{source.src_dir}"'),
333+
# HACK: extout is required to find config.h
334+
"-e", %Q('$extout="#{build.build_dir}/.ext"'),
335+
# HACK: force static ext build by imitating extmk
336+
"-e", %Q('$static = true; trace_var(:$static) {|v| $static = true }'),
337+
# HACK: $0 should be extconf.rb path due to mkmf source file detection
338+
# and we want to insert some hacks before it. But -e and $0 cannot be
339+
# used together, so we rewrite $0 in -e.
340+
"-e", %Q('$0="#{srcdir}/extconf.rb"'),
341+
"-e", %Q('require_relative "#{srcdir}/extconf.rb"'),
342+
"-I#{build.build_dir}",
343+
]
344+
sh "#{build.baseruby_path} #{extconf_args.join(" ")}", chdir: objdir
345+
make_cmd = %Q(make -C "#{objdir}" #{make_args.join(" ")} static)
327346
sh make_cmd
328347
end
329348
mkdir_p File.dirname(build.extinit_obj)

ext/js/Makefile

Lines changed: 0 additions & 31 deletions
This file was deleted.

ext/js/depend

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
link.filelist:
2+
echo $(foreach obj,$(OBJS),$(abspath $(obj))) > $@
3+
4+
static: link.filelist
5+
6+
bindgen/rb-js-abi-host.h bindgen/rb-js-abi-host.c &: bindgen/rb-js-abi-host.wit
7+
@mkdir -p "$(@D)"
8+
wit-bindgen c --import $(srcdir)/bindgen/rb-js-abi-host.wit --out-dir bindgen
9+
10+
js-core.o: bindgen/rb-js-abi-host.h
11+
12+
bindgen/%.o: bindgen/%.c
13+
@mkdir -p "$(@D)"
14+
$(CC) -c -I./bindgen -o $@ $<

ext/js/extconf.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require "mkmf"
2+
$objs = ["js-core.o", "bindgen/rb-js-abi-host.o"]
3+
create_makefile("js")

ext/witapi/Makefile

Lines changed: 0 additions & 32 deletions
This file was deleted.

ext/witapi/depend

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
link.filelist:
2+
echo $(foreach obj,$(OBJS),$(abspath $(obj))) > $@
3+
echo -mexec-model=reactor >> $@
4+
5+
static: link.filelist
6+
7+
bindgen/rb-abi-guest.h bindgen/rb-abi-guest.c &: bindgen/rb-abi-guest.wit
8+
@mkdir -p "$(@D)"
9+
wit-bindgen c --export $(srcdir)/bindgen/rb-abi-guest.wit --out-dir bindgen
10+
11+
witapi-core.o: bindgen/rb-abi-guest.h
12+
13+
bindgen/%.o: bindgen/%.c
14+
@mkdir -p "$(@D)"
15+
$(CC) -c -I./bindgen -o $@ $<

ext/witapi/extconf.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require "mkmf"
2+
$objs = ["witapi-core.o", "bindgen/rb-abi-guest.o"]
3+
create_makefile("witapi")

0 commit comments

Comments
 (0)