diff options
author | Alan Wu <[email protected]> | 2025-05-07 00:19:36 +0900 |
---|---|---|
committer | Alan Wu <[email protected]> | 2025-05-15 00:39:03 +0900 |
commit | 92b218fbc379fe85792eb060b71520e271971335 () | |
tree | d5fbb4b7dd49d3388d9cff5fbdccc5effa7e20d3 /yjit | |
parent | b5575a80bc3849651c395d0ae470eb41dc3aa897 (diff) |
YJIT: ZJIT: Allow both JITs in the same build
This commit allows building YJIT and ZJIT simultaneously, a "combo build". Previously, `./configure --enable-yjit --enable-zjit` failed. At runtime, though, only one of the two can be enabled at a time. Add a root Cargo workspace that contains both the yjit and zjit crate. The common Rust build integration mechanisms are factored out into defs/jit.mk. Combo YJIT+ZJIT s are supported; if either JIT uses `--enable-*=dev`, both of them are built in dev mode. The combo build requires Cargo, but building one JIT at a time with only rustc in release build remains supported.
Notes: Merged: https://.com/ruby/ruby/pull/13262
-rw-r--r-- | yjit/Cargo.toml | 27 | ||||
-rw-r--r-- | yjit/bindgen/Cargo.toml | 2 | ||||
-rw-r--r-- | yjit/yjit.mk | 57 |
3 files changed, 11 insertions, 75 deletions
@@ -9,9 +9,6 @@ edition = "2021" # Rust 2021 edition to compile with rust-version = "1.58.0" # Minimally supported rust version publish = false # Don't publish to crates.io -[lib] -crate-type = ["staticlib"] - [dependencies] # No required dependencies to simplify build process. TODO: Link to yet to be # written rationale. Optional For development and testing purposes @@ -27,27 +24,3 @@ disasm = ["capstone"] # from cfg!(debug_assertions) so that we can see disasm of the code # that would run in the release mode. runtime_checks = [] - -[profile.dev] -opt-level = 0 -debug = true -debug-assertions = true -overflow-checks = true - -[profile.dev_nodebug] -inherits = "dev" - -[profile.stats] -inherits = "release" - -[profile.release] -# NOTE: --enable-yjit builds use `rustc` without going through Cargo. You -# might want to update the `rustc` invocation if you change this profile. -opt-level = 3 -# The extra robustness that comes from checking for arithmetic overflow is -# worth the performance cost for the compiler. -overflow-checks = true -# Generate debug info -debug = true -# Use ThinLTO. Much smaller output for a small amount of build time increase. -lto = "thin" @@ -8,3 +8,5 @@ edition = "2021" [dependencies] bindgen = "0.70.1" env_logger = "0.11.5" @@ -19,60 +19,21 @@ YJIT_SRC_FILES = $(wildcard \ # rebuild at the next build. YJIT_LIB_TOUCH = touch $@ # YJIT_SUPPORT=yes when `configure` gets `--enable-yjit` ifeq ($(YJIT_SUPPORT),yes) -$(YJIT_LIBS): $(YJIT_SRC_FILES) $(ECHO) 'building Rust YJIT (release mode)' +$(Q) $(RUSTC) $(YJIT_RUSTC_ARGS) $(YJIT_LIB_TOUCH) -else ifeq ($(YJIT_SUPPORT),no) -$(YJIT_LIBS): - $(ECHO) 'Error: Tried to build YJIT without configuring it first. Check `make showconfig`?' - @false -else ifeq ($(YJIT_SUPPORT),$(filter dev dev_nodebug stats,$(YJIT_SUPPORT))) -# NOTE: MACOSX_DEPLOYMENT_TARGET to match `rustc --print deployment-target` to avoid the warning below. -# ld: warning: object file (yjit/target/debug/libyjit.a(<libcapstone object>)) was built for -# newer macOS version (15.2) than being linked (15.0) -# We don't use newer macOS feature as of yet. -$(YJIT_LIBS): $(YJIT_SRC_FILES) - $(ECHO) 'building Rust YJIT ($(YJIT_SUPPORT) mode)' - +$(Q)$(CHDIR) $(top_srcdir)/yjit && \ - CARGO_TARGET_DIR='$(CARGO_TARGET_DIR)' \ - CARGO_TERM_PROGRESS_WHEN='never' \ - MACOSX_DEPLOYMENT_TARGET=11.0 \ - $(CARGO) $(CARGO_VERBOSE) build $(CARGO_BUILD_ARGS) - $(YJIT_LIB_TOUCH) -else -endif - -yjit-libobj: $(YJIT_LIBOBJ) - -YJIT_LIB_SYMBOLS = $(YJIT_LIBS:.a=).symbols -$(YJIT_LIBOBJ): $(YJIT_LIBS) - $(ECHO) 'partial linking $(YJIT_LIBS) into $@' -ifneq ($(findstring darwin,$(target_os)),) - $(Q) $(CC) -nodefaultlibs -r -o $@ -exported_symbols_list $(YJIT_LIB_SYMBOLS) $(YJIT_LIBS) -else - $(Q) $(LD) -r -o $@ --whole-archive $(YJIT_LIBS) - -$(Q) $(OBJCOPY) --wildcard --keep-global-symbol='$(SYMBOL_PREFIX)rb_*' $(@) endif -# For Darwin only: a list of symbols that we want the glommed Rust static lib to export. -# Unfortunately, using wildcard like '_rb_*' with -exported-symbol does not work, at least -# not on version 820.1. Assume llvm-nm, so XCode 8.0 (from 2016) or newer. -# -# The -exported_symbols_list pulls out the right archive members. Symbols not listed -# in the list are made private extern, which are in turn made local as we're using `ld -r`. -# Note, section about -keep_private_externs in ld's man page hints at this behavior on which -# we rely. -ifneq ($(findstring darwin,$(target_os)),) -$(YJIT_LIB_SYMBOLS): $(YJIT_LIBS) - $(Q) $(tooldir)/darwin-ar $(NM) --defined-only --extern-only $(YJIT_LIBS) | \ - sed -n -e 's/.* //' -e '/^$(SYMBOL_PREFIX)rb_/p' \ - -e '/^$(SYMBOL_PREFIX)rust_eh_personality/p' \ - > $@ - -$(YJIT_LIBOBJ): $(YJIT_LIB_SYMBOLS) endif # By using YJIT_BENCH_OPTS instead of RUN_OPTS, you can skip passing the options to `make install` @@ -94,7 +55,7 @@ RUST_VERSION = +1.58.0 .PHONY: yjit-smoke-test yjit-smoke-test: ifneq ($(strip $(CARGO)),) - $(CARGO) $(RUST_VERSION) test --all-features -q --manifest-path='$(top_srcdir)/yjit/Cargo.toml' endif $(MAKE) btest RUN_OPTS='--yjit-call-threshold=1' BTESTS=-j $(MAKE) test-all TESTS='$(top_srcdir)/test/ruby/test_yjit.rb' |