Skip to content

Commit

Permalink
Use extconf.rb for external GC compilation
Browse files Browse the repository at this point in the history
This commit adds extconf.rb for both the default GC and and MMTk to build
the external GC. This allows common.mk to not need to contain any
implementation-specific build configuration.
  • Loading branch information
peterzhu2118 authored and eightbitraptor committed Nov 22, 2024
1 parent b7d55d5 commit 98f3e2d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 32 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/modgc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,22 @@ jobs:
${arch:+--target=$arch-$OSTYPE --host=$arch-$OSTYPE}
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build MMTK Ruby lib
- name: Set MMTk environment variables
run: |
cd ../src/gc/mmtk
if [[ ${{ matrix.gc.mmtk_build }} == release ]]; then
cargo build --release
else
cargo build
if [[ ${{ matrix.gc.mmtk_build }} == debug ]]; then
echo 'RUST_LOG=' >> $GITHUB_ENV
# Debug builds run much slower so we should increase the timeout
echo 'RUBY_TEST_TIMEOUT_SCALE=10' >> $GITHUB_ENV
# SYNTAX_SUGGEST_TIMEOUT defaults to 1 second
echo 'SYNTAX_SUGGEST_TIMEOUT=60' >> $GITHUB_ENV
fi
echo 'RUST_LOG=' >> $GITHUB_ENV
echo 'MMTK_PLAN=${{ matrix.gc.mmtk_plan }}' >> $GITHUB_ENV
echo 'EXCLUDES=../src/test/.excludes-mmtk' >> $GITHUB_ENV
echo 'MSPECOPT=-B../src/spec/mmtk.mspec' >> $GITHUB_ENV
if: ${{ matrix.gc.name == 'mmtk' }}

- run: $SETARCH make

- name: Build shared GC
run: |
echo "RUBY_GC_LIBRARY=${{ matrix.gc.name }}" >> $GITHUB_ENV
Expand All @@ -150,8 +148,6 @@ jobs:
fi
if: ${{ matrix.gc.name == 'mmtk' }}

- run: $SETARCH make

- run: |
$SETARCH make golf
case "${{ matrix.configure }}" in
Expand Down
30 changes: 11 additions & 19 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ install-prereq: $(CLEAR_INSTALLED_LIST) yes-fake sudo-precheck PHONY
clear-installed-list: PHONY
@> $(INSTALLED_LIST) set MAKE="$(MAKE)"

clean: clean-ext clean-enc clean-golf clean-docs clean-extout clean-local clean-platform clean-spec
clean: clean-ext clean-enc clean-golf clean-docs clean-extout clean-gc clean-local clean-platform clean-spec
clean-local:: clean-runnable
$(Q)$(RM) $(ALLOBJS) $(LIBRUBY_A) $(LIBRUBY_SO) $(LIBRUBY) $(LIBRUBY_ALIASES)
$(Q)$(RM) $(PROGRAM) $(WPROGRAM) miniruby$(EXEEXT) dmyext.$(OBJEXT) dmyenc.$(OBJEXT) $(ARCHFILE) .*.time
Expand Down Expand Up @@ -751,11 +751,13 @@ clean-capi: PHONY
clean-platform: PHONY
clean-extout: PHONY
-$(Q)$(RMDIR) $(EXTOUT)/$(arch) $(RUBYCOMMONDIR) $(EXTOUT) 2> $(NULL) || $(NULLCMD)
clean-gc: PHONY
$(Q) $(RMALL) .gc
clean-docs: clean-rdoc clean-html clean-capi
clean-spec: PHONY
clean-rubyspec: clean-spec

distclean: distclean-ext distclean-enc distclean-golf distclean-docs distclean-extout distclean-local distclean-platform distclean-spec
distclean: distclean-ext distclean-enc distclean-golf distclean-docs distclean-extout distclean-gc distclean-local distclean-platform distclean-spec
distclean-local:: clean-local
$(Q)$(RM) $(MKFILES) yasmdata.rb *.inc $(PRELUDES) *.rbinc *.rbbin
$(Q)$(RM) config.cache config.status config.status.lineno
Expand All @@ -768,6 +770,7 @@ distclean-html: clean-html
distclean-capi: clean-capi
distclean-docs: clean-docs
distclean-extout: clean-extout
distclean-gc: clean-gc
distclean-platform: clean-platform
distclean-spec: clean-spec
distclean-rubyspec: distclean-spec
Expand Down Expand Up @@ -1940,30 +1943,19 @@ rewindable:

HELP_EXTRA_TASKS = ""

MMTK_BUILD=debug
MMTK_SRC_PATH=$(srcdir)/gc/mmtk
MMTK_LIB_PATH=$(srcdir)/gc/mmtk/target/$(MMTK_BUILD)/libmmtk_ruby.$(LIBEXT)

shared-gc: probes.h
$(Q) if test -z $(shared_gc_dir); then \
echo "You must configure with --with-shared-gc to use shared GC"; \
exit 1; \
elif test -z $(SHARED_GC); then \
echo "You must specify SHARED_GC with the GC to build"; \
exit 1; \
else \
$(MAKEDIRS) $(shared_gc_dir); \
echo generating $(shared_gc_dir)librubygc.$(SHARED_GC).$(SOEXT); \
if [ "$(SHARED_GC)" = "mmtk" ]; then \
if test ! -f $(MMTK_LIB_PATH); then \
echo "libmmtk_ruby.$(LIBEXT) not found. Please run 'cargo build' inside $(MMTK_SRC_PATH)"; \
exit 1; \
fi; \
$(LDSHARED) -I$(srcdir)/include -I$(srcdir) -I$(arch_hdrdir) $(XDLDFLAGS) $(cflags) -DBUILDING_SHARED_GC -fPIC -o $(shared_gc_dir)librubygc.$(SHARED_GC).$(SOEXT) $(srcdir)/gc/$(SHARED_GC).c $(MMTK_LIB_PATH); \
else \
$(LDSHARED) -I$(srcdir)/include -I$(srcdir) -I$(arch_hdrdir) $(XDLDFLAGS) $(cflags) -DBUILDING_SHARED_GC -fPIC -o $(shared_gc_dir)librubygc.$(SHARED_GC).$(SOEXT) $(srcdir)/gc/$(SHARED_GC).c; \
fi; \
fi
$(Q) $(MAKEDIRS) $(shared_gc_dir) .gc/$(arch)/$(SHARED_GC)
$(Q) $(RUNRUBY) -C .gc/$(arch)/$(SHARED_GC) $(CURDIR)/$(srcdir)/gc/$(SHARED_GC)/$(EXTCONF)
$(Q) $(CHDIR) .gc/$(arch)/$(SHARED_GC) && \
$(MAKE) extout=../../../$(EXTOUT) BUILTRUBY=../../../miniruby$(EXEEXT) && \
$(CP) librubygc.$(SHARED_GC).$(DLEXT) $(shared_gc_dir)

help: PHONY
$(MESSAGE_BEGIN) \
Expand Down Expand Up @@ -7285,7 +7277,7 @@ gc.$(OBJEXT): $(CCAN_DIR)/str/str.h
gc.$(OBJEXT): $(hdrdir)/ruby.h
gc.$(OBJEXT): $(hdrdir)/ruby/ruby.h
gc.$(OBJEXT): $(hdrdir)/ruby/version.h
gc.$(OBJEXT): $(top_srcdir)/gc/default.c
gc.$(OBJEXT): $(top_srcdir)/gc/default/default.c
gc.$(OBJEXT): $(top_srcdir)/gc/gc.h
gc.$(OBJEXT): $(top_srcdir)/gc/gc_impl.h
gc.$(OBJEXT): $(top_srcdir)/internal/array.h
Expand Down
6 changes: 3 additions & 3 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ rb_gc_guarded_ptr_val(volatile VALUE *ptr, VALUE val)

static const char *obj_type_name(VALUE obj);
#define RB_AMALGAMATED_DEFAULT_GC
#include "gc/default.c"
#include "gc/default/default.c"
static int external_gc_loaded = FALSE;


Expand Down Expand Up @@ -742,7 +742,7 @@ ruby_external_gc_init(void)
}
}

size_t gc_so_path_size = strlen(SHARED_GC_DIR "librubygc." SOEXT) + strlen(gc_so_file) + 1;
size_t gc_so_path_size = strlen(SHARED_GC_DIR "librubygc." DLEXT) + strlen(gc_so_file) + 1;
gc_so_path = alloca(gc_so_path_size);
{
size_t gc_so_path_idx = 0;
Expand All @@ -752,7 +752,7 @@ ruby_external_gc_init(void)
GC_SO_PATH_APPEND(SHARED_GC_DIR);
GC_SO_PATH_APPEND("librubygc.");
GC_SO_PATH_APPEND(gc_so_file);
GC_SO_PATH_APPEND(SOEXT);
GC_SO_PATH_APPEND(DLEXT);
GC_ASSERT(gc_so_path_idx == gc_so_path_size - 1);
#undef GC_SO_PATH_APPEND
}
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions gc/default/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require_relative "../extconf_base"

create_gc_makefile("default")
13 changes: 13 additions & 0 deletions gc/extconf_base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "mkmf"

srcdir = File.join(__dir__, "..")
$CFLAGS << " -I#{srcdir}"

$CFLAGS << " -DBUILDING_SHARED_GC"
$CFLAGS << " -fPIC"

def create_gc_makefile(name)
create_makefile("librubygc.#{name}")
end
37 changes: 37 additions & 0 deletions gc/mmtk/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require_relative "../extconf_base"

# Statically link `libmmtk_ruby.a`
$LIBS << " $(MMTK_BUILD)/libmmtk_ruby.#{RbConfig::CONFIG["LIBEXT"]}"

create_gc_makefile("mmtk")

makefile = File.read("Makefile")

# Modify the `all` target to run the `mmtk` target first
makefile.gsub!(/^all:\s+(.*)$/, 'all: mmtk \1')

# Add the `mmtk` target to run `cargo build`
makefile << <<~'MAKEFILE'
$(srcdir)/mmtk.c: mmtk
MMTK_BUILD=debug
.PHONY: mmtk
mmtk:
$(Q) case $(MMTK_BUILD) in \
release) \
CARGO_TARGET_DIR="." cargo build --manifest-path=$(srcdir)/Cargo.toml --release \
;; \
debug) \
CARGO_TARGET_DIR="." cargo build --manifest-path=$(srcdir)/Cargo.toml \
;; \
*) \
$(ECHO) Unknown MMTK_BUILD=$(MMTK_BUILD) \
exit 1 \
;; \
esac
MAKEFILE

File.open("Makefile", "w") { |file| file.puts(makefile) }
2 changes: 1 addition & 1 deletion gc/mmtk.c → gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "gc/gc.h"
#include "gc/gc_impl.h"
#include "gc/mmtk.h"
#include "gc/mmtk/mmtk.h"

#include "ccan/list/list.h"
#include "darray.h"
Expand Down
File renamed without changes.

0 comments on commit 98f3e2d

Please sign in to comment.