Skip to content

Commit 1758137

Browse files
nobupeterzhu2118
authored andcommitted
Simplify gc/mmtk/extconf.rb
- Split static recipes to depend file. - Modify makefile configurations in the block to `create_makefile`. - Expand rust sources in extconf.rb instead of GNU make extension. TODO: pass `CARGO_TARGET_DIR` without shell syntax.
1 parent c961d09 commit 1758137

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

gc/extconf_base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
append_cflags("-fPIC")
1111

12-
def create_gc_makefile(name)
13-
create_makefile("librubygc.#{name}")
12+
def create_gc_makefile(name, &block)
13+
create_makefile("librubygc.#{name}", &block)
1414
end

gc/mmtk/depend

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$(TARGET_SO): $(MMTK_BUILD)/$(LIBMMTK_RUBY)
2+
3+
# Add the `libmmtk_ruby.a` target to run `cargo build`
4+
5+
release/$(LIBMMTK_RUBY) debug/$(LIBMMTK_RUBY): $(RUSTSRCS) $(srcdir)/Cargo.toml $(srcdir)/Cargo.toml
6+
7+
release/$(LIBMMTK_RUBY):
8+
CARGO_TARGET_DIR="." cargo build --manifest-path=$(srcdir)/Cargo.toml --release
9+
10+
debug/$(LIBMMTK_RUBY):
11+
CARGO_TARGET_DIR="." cargo build --manifest-path=$(srcdir)/Cargo.toml
12+
13+
clean: clean-mmtk
14+
15+
.PHONY: clean-mmtk
16+
clean-mmtk:
17+
-$(Q)$(RM_RF) debug release
18+
-$(Q)$(RM) .rustc_info.json

gc/mmtk/extconf.rb

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,18 @@
33
require_relative "../extconf_base"
44

55
# Statically link `libmmtk_ruby.a`
6-
$LIBS << " $(MMTK_BUILD)/libmmtk_ruby.#{RbConfig::CONFIG["LIBEXT"]}"
6+
$LIBS << " $(MMTK_BUILD)/$(LIBMMTK_RUBY)"
77

8-
create_gc_makefile("mmtk")
8+
rustsrcs = Dir.glob("src/*.rs", base: __dir__).map {|s| "$(srcdir)/#{s}"}
99

10-
makefile = File.read("Makefile")
10+
create_gc_makefile("mmtk") do |makefile|
11+
[
12+
*makefile,
1113

12-
makefile.prepend("MMTK_BUILD=debug\n")
13-
14-
# Add `libmmtk_ruby.a` as an object file
15-
makefile.gsub!(/^OBJS = (.*)$/, "OBJS = \\1 $(MMTK_BUILD)/libmmtk_ruby.#{RbConfig::CONFIG["LIBEXT"]}")
16-
17-
# Modify the `all` target to run the `libmmtk_ruby.a` target first
18-
makefile.gsub!(/^all:\s+(.*)$/, "all: $(MMTK_BUILD)/libmmtk_ruby.#{RbConfig::CONFIG["LIBEXT"]} \\1")
19-
20-
# Add the `libmmtk_ruby.a` target to run `cargo build`
21-
makefile << <<~MAKEFILE
22-
$(MMTK_BUILD)/libmmtk_ruby.#{RbConfig::CONFIG["LIBEXT"]}: $(wildcard $(srcdir)/src/*.rs) $(srcdir)/Cargo.toml $(srcdir)/Cargo.toml
23-
$(Q) case $(MMTK_BUILD) in \
24-
release) \
25-
CARGO_TARGET_DIR="." cargo build --manifest-path=$(srcdir)/Cargo.toml --release \
26-
;; \
27-
debug) \
28-
CARGO_TARGET_DIR="." cargo build --manifest-path=$(srcdir)/Cargo.toml \
29-
;; \
30-
*) \
31-
$(ECHO) Unknown MMTK_BUILD=$(MMTK_BUILD) \
32-
exit 1 \
33-
;; \
34-
esac
35-
36-
clean: clean-mmtk
37-
38-
.PHONY: clean-mmtk
39-
clean-mmtk:
40-
-$(Q)$(RM_RF) debug release
41-
-$(Q)$(RM) .rustc_info.json
42-
MAKEFILE
43-
44-
File.open("Makefile", "w") { |file| file.puts(makefile) }
14+
<<~MAKEFILE,
15+
MMTK_BUILD = debug
16+
LIBMMTK_RUBY = libmmtk_ruby.#$LIBEXT
17+
RUSTSRCS = #{rustsrcs.join(" \\\n\t ")}
18+
MAKEFILE
19+
]
20+
end

0 commit comments

Comments
 (0)