diff --git a/common.mk b/common.mk index 9e89bed740..ab493734a5 100644 --- a/common.mk +++ b/common.mk @@ -185,6 +185,8 @@ COMMONOBJS = array.$(OBJEXT) \ $(PRISM_FILES) \ $(YJIT_OBJ) \ $(YJIT_LIBOBJ) \ + $(ZJIT_OBJ) \ + $(ZJIT_LIBOBJ) \ $(COROUTINE_OBJ) \ $(DTRACE_OBJ) \ $(BUILTIN_ENCOBJS) \ diff --git a/configure.ac b/configure.ac index 88b7d2ae85..28cfb66605 100644 --- a/configure.ac +++ b/configure.ac @@ -3910,6 +3910,19 @@ AC_ARG_ENABLE(yjit, )] ) +dnl build ZJIT in release mode if rustc >= 1.58.0 is present and we are on a supported platform +AC_ARG_ENABLE(zjit, + AS_HELP_STRING([--enable-zjit], + [enable in-process JIT compiler that requires Rust build tools. enabled by default on supported platforms if rustc 1.58.0+ is available]), + [ZJIT_SUPPORT=$enableval], + [AS_CASE(["$YJIT_TARGET_OK:$YJIT_RUSTC_OK"], + [yes:yes], [ + ZJIT_SUPPORT=yes + ], + [ZJIT_SUPPORT=no] + )] +) + CARGO= CARGO_BUILD_ARGS= YJIT_LIBS= @@ -3959,6 +3972,43 @@ AS_CASE(["${YJIT_SUPPORT}"], AC_DEFINE(USE_YJIT, 0) ]) +ZJIT_LIBS= +AS_CASE(["${ZJIT_SUPPORT}"], +[yes|dev], [ + AS_IF([test x"$RUSTC" = "xno"], + AC_MSG_ERROR([rustc is required. Installation instructions available at https://www.rust-lang.org/tools/install]) + ) + + AS_CASE(["${ZJIT_SUPPORT}"], + [yes], [ + rb_rust_target_subdir=release + ], + [dev], [ + rb_rust_target_subdir=debug + CARGO_BUILD_ARGS='--features disasm,runtime_checks' + AC_DEFINE(RUBY_DEBUG, 1) + ]) + + AS_IF([test -n "${CARGO_BUILD_ARGS}"], [ + AC_CHECK_TOOL(CARGO, [cargo], [no]) + AS_IF([test x"$CARGO" = "xno"], + AC_MSG_ERROR([cargo is required. Installation instructions available at https://www.rust-lang.org/tools/install]) + ])) + + ZJIT_LIBS="zjit/target/${rb_rust_target_subdir}/libzjit.a" + AS_CASE(["$target_os"],[openbsd*],[ + # Link libc++abi (which requires libpthread) for _Unwind_* functions needed by yjit + LDFLAGS="$LDFLAGS -lpthread -lc++abi" + ]) + ZJIT_OBJ='zjit.$(OBJEXT)' + AS_IF([test x"$ZJIT_SUPPORT" != "xyes" ], [ + AC_DEFINE_UNQUOTED(ZJIT_SUPPORT, [$ZJIT_SUPPORT]) + ]) + AC_DEFINE(USE_ZJIT, 1) +], [ + AC_DEFINE(USE_ZJIT, 0) +]) + dnl These variables end up in ::RbConfig::CONFIG AC_SUBST(YJIT_SUPPORT)dnl what flavor of YJIT the Ruby build includes AC_SUBST(RUSTC)dnl Rust compiler command diff --git a/zjit/src/lib.rs b/zjit/src/lib.rs index a135192397..655a85aca6 100644 --- a/zjit/src/lib.rs +++ b/zjit/src/lib.rs @@ -1,3 +1,10 @@ +mod zjit; + extern "C" fn zjit_init() { println!("zjit_init"); } + +#[no_mangle] +pub extern "C" fn rb_zjit_parse_option() -> bool { + false +}